Difference between "move" and "li" in MIPS assembly language

user2492270 picture user2492270 · Nov 7, 2013 · Viewed 114.2k times · Source

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?

Answer

duskwuff -inactive- picture duskwuff -inactive- · Nov 7, 2013

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