1

How to load and store word from address that index is in a register? in Assembly MIPS
Example:

lw $t0, $a0($t1)  and sw $t0,$a0($t1)  

Those intructions is just for what I will do (incorrect) Thanks

sushant-hiray
  • 1,838
  • 2
  • 21
  • 28
Phiber
  • 1,041
  • 5
  • 17
  • 40

2 Answers2

2

Try doing this instead of your only lw statement:

add $a0 $a0 $t1
lw $t0 0($a0)
sub $a0 $a0 $t1

The last sub is needed only if you want to restore $a0 back to the original value.

You can do the same thing for the sw part.

sushant-hiray
  • 1,838
  • 2
  • 21
  • 28
  • tanks!!!!, i have another probleme that $ao is integer that increment +1, so added sll $a0 ,$a0,2 after to multiply this integer by 4 and now it's work – Phiber Nov 25 '13 at 07:52
1

Microchip microcontrollers contain DSP-extensions with instructions:

LBUX rd, index(base)  # load byte
LHX rd, index(base)   # load half-word
LWX rd, index(base)   # load word

Where "index" and "base" is GPR registers.

But I did not find the same instructions for storing.

7profy
  • 54
  • 4
  • An equivalent store would have 3 register inputs, vs. a load only having 2 inputs (and one register output). That might be why Microchip added load versions but not stores. Mainstream MIPS [didn't like that lack of orthogonality](https://stackoverflow.com/questions/46879095/using-a-register-as-an-offset#comment80708536_46880563), even though some arrays are read-only. Later mainstream MIPS has indexed loads/stores for *FP* registers, not GPRs. – Peter Cordes Jan 12 '22 at 13:12