0
我想做一個循環,將用戶輸入的整數添加到數組,直到它填充數組。每次我鍵入一個值時,QTSPIM吐出268501016,我假設它是存儲在寄存器中的一些隨機值。For循環MIPS使用。空間
爲了測試我的程序是否經歷了整個循環,當程序到達我的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代碼。