我不能完全弄清楚我在彙編代碼中做錯了什麼。我想有時「主:」在寫比較兩個空值終止被輸入爲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過程。這是我第一次編寫彙編代碼,所以我認爲這些東西真的很基本,我錯過了這些。任何指針都會很棒。
感謝您的幫助