【问题标题】:Why I have the error "store address not aligned on word boundary"为什么我有错误“存储地址未在字边界上对齐”
【发布时间】:2017-01-31 10:02:41
【问题描述】:

我的 MIPS 代码有问题...我会检查键盘传递的字符串中出现的情况,但没有要比较的字符。我在堆栈中有字符串(堆栈 -255 位置)和 .data 部分中有一个数组来存储出现的次数。基本思想是我用循环从堆栈中一个接一个地加载一个字母(lb $t1,($a0)t1=字母的ascii代码-a0=函数传递的堆栈),减去读取的字母从堆栈中用 97 (97=a) 获取数组的索引,然后使用另一个循环,计算出现次数并将其保存在之前计算的索引下。显然,该数组有 104 个位置(26 个字母 * 4,因为我会保存出现次数)。问题是,当我找到我的数组位置的索引并且我会在该位置内保存使用 sw $--, myArray($--) 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

【问题讨论】:

    标签: mips spim


    【解决方案1】:

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

    假设 $t4 包含 4 的倍数,看起来确实如此,这意味着 myArray 不是字对齐的。要解决此问题,您可以在数据部分的 myArray 之前的行中添加 .align 2

    【讨论】:

    • 非常感谢迈克尔!!!现在我可以将我的出现保存在数组中。谢谢谢谢!
    猜你喜欢
    • 2013-12-23
    • 1970-01-01
    • 1970-01-01
    • 2016-08-24
    • 2017-06-25
    • 2014-05-27
    • 2012-03-05
    • 2016-08-06
    • 1970-01-01
    相关资源
    最近更新 更多