在这个程序中,我试图在文本"你好吗"中找到单词"how"的出现,该单词在开头是硬编码的。但是由于某些原因,当我运行该程序时,它不会停止并且不打印任何内容。所以我只是想知道谁能告诉我我哪里错了?提前致谢
text: .ascii "how are you"
word: .ascii "how"
.text
.globl main
main:
Search:#search the occurrence of th word
li $s0, 0 # pointer for the text
li $s1, 0 # pointer for the word
li $s7, 0 # counter for occrence
compare:lb $t0, text($s0)
addi $s0, $s0, 1
lb $t1, word($s1)
addi $s1, $s1, 1
bne $t0, $t1, next_word # compare next word
beq $t6, $s1, bingo # t6 is the length of the keyword
j compare # keep comparing
bingo:
addi $s7, $s7, 1 # occrence + 1
next_word:
li $s1, 0 # refresh the keyword
loop: lb $t0, text($s0)
addi $s0, $s0, 1
bne $t0, 32, loop
beq $t7, $s0, print_result # we have searched the all text
j compare
print_result:
la $a0, ($s7)
li $v0, 1
syscall
li $v0, 10
syscall
程序执行将导致
loop: lb $t0, text($s0)
addi $s0, $s0, 1
bne $t0, 32, loop
因为 $t 0 在第一次跳回"比较"后保持 0。使用 Mars(火星(中包含的分步调试器。也许尝试加载您的值
la $a0, text
lb $t0, 0($a0)
而不是
lb $t0, text($s0)