arraysassemblymipspcspim

Converting C++ code to Mips


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?


Solution

  • 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.