MIPS“未对齐地址,例外5";错误 [英] MIPS "Unaligned address, Exception 5" error
问题描述
我是使用SPIM MIPS模拟器的菜鸟.
当我尝试将26个单词的数组初始化为0时,标题X出现了26次错误.我已将问题隔离为存储字操作sw $t0, 0($s3)
,但不知道我在做什么错.
I'm a noob using SPIM MIPS simulator.
I get the error in title X 26 times, when I try to initialize an array of 26 words to 0. I've isolated the problem to be the store word operation sw $t0, 0($s3)
, but have no clue what am I doing wrong.
代码:
.data
theArray: .space 104
theArraySz: .word 26
.text
.globl main
main:
move $t0, $zero
la $s3, theArray
lw $s4, theArraySz
add $t2, $zero
initLoop:
beq $t2, $s4, initEnd
sw $t0, 0($s3)
addi $s3, $s3, 4
addi $t2, $t2, 1
j initLoop
initEnd:
jr $ra
推荐答案
确保theArray
的地址与32位字边界对齐.如果您有能力单步执行程序,则可以检查该地址,并在第一条la
指令后检查$s3
的值.
Make sure the address of theArray
is aligned to a 32-bit word boundary. You can inspect the address if you have the ability to single-step through the program, and check the value of $s3
after the first la
instruction.
有关对齐的文档和.align
指令,请参见此Wiki .可以用来强制对齐.
See this wiki for documentation about alignment, and the .align
directive that can be used to force alignment.
这篇关于MIPS“未对齐地址,例外5";错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!