我正在尝试从键盘中取出 4 个数字并将其存储到一个数组中。我想出了以下代码,但是当我尝试打印数组中的第一个数字时,它会打印 0。为什么它不打印数组中的第一个值?
main:
li $v0, 5 # read integer
syscall
add $s0, $v0, $zero #store input1 to s0
li $v0, 5 # read integer
syscall
add $s1, $v0, $zero #store input2 to s0
li $v0, 5 # read integer
syscall
add $s2, $v0, $zero #store input3 to s0
li $v0, 5 # read integer
syscall
add $s3, $v0, $zero #store input4 to s0
.data
list: $s0, $s1, $s2, $s3 #set array from keyboard values
.text
#get the array into a register
la $t3, list # put address of list into $t3
lw $t4, 0($t3) # get the value from the array cell
li $v0, 1 # print integer
move $a0, $t4 # what to print is stored at $s1
syscall # make system call
exit:
li $v0, 10 # exit system call
syscall
想法来自: http ://www.cs.pitt.edu/~xujie/cs447/AccessingArray.htm 但他们使用硬编码的整数而不是从键盘保存到寄存器的值。谢谢您的帮助。