我不能完全弄清楚我在汇编代码中做错了什么。我想有时“主:”在写比较两个空值终止被输入为A0 $和$ A1字符串的程序段,然后调用简单的MIPS汇编
jal hamming
启动程序。
基本上这部分我想两个字符串进行比较字符通过字符,直到一个字符串命中null终止字符。然后程序停止并返回有多少个字符不同,直到终止。
我认为它与我使用的跳跃有关,但我不太确定。该方案是有点长,所以我把主要的一块,我认为是问题(因此忽略像$ A3,已初始化和定义已经变量):
diffchar:
li $t4, 0
li $t5, 1
beq $a0, $a1, samechars
move $v0, $t5
j diffcharend
samechars:
move $v0, $t4
diffcharend:
jr $ra
hamming:
absvaluedone:
li $a2, 0
#li $v0, 0
move $t0, $a0
move $t1, $a1
hammingloopbegin:
lb $t2, 0($t0)
lb $t3, 0($t1)
beq $t2, $0, hammingdone
beq $t3, $0, hammingdone
la $a0, 0($t0)
la $a1, 0($t1)
jal diffchar **#this is the line that causes me problems, if I take this out it is fine**
beq $v0, $0, next
addiu $a2, $a2, 1
next:
addiu $t0, $t0, 1
addiu $t1, $t1, 1
j hammingloopbegin
hammingdone:
add $v0, $a2, $a3
jr $ra
当我运行我的程序我的输出看起来这样口口声声说一个无限循环:
Exception occurred at PC=0x00400144
Bad address in data/stack read: 0x10021226
Exception 7 [Bad address in data/stack read] occurred and ignored
Exception occurred at PC=0x00400140
Bad address in data/stack read: 0x1002121b
Exception 7 [Bad address in data/stack read] occurred and ignored
我觉得有什么毛病diffchar或我使用跳来跳去到diffchar过程。这是我第一次编写汇编代码,所以我认为这些东西真的很基本,我错过了这些。任何指针都会很棒。
感谢您的帮助