0
我想從鍵盤取4個數字並將其存儲到數組中。我想出了下面的代碼,但是當我嘗試打印數組中的第一個數字時,它會打印0.爲什麼它不打印數組中的第一個值?取自MIPS存儲鍵盤輸入(整數)到陣列
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 但他們用硬編碼的整數,而不是從鍵盤保存到寄存器中的值。 感謝您的幫助。
真棒,謝謝尋求幫助。 – joshmmo