0

I am trying to make an array to which I have provided the data at compile time in MIPS. but I am getting error and thus the code is not getting compiled. Here is the chunk of code which is causing error.

.data

array: .space 'A','B','C','D','E','F','G','H','I'

What is the reason for error? If you know any tutorials which explain arrays of .space, .byte and .word, please mention them in answer.

Regards

Naruto
  • 1,710
  • 7
  • 28
  • 39

1 Answers1

1

You can't use .space directive for initialized arrays. .space is for reserving N uninitialized bytes. You can use .byte or .word for such purpose, depending on the size of your data. In your example, you're using ASCII characters, so .byte should be OK.

.data

array: 
.byte 'A','B','C','D','E','F','G','H','I'

Any MIPS assembly reference should be OK. Here's one.

m0skit0
  • 25,268
  • 11
  • 79
  • 127
  • but with .byte I get "Memory Address out of bound error"? What should I do – Naruto Oct 14 '12 at 12:09
  • add $s4,$t1,$t0 lb $a0,0($s4) li $v0,4 syscall when the simulator executes this statement, the error is generated – Naruto Oct 14 '12 at 12:10
  • You didn't post the code. Also I recommend [MARS MIPS simulator](http://courses.missouristate.edu/kenvollmar/mars/), for me way better than SPIM. – m0skit0 Oct 14 '12 at 16:45