; ######################################################################################### ; # Indiana University # ; # Computer Science Department # ; # # ; # Example Program 2 # ; # # ; # DESCRIPTION: # ; # # ; # This program defines 4 storage bytes in memory and adds the values contained in # ; # the locations. The sum is placed in a long word variable called result. # ; # # ; # AUTHOR: # ; # Bryce Himebaugh (bhimebau@cs.indiana.edu) # ; # IUCS Staff # ; # 6/21/99 # ; # # ; ######################################################################################### SECTION code START: clr.l d0 ; initialize register to hold a data byte. moveq.l #4,d1 ; intialize the loop counter stored in d0 clr.l d2 ; initialize register used to hold the sum lea byte_array,a0 ; load the address if byte_array into a0 add_loop: move.b (a0)+,d0 ; move one byte @ a0 to d0, inc. a0 add.l d0,d2 ; add the d0 to d2 subq.l #1,d1 ; decrement the loop counter bne add_loop ; branch back if the loop counter is not 0 move.l d2,result ; move the register containing the sum to memory trap #15 ; terminate using TRAP #15 mode 0 (d1=0). SECTION data ; variables need to go in data section for ; watch window visability through the debugger byte_array: ds.b 4 ; reserve 4 bytes at location byte_array result: ds.l 1 ; reserve 1 long word at location result