基本上,我需要从用户那里存储10个整数,并打印它们的总和。我的问题是我的总和始终为零。我认为问题是我没有正确加载数组。
感谢您的帮助。
.text
main:
readLoop:
beq $t0, 40, sum #branch if equal to 40, 10 items
li $v0, 4 #Print string
la $a0, prompt1 #load prompt
syscall
li $v0, 5 #read int
syscall
sw $v0, myarray #store input in array
addi $t0, $t0, 4 #add by 4 to count
j readLoop
sum:
beq $t0, 40, printsum
lw $t1,myarray($t0)
addi $t0, $t0, 4
j sum
printsum:
la $a0,result
li $v0,4
syscall
move $a0,$v1
li $v0,1
syscall
exit:
li $v0,10
syscall
.data
myarray: .space 40
result: .asciiz "The result is "
prompt1: .asciiz "Enter elements in the array: "