# Simple loop test # # The program reads some initial values from data memory, then loops. # On each iteration, both a pointer to memory and a data # accumulator is incremented, and the accumulator is written to memory. # The loop terminates when the ending memory address (read from # memory on startup) is reached. # # Data file inital values locations: # 0 address base for writing values to memory # 4 data increment # 8 address increment (make sure this is a multiple of 4!) # 12 last memory address # # Register use: # $1 memory pointer # $2 amount to increment accumulator on each iteration # $3 amount to increment memory pointer on each iteration # $4 ending memory address # $5 accumulator # # ASSEMBLER SOURCE # COMMENTS # ASSEMBLED BINARY # HEX .text lw $1,0($0) # get address base 100011 00000 00001 0000000000000000 : 8c010000 lw $2,4($0) # get data increment 100011 00000 00010 0000000000000100 : 8c020004 lw $3,8($0) # get address incr 100011 00000 00011 0000000000001000 : 8c030008 lw $4,12($0) # get last mem addr 100011 00000 00100 0000000000001100 : 8c04000c add $5,$0,$0 # clear sum register 000000 00000 00000 00101 00000 100000 : 00002820 loop: sw $5,0($1) # store sum 101011 00001 00101 0000000000000000 : ac250000 add $5,$5,$2 # increment sum 000000 00101 00010 00101 00000 100000 : 00a22820 add $1,$1,$3 # increment mem ptr 000000 00001 00011 00001 00000 100000 : 00230820 beq $1,$4,done # loop until done 000100 00001 00100 0000000000000001 : 10240001 beq $0,$0,loop 000100 00000 00000 1111111111111011 : 1000fffb done: : ffffffff