2012-11-09 39 views
0

我試圖讓用戶輸入'Y'重新啓動程序(分支回主)或'N'(分支結束程序)。我正在使用系統調用操作碼12讀取單個字符MIPS無限循環/加載字符字節錯誤

endCheck: 
la $a0, newLine    # Print the newLine 
li $v0, 4 
syscall 

la $a0, endPrompt   # print the Start over message 
li $v0, 4 
syscall 

li $v0, 12    # take in char input 
syscall 
move $t0, $v0 

lb $t1, ($t0)    # Load the char byte into t1 

beq $t1, 89, main   # Go back to start if they entered 'Y' 
bne $t1, 78, endCheck   # Ask the user again because input was not 'N' or 'Y' 

li $v0, 10    
syscall 

我在lb行上得到一個錯誤。即使我在數據段上分配了1個字節的空間,並將輸入讀爲1個字符的字符串,我也會遇到一個無限循環(當它正確編譯時它總是回到endCheck)我做錯了什麼?

回答

1

當您使用syscall 12時,字符本身返回$v0。它不會給你一個讀取角色的地址。完全可以省略lb

因此,當您應該使用$t0時,您正在使用$t1進行比較。