为什么我有错误"store address not aligned on word boundary"



我的MIPS代码有问题。。。我会检查键盘传递的字符串中的出现情况,而不需要比较字符。我在堆栈中有一个字符串(堆栈-255位置),在.data部分有一个数组来存储出现的情况。基本思想是,我用循环(lb$t1,($a0)t1=字母的ascii代码-a0=函数传递的堆栈)从堆栈中一个接一个地加载一个字母,用97(97=a)减去从堆栈中读取的字母,获得数组的索引,用另一个循环计算出现次数,并将其保存在之前计算的索引下。显然,数组有104个位置(26个字母*4,因为我会节省出现的次数)。问题是,当我找到数组位置的索引并将其保存在该位置内时,sw$--、myArray($--)Mars的出现会给我以下错误:0x0040007c处的运行时异常:存储地址未在字边界0x10010087上对齐我试着在.data部分添加.aalign,但我没有找到解决方案,也许我做错了一些事情。。。有什么帮助吗?

这是我的代码:

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

如果要访问内存中的一个字,地址必须与字对齐(4的倍数)。

假设$t4包含4的倍数,这似乎是这样的,这意味着myArray不是单词对齐的。要解决此问题,您需要在数据节中myArray之前的行中添加.align 2

最新更新