In: Computer Science
Write a MIPS Assembly program that computes the sum of all the odd numbers from 1 ..99 and print out the answer.
main:
li $v1, 99 # initialized v1 to 99
li $t1, 0 # initialized t1 to 0
loop:
add $t1, $t1, $v1 # sum of odd numbers in register $t0
addi $v1, $v1, -2 # summing of odd numbers in reverse order
bnez $v1, loop # branch to loop if $v0 is != zero
li $v1, 4 # system call code for Print String
la $a0, result # load address of message into $a0
syscall # print the string
li $v0, 1 # system call code for Print Integer
move $a0, $t0 # move value to be printed to $a0
syscall # print sum of integers
b main # branch to main
end: li $v0, 4 # system call code for Print String
la $a0, bye # load address of msg. into $a0
syscall # print the string
li $v0, 10 # terminate program run and
syscall # return control to system