我正在尝试创建一个循环,将用户输入的整数添加到数组中,直到它填满数组。每次我输入一个值时,QTSPIM 都会输出 268501016,我认为这是存储在寄存器中的一些随机值。
为了测试我的程序是否正在执行整个循环,当程序到达我的 beq 的分支部分时,我添加了一个对 ascii 行的调用。即使值不相等(至少在我的理解中),该程序似乎也在分支。
.data
array1: .space 24
str1: .ascii "Type in numbers:"
str2: .ascii "Reached Terminate"
.text
main:
li $t2, 5
li $t3, 0
loop1:
beq $t3, $t2, terminate #branch if equal
la $a0, str1
syscall
ori $v0, $0, 5 #instruction to store user input in v0
syscall #get user input and store it in v0
la $t4, array1 #load the address of the array
addu $t0, $0, $v0 #add v0 (our user input) to $t0
sw 0($t4), t0 #stores the value in $t4 to our array
addi $t3, $t3, 1 #add 1 to t3 (incrementing the counter)
addi $t4, $t4, 4 $add 4 to increment the array 4 bits to the next array slot
jal loop1
terminate:
la $a2, str2 #load the string to check when the program reaches terminate
syscall
ori $v0, $0, 10 # end the program
syscall
我唯一能想到的是我的跳转调用不会回到loop1,但如果是这种情况,我不知道如何解决这个问题。
这是 32 位 MIPS 代码。