我想製作一個程序,讀取幾個字符沒有特別的限制,但只需按Enter鍵(我發現Enter鍵的ascii代碼是13,糾正我,如果我是錯的)和一種「縫合」在一起。Assembly MIPS:將字符粘在一起給出的系統調用12服務
例如,如果用戶給出字符'3','4','5',程序應顯示整數'345'。所以,每個角色都應該匹配一點。
我試圖與循環如下發揮:
.text
.globl main
main:
add $t0, $zero, $zero #counter
loop:
li $v0, 12 #v0 = the character that was read
syscall
subi $v0, $v0, 48
#from the register column, I found that after the syscalls, the v0
#register always adds 48 to the given character
beq $v0, 13, exit #if Enter is given, exit from the loop
move $t1, $v0 #move the character to t1
sb $t1, ($t0) #store the character to t0
addiu $t0, $t0, 1 #point to the next spot of the t0
j loop
exit:
add $a0, $t0, $zero #load the contents of t0 to a0
li $v0, 1 #print the result
syscall
li $v0, 10
syscall
,顯示在我的awkardly編寫的代碼的錯誤是「運行時異常在0x00400020:地址超出範圍00000000的」因「存儲字節」命令。
我應該給一個抵消?
是否整個「存儲字節」thingy從根本上錯誤?
是否每次都需要given_character-48?
我該怎麼辦?
我沒有在回答中寫下任何有關如何處理非本地大整數的問題,因爲這對於您當前的裝配技能IMO來說看起來有些複雜。所以我正在推動你走向「串」解決方案,但也許這不是你所期望的。 – Ped7g
順便說一句,我無法弄清,爲什麼輸入'3','4','5'應該產生'347'輸出。從你的問題中不清楚你想用輸入值做什麼樣的計算......所以我只是猜測它是一個錯字。 – Ped7g
它確實是一個錯字 – Coursal