How to make an update an array in MIPS?
I'm trying to make an array, and then update the values of certain cel开发者_运维问答ls if needed. From what I know, using the Stack Frame would be the best approach, but I can't get it to work. Anyone able to point me in the right direction?
Thanks!
You should already have a good understanding of how array manipulation works in a language like C.
If you want to put an array in the current stack frame, and manipulate it there (and understand the benefits and issues of doing so), then you should do the following:
- First, take note of the current value of the stack pointer register (
$sp
). You will use this as the pointer to the start of the array. Store it in another register. - First increment the stack pointer register (
$sp
) by however many bytes the array is. This will give you enough space to work. - When you want to update the array, compute the address of the start of the array plus the array index. For example, to write or read element 5, add 5 to the start of the array, times the word size. On a 32-bit machine, multiply it by 4.
- Use the
sw
instruction to store a word in the array at that address, and uselw
to load a word.
精彩评论