0

I am new to mips assembly. I cant get what exactly those instructions do so I try to test it. This a code to switch values of the registers t0 and t1.

# Perform swap.
    lw  $t3, 0($t0)
    lw  $t4, 0($t1) 
    sw  $t3, 0($t1)
    sw  $t4, 0($t0)

The code seems reasonable,storing their values in t3 and t4 and then swapping them. The thing I can't understand here is why we cant use move or load word here instead of store word? For example why the code cant not be like this?

# Perform swap.
    lw  $t3, 0($t0)
    lw  $t4, 0($t1) 
    move $t1,$t3
    move $to,$t4

Or like this

# Perform swap.
lw  $t3, 0($t0)
lw  $t4, 0($t1) 
lw  $t1,0($t3)
lw $t2,0($t4)
Ben Bitdiddle
  • 25
  • 1
  • 4

1 Answers1

1

Store word (4 bytes) : to take content from register and store it in memory

Load word (4 bytes): It's strictly the opposite, get value from memory emplacement and store it in register

Move: it's copy value from register 1 (for example) and put it to another register

nissim abehcera
  • 821
  • 6
  • 7
  • `move` does not really have a size, it's going to move the entire register. So it will depend on the processor you're running with (4 bytes in mips32 and 8 in mips64) – Alexis Wilke Feb 27 '19 at 17:19
  • You're right , but why in Gnu assembly , there are many move like movq or movb etc... – nissim abehcera Feb 27 '19 at 17:22
  • The movq, movb, etc. are INTEL instructions. In MIPS, there isn't an actual `move` instruction anyway. It's usually converted to `add $dst, $zero, $src` (adding zero to source and saving it in destination is equivalent to _moving_ $src to $dst.) – Alexis Wilke Feb 27 '19 at 18:02