******************************************************************************** *2345678911234567892123456789312345678941234567895123456789612345678971234567898 ******************************************************************************** *Name: Lorraine D'Ortona *File: add5values.asm *Due Date: 1/1/2012 *Description: (what it does and how - algorithm description) * Adds the elements in an array of length 5. Demonstates: Looping, * ORG, EQU, DB, Index Addressing Mode, Arrays, Formatting and * Readability of Code, Comments, *Input: (Input format and error checking) * 5 element array of hex values * No error checking of input *Output (What will be output, in what form, and where) * Sum is stored in vaiable sum *Errors (what are they)(How do you detect them)(How do you handle them) * No error checking in this program ******************************************************************************** ********** Constants *********************** FIVE EQU $05 ;FIVE is a symbol for $05 ZERO EQU $00 ;ZERO is a symbol for $00 ********** Variable Declarations *********** ORG $2000 array DB $01,$02,$03,$04,$05 ;Array is the address of first value($2000) sum DB $00 avg DW $0000 ********** Main **************************** ORG $3000 ldab #ZERO ;Initialize sum (acc b) to $00. Same as ldab $2005 ldaa #ZERO ;Initialize counter (acc a) to zero (A) ldx #array ;Point to the first value. Same as ldx #2000 jsr ADD jsr AVER SWI ******************************************************************************** *2345678911234567892123456789312345678941234567895123456789612345678971234567898 ******************************************************************************** * Subroutine Name: ADD * * This subroutine will add the five elements. * Traverses the array using a pointer * Acc a is the counter and acc b will be the sum ******************************************************************************** ADD cmpa #FIVE ;added all 5 scores? Counter acc a =5? Branch beq DONE ;Subtract acc a from 5. Result is 0 if they are =. ;If result = 0 CCR Z bit-1 addb $0,X ;No branch. Add the number pointed to to sum inx ;point to the next value inca ;increment the counter bra ADD ;start the loop again. Branch always ******************************************************************************** *2345678911234567892123456789312345678941234567895123456789612345678971234567898 ******************************************************************************** * Subroutine Name: DONE * * The end. ******************************************************************************** DONE stab sum ;save the result rts ;back to the main ******************************************************************************** *2345678911234567892123456789312345678941234567895123456789612345678971234567898 ******************************************************************************** * Subroutine Name: AVER * * This subroutine takes the average of the * five elements and stores it in avg ******************************************************************************** AVER ldab sum ;this thing don't pad our values... ldaa #$00 ;clear out A ldx #0005 ;load the total number of values into X idivs ;16-bit D/X, store in X stx avg ;store the rsult in avg rts ;return to main