Chapter 6: Appendix A- 6 (page 572)
A.6 [5] Using SPIM, write and test an adding machine program that repeatedly reads in integers and adds them into a running sum. The program should stop when it gets an input that is 0, printing out the sum at that point. Use the SPIM system calls described on pages A-43 and A-45.
Short Answer
The required code:
.data
str: .asciiz
str2: .asciiz
.text
main:
li $a0,0
loop:
li $v0,4
la $a0,str
syscall
li,$v0,5
syscall
beq $v0,$0,done
add $v0,$0,$v0
j loop
done:
li $v0,4
la $a0,str2
syscall
li $v0,1
move $a0,$s0
syscall
.end