Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MIPS instruction set move vs add/addi 0 for storing values?

Tags:

assembly

mips

I'm currently taking a Computer Organization and Assembly Language course that mainly uses the MIPS instruction set to teach assembly language.

I noticed that many of the examples that the professor has posted online use add or addi to move a value into the $a0 argument register for calling print services like the following...

# store the first integer in $a0 and print
add $a0, $zero, $t0
li $v0, 1
syscall

or...

# store the first integer in $a0 and print
addi $a0, $t0, 0
li $v0, 1
syscall

I've also noticed some examples online where others just use the move instruction to accomplish the same thing like the following...

# store the first integer in $a0 and print
move $a0, $t0
li $v0, 1
syscall

Is using the add or addi instruction preferred over simply using move in this scenario? If so then why? Is there a performance difference or is this just a matter of taste?

like image 276
Anthony Jack Avatar asked Feb 03 '23 08:02

Anthony Jack


1 Answers

The move instruction is not a real instruction - it is a pseudo instruction that is translated into an add instruction by the assembler.

There are a whole bunch of these pseudo instructions, see e.g. https://en.wikipedia.org/wiki/MIPS_architecture#Pseudo_instructions

This type of thing is very common on RISC processors, where you want a minimal instruction set, and a particular instruction may be used for more than one purpose.

like image 122
Paul R Avatar answered Feb 05 '23 17:02

Paul R