开发者

How to make an update an array in MIPS?

开发者 https://www.devze.com 2023-02-10 08:46 出处:网络
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. Any

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:

  1. 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.
  2. First increment the stack pointer register ($sp) by however many bytes the array is. This will give you enough space to work.
  3. 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.
  4. Use the sw instruction to store a word in the array at that address, and use lw to load a word.
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号