0

I was trying to write a MIPS program that runs similar to the C code below

int main{
unsigned int x = 1;
unsigned int y = 11;
while (x < 6) {
int temp = myArray[x];
myArray[x] = myArray[y];
myArray[y] = temp;
x+=2;
y-=2;
}

And I have my array defined as below (I can only use .word in this case)

    myArray:
        .word 29 17 27 20 25 22 23 24 21 26 19 28

I've done the initialization and the ending part but don't know how to do within the loop

    li $v0 1
        li $v1 11
        li $v2 6

        loop:
        bge $v0 $v2 loopexit
        
        addi $v0 $v0 1
        sub $v1 $v1 1

I'm wondering how can I perform the myArray[x] using MIPS? I'm thinking of bit masking but I'm not sure how to do it with a changing number

  • `myArray[x]` is array indexing, selecting which array element (word) to load or store. [C to MIPS - functions and arrays](https://stackoverflow.com/q/54858960). Not shifting to access bits within one word. Look at C compiler output for MIPS. ([Tweak mips-gcc output to work with MARS](https://stackoverflow.com/q/13052444)) – Peter Cordes Oct 22 '22 at 22:08
  • Or to put it another way, the bits you want to extract are aligned 32-bit chunks from a very wide bit-array. A special case of bitfield extraction that can and should be done with word loads/stores. – Peter Cordes Oct 22 '22 at 22:18

0 Answers0