1

I have a function that takes a memory address as $a0 and I access the (variable) number of words by using x($a0), where x is multiples of 8. I need to store these in the $sp register so I can use the $a0 register for passing arguments to other functions. Completely new to MIPS assembly, so any pointers here would help!

Stack Player
  • 1,470
  • 2
  • 18
  • 32
sff
  • 73
  • 3

1 Answers1

0

Multiples of 8 i assume you are using mips-64

first u make a loop and increment a0 by 8 each time:

loop: lw $t0, 0($a0)   ;fetch data and store in t0
      addi $sp,$sp,-8  ;increase stack
      sw $t0, 0($sp)   ;store data fetched
      addi $a0,$a0,8   ;increment a0 to go to next entry
;here you check that you haven't reached x yet
;let's say 8*x+$a0(initial) is stored in $t1 (this is easy to do just use sll by 3 to multiply by 8 then add a0 before loop)
      bne $a0,$t1,loop
;now you can use $a0
Stack Player
  • 1,470
  • 2
  • 18
  • 32