0

I am converting a C++ project in Mips assembly language. In c++ you can initialize an array like

int array[5]={1,2,3,4,5};

How can I initialize an array of characters in MIPS assembly language?

pb2q
  • 58,613
  • 19
  • 146
  • 147
Naruto
  • 1,710
  • 7
  • 28
  • 39

1 Answers1

0

In MIPS assembly you would instruct the assembler to statically allocate enough memory for the array, and its initial value using the directives .data and .word. E.g:

.data
arrayOfInts:
.word 1, 2, 3, 4, 5
arrayOfChars
.word 'a', 'b', 'c'

This works for compile-time defined variables. If your intent is to dynamically allocate the array you'd have to do it yourself.

gusbro
  • 22,357
  • 35
  • 46
  • Does this work with .space cuz I am getting error with .space – Naruto Oct 14 '12 at 11:26
  • @UmerFarooq: With `.space` you have to tell the assembler how many bytes to reserve, but not the actual values. e.g. `.space 32` to reserve 32 bytes – gusbro Oct 14 '12 at 15:57
  • I have used .byte but I get "Memory out of bound error" in QTSPIM – Naruto Oct 14 '12 at 16:22
  • The directive is a compile-time mechanism. If you are getting this error at runtime then i guess its not related to this directive. If you are getting that error at compile-time maybe you need to put first a `.data` directive (e.g. `.data 0x2000`) to tell the compiler where is your data segment. – gusbro Oct 14 '12 at 19:38