1
我正在嘗試寫入從用戶處取得的求和整數的MIPS代碼,直到用戶輸入字符「*」。從字符中加入整數循環退出
輸出會喜歡 「1 4 3 *總計:8」
我寫的代碼終止循環條件時用戶輸入 「-1」,而不是 「*」。我試着寫'*'語法而不是-1,但它沒有給出總和。用戶輸入「*」字符時如何退出循環?這是我的第一個問題,這裏是我的工作代碼「-1」。
# $s0=Sum, $s1=Checkvalue
.data # Data memory area
prompt: .asciiz "Total: "
.text # Code area
main:
move $s0, $zero # Sum is made "0"
li $s1, -1 # Checkvalue is made "-1"
loop: bne $s0, $s0, exit # Infinite loop is described
li $v0, 5 # Read integer into $v0
syscall # Make the syscall read_int
move $t0, $v0 # Move the integer read into $t0
beq $t0, $s1, exit # If the read value is equal "-1", exit
add $s0, $t0, $s0 # Add the read integer to sum
j loop # Return loop
exit:
li $v0, 4 # Syscall to print string
la $a0, prompt
syscall
move $a0, $s0 # Syscall to print string
li $v0, 1
syscall
li $v0, 10 # Syscall to exit
syscall
# Reference: www.es.ele.tue.nl/~heco/courses/ProcDesign/SPIM.ppt
我的第二個問題是我使用了「系統調用」,我的用法是否適用於stdin和stdout,系統函數?
非常感謝。
謝謝。我發佈了一個與此[這裏]有關的新問題(http://stackoverflow.com/questions/36296223/comparing-two-strings-in-mips) – bieaisar