39

I was practicing converting C code into MIPS assembly language, and am having trouble understanding the usage of move and li in variable assignment.

For example, to implement the following C line in MIPS:

int x = 0;

If I understand it correctly (I highly doubt this, though), it looks like both of these work in MIPS assembler:

move $s0, $zero
li $s0, $zero

Am I wrong? What is the difference between these two lines?

Palec
  • 12,743
  • 8
  • 69
  • 138
user2492270
  • 2,215
  • 6
  • 40
  • 56

2 Answers2

65

The move instruction copies a value from one register to another. The li instruction loads a specific numeric value into that register.

For the specific case of zero, you can use either the constant zero or the zero register to get that:

move $s0, $zero
li   $s0, 0

There's no register that generates a value other than zero, though, so you'd have to use li if you wanted some other number, like:

li $s0, 12345678
  • 42
    You should also be aware that "move" and "li" are both "pseudo-instructions". "move $s0,$s1" might really be "add $s0,$0,$s1". A "li" instruction might be the combination of a "lui" and a "ori" instruction so "li" may even be two instructions. – Martin Rosenau Nov 07 '13 at 06:58
  • So `li` is conceptually the same as move-immediate? – Zaz Jul 06 '23 at 18:19
0

the move instruction moves the value of one register to another while li just loads an immediate value to a register.

RusJaI
  • 666
  • 1
  • 7
  • 28