Write a MIPS program that generates and adds up all even numbers from 1 to 100.
- it must have at least one loop
- it should store the sum in register R12
And this is what I wrote:
main:
li $t0, 0 # clear register $t0 to zero
li $t4, 0 # clear register $t4 to zero
loop:
add $t0, $t0, 2 # generating even numbers in register $t0
add $t4, $t4, $t0 # compute the sume
bne $t0, 100, loop # if t0 reached 100 then go to loop.
b endloop # branch to endloop
endloop:
li $v0, 10 # terminate program run and
syscall # Exit
Is this correct?