0

I have the following C row code:

B[x] = A[x+7] + A[x+2];

Assuming that A is stored in $s0, B in $s1 and x in $t0.

I have got the following MIPS code:

add $t1, $t0, 7  
add $t2, $t0, 2   
lw  $t3, $t1($s0)  
lw  $t4, $t2($s0)  
add $t3, $t3, $t4 
sw  $t3, $t0($s1)

Now my question is, am I allow to use in MIPS code like this: $t0($s1), if not can anybody explain why and what are the other alternatives I can use?

I searched online and I could not get a proper answer to this issue!

Peter Cordes
  • 286,368
  • 41
  • 520
  • 731
  • 1
    No you can't. The reason is that they created the ISA like this :) The alternative is to do the addition yourself. – Jester Oct 14 '18 at 18:23
  • 1
    [Using a register as an offset](https://stackoverflow.com/q/46879095) has a nice answer why the ISA is designed that way. The other two duplicates I linked have some examples of how to do the address math yourself using `addu` and a left-shift. – Peter Cordes Oct 14 '18 at 18:26

0 Answers0