program to compute the sum for an integer from 1 to n ,the user should keep enter integers until enter 0
# i..>$t0 sum...>$t1 n...>$t2
.data
prompt1: .asciiz "Enter a number"
prompt2: .asciiz "The sum of entered number is: "
.text
main:
li $v0, 4 #System call code for print String
la $a0, prompt1 #load address of prompt1
syscall #Call OS to print prompt1
li $v0, 5 #System call code for read integer
syscall #Call OS to read integer into $v0
move $t2, $v0 #move the number to read into $t2
addi $t0, $zero,1 #i=0+1
add $t1, $zero,$zero #sum=0+0
loop: slt $t3, $t2,$t0 #t4= if n(i)
bnq $zero, $t3, goo #if 0==t4 go to "goo"
add $t1, $t1, $t0 #sum=+1
addi $t0, $t0, 1 # i+=1
j loop
goo: beq $t2, $zero, exit #if n==0 go to "go"
li $v0, 4
la $a0, prompt2
syscall # print out "Sum = "
li $v0, 1
move $a0, $t1
syscall # print out actual sum
exit:
li $v0, 10
syscall