# Sum an array of integers. # Leave the result in Sum. # place the value in r4 to be printed # Registers # $t1 -- true if done # $t2 -- current address in array # $t3 -- last address of array # $t4 -- running sum # $t5 -- temp to get value from memory .text .globl main main: add $t4, $0, $0 # Initialize $t4 la $t2, First # get first address la $t3, Last # get last address loop: slt $t1, $t3, $t2 # test if done bne $t1, $0, done # if yes, branch lw $t5, 0($t2) # load array value add $t4, $t4, $t5 # add to sum addi $t2, $t2, 4 # inc array pointer j loop # do it again done: sw $t4, Sum lw $a0, Sum li $v0, 1 # print contents of $t4 (This will be the sum) syscall li $v0, 10 # Quit syscall # Data .data First: .word 10 .word 20 .word 1 .word 15 .word 3 .word 10 Last: .word 5 Sum: .word 0 # should be 64