.data
firstnum: .asciiz "Please enter the first number\n"
seconnum: .asciiz "Please enter the second number\n"
answer : .asciiz "The answer is "
newline : .asciiz "\n"
.text
.align 2
.globl main
main:
la $v1, firstnum
jal print
jal get
move $t0, $v0
la $v1, seconnum
jal print
jal get
move $t1, $v0
li $t2, 0 # output starts at 0
bne $t1, $zero, loop # if t1 is not 0, enter the loop
j end # otherwise, end
print:
li $v0, 4
li $a0, 0
add $a0, $zero, $v1
syscall
jr $31
printnum:
li $v0, 1
li $a0, 0
add $a0, $zero, $v1
syscall
jr $31
get:
li $v0, 5
syscall
jr $31
loop:
add $t2, $t2, $t0 # add the first operand to the result
sub $t1, $t1, 1 # subtract one from the second operand
bne $t1, $zero, loop # if the second operand is > 0, continue
# otherwise, end
end:
la $v1, answer
jal print
move $v1, $t2
jal printnum
la $v1, newline
jal print
li $v0, 10
syscall
P.S. anyone think my blog font is too small?