1

I can't seem to visualize how this works. I'm trying to translate this simple assignment from C to mips:

#define ARRAYSIZE 16
int intarray[]={1, 5, -3, 6, 12, 21, 18, 44, 32, 9, 23, 10, 11, 99, 100, 24};

intarray[little] = intarray[ARRAYSIZE-1];

So I define the array in the data

.data
  intarray: .word 1, 5, -3, 6, 12, 21, 18, 44, 32, 9, 23, 10, 11, 99, 100, 24

Now the problem is I know how to load a word from this array easy enough

lw $t0, intarray($a0)

But I can't figure out how to save to that array because it's not located in a register. Can I even manipulate that array, or do I have to build a duplicate array in the registers?

Voxorin
  • 89
  • 10
  • _"But I can't figure out how to save to that array"_ By using the `sw` instruction. – Michael Jul 26 '18 at 05:46
  • `sw` saves to a register, but how does that turn an array from `array[1, 2, 3]` to `array[1, 4, 3]`. I mean I could save `array[1]` or `array[2]` to register `$s0`, but how does that help me return the mutated array `array[1, 4, 3]`. Do you understand what I'm getting at? – Voxorin Jul 26 '18 at 13:04
  • _"sw saves to a register"_ No. It takes the value of a register and stores it in memory. – Michael Jul 26 '18 at 13:11

1 Answers1

1

I was mixing up lw and sw, thinking in assembly can be confusing at first. It turns out the answer I was looking for was that you need to first load the base address of the array(la address) and then call sw register address.

Voxorin
  • 89
  • 10