1

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
Jens Björnhager
  • 5,632
  • 3
  • 27
  • 47
Israel
  • 1,184
  • 2
  • 13
  • 26

1 Answers1

3

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.

unwind
  • 391,730
  • 64
  • 469
  • 606
  • Ok, I now see how I step, and I see that after the la, $s3 holds the address 268500992: "Reg 19 = 0x10010000 (268500992)" – Israel Jan 03 '13 at 10:58
  • Thanks, adding ".align 2" right after ".data" solved the problem (Please don't mind the previous comment). – Israel Jan 03 '13 at 11:05