MIPS “Unaligned address, Exception 5” error

本小妞迷上赌 提交于 2019-12-11 10:01:58

问题


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.

The code:

.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

回答1:


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.

See this wiki for documentation about alignment, and the .align directive that can be used to force alignment.



来源:https://stackoverflow.com/questions/14137003/mips-unaligned-address-exception-5-error

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!