0

I want to write

.text
main:
    lw  $t2, c

.data 
c: .word 1

without using lw, on mars I tried

 add    $t2,$t2,c

and also

addi    $t2,$t2,0($c)

but they dont work How do I do this

Ben Bitdiddle
  • 25
  • 1
  • 4
  • 3
    You can't do that. If you need to avoid `lw` specifically, you can reproduce its behavior using `lb`. – Jester Feb 24 '19 at 11:31
  • 1
    MIPS is a [load/store architecture](https://en.wikipedia.org/wiki/Load%E2%80%93store_architecture), which means only loads and stores can access memory. You can't do that with add or any other instructions – phuclv Feb 24 '19 at 15:15
  • @Jester: or two `lhu` instead of 4 `lbu` (and you would want lbu to zero-extend, not sign-extend with `lb`). Or LWL / LWR unaligned-load instructions. (https://blogs.msdn.microsoft.com/oldnewthing/20180409-00/?p=98465). For addresses that actually are aligned, you only need one of those two. – Peter Cordes Feb 24 '19 at 18:30

0 Answers0