Search code examples
assemblymipsmars-simulator

How to load and store word from/to address that index is in a register, MIPS


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


Solution

  • 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.