我的MIPS代码有问题...我会检查键盘传递的字符串中的匹配项,而不是要比较的字符。我在堆栈中有一个字符串(堆栈位置为-255 ),在.data部分中有一个数组来存储匹配项。基本思想是,我使用循环(lb $t1,($a0) t1= letter - a0=堆栈的ascii代码在函数处传递)逐个从堆栈加载一个字母,使用97 (97=a)减去从堆栈读取的字母并获得数组的索引,然后使用另一个循环计算出现的次数并将其保存在前面计算的索引下。显然,该数组有104个位置(26个字母*4,因为我会保存出现的次数)。问题是,当我找到我的数组位置的索引,并且我会用sw $--,myArray($--) Mars将出现的内容保存在这个位置中时,Mars会给我这个错误:运行时异常在0x0040007c:存储地址不对齐在字边界0x10010087我试图在.data部分添加.align,但我没有找到解决方案,可能我弄错了一些东西……有什么帮助吗?
这是我的代码:
analizza_stringa: (function)
while_string:
# load a byte from the stack
lb $t0, ($a0)
#check end string
beq $t0, $zero, end
#check a line feed
beq $t0, 10, end
#array index
subi $t3, $t0, 97
#Multiply by 4 (I would save number)
mul $t4, $t3, 4
while_occorrenza:
#like before
beq $t1, 10, continue
#load a letter like before
lb $t1,($a0)
#Check the occurrences
bne $t1, $t0, continue2
#add 1 at the occurrences
addi $t5, $t5, 1
continue2:
#add 1 for the pointer at the string
addi $a0, $a0, 1
#Repeat
j while_occorrenza
continue:
#Save the number under the index calculated before
sw $t5, myArray($t4)
#counter=0 for another loop
li $t3, 0
#next character
addi $a0, $a0, 1
# repeat the first loop
j while_string
end:
jr $ra发布于 2017-01-31 20:44:29
如果要访问内存中的单词,地址必须与单词对齐(4的倍数)。
假设$t4包含4的倍数,这意味着myArray不是单词对齐的。要解决这个问题,您可以在数据部分中myArray之前的行上添加.align 2。
https://stackoverflow.com/questions/41954604
复制相似问题