.data
N: .space 100
arr: .space 5
iMsg: .asciiz "Enter a series of 5 formulae: \n"
oMsg: .asciiz "The values are: \n"
cr: .asciiz "\n"
.text
main:
# ouput the prompt
li $v0,4
la $a0,iMsg
syscall
#Get input words
la $s0,arr
li $s1,0 #Counter
li $s2,5 #Maximum number of words allowed to be inputted
loop1:
# get the string
li $v0,8
la $a0,N
li $a1,100
syscall
sw $v0,0($s0)
addi $s1,$s1,1
beq $s1,$s2,end1
addi $s0,$s0,4
b loop1
end1:
sw $s2,N
# output the string prefix text
li $v0,4
la $a0,oMsg
syscall
#Output list
la $s0,arr
lw $s1,N
# output the number
loop2:
beqz $s1,end2
lw $a0,0($s0)
li $v0,4
la $a0,N
syscall
li $v0,4
la $a0,cr
syscall
subu $s0,$s0,-4
subu $s1,$s1,1
b loop2
end2:
# exit
jr $ra
Asked
Active
Viewed 61 times
0
-
syscall 8 [doesn't return anything](https://www.doc.ic.ac.uk/lab/secondyear/spim/node8.html), so I'm not sure what you intended `sw $v0,0($s0)` to do. – Michael Sep 22 '15 at 19:27
-
It's supposed to store the value in the directory v0 into the array s0. I have similar code using integers but i can't seem to get it right for string values. – Tia Sep 22 '15 at 19:31