Hello. I'm just scratching the surface of Assembly for the first time and am trying to figure out how to manipulate arrays.

It's my understanding that arrays live in RAM, and RAM ONLY. So you must load the piece of the array you want to mess with into a register, then store it back into RAM when your done messing with it. So here's my question:

What if I want to access say x[5] when all I know is x[0] is stored in memory address 1,000,000. When I'm done, I want to put it into x[6]. Would something like this work? If not, please help me find my miss-understanding. Thanks for any help

lw $t0, 5(1000000)
addi $t0, $t0, 1
sw $t0, 6(1000000)
Posted on 2010-02-06 19:26:07 by TheTechNoob
I'm not familiar with the syntax of the assembler you're using, nor with the CPU, but I think you've got it approximately right... provided that the "items" in your array are one byte in size. If you had an array of double-precision floats, taking up 8 bytes each, "p++" in C would advance the pointer by 8 bytes (C knows what we're pointing to, 'cause it insists on being told). Asm will not do this for you! I don't know if syntax like "lw $t0, 5 * 8(1000000)" would be acceptable to your assembler, but you'd have to advance the address by 8 bytes for each item. Does the "w" in the instruction imply "word"? Two bytes, possibly? If so, you'd need to increase the address by two for each item. Hopefully, someone more familiar with your setup will be along with a better answer.

You ask "will this work?". I dunno, does it? Presumably, you've got the "laboratory" at hand. Do the experiment! If you're "afraid of the machine", you'll never get anywhere. Errors and crashes aren't "punishment", they're learning tools! :)

Best,
Frank

Posted on 2010-02-07 16:31:40 by fbkotler

I'm not familiar with the syntax of the assembler you're using, nor with the CPU,


Vaguely reminds me of MIPS.
Posted on 2010-02-07 19:13:02 by SpooK