Difference between "addi" and "add" for pseudoinstruction "move" in MIPS?
The addi
instruction requires an immediate operand rather than a register, so the $0
would actually be 0
:
add $rt, $rs, $0
addi $rt, $rs, 0
Both will work and have all the needed information encoded into the instruction itself):
add $d, $s, $t
0000 00ss ssst tttt dddd d000 0010 0000
addi $t, $s, i
0010 00ss ssst tttt iiii iiii iiii iiii
However, it would be more usual to just use the zero-locked $0
register in this particular case since that is, after all, its purpose.
I would also tend to use the unsigned variant however, since I seem to recall there may be extra overflow checking done for signed instructions:
addu $rt, $rs, $0
izelkay
Updated on September 14, 2020Comments
-
izelkay over 3 years
For this pseudoinstruction:
move $rt, $rs
Are both the addi and add assembly code acceptable? So could I use either
add $rt, $rs, $0
or
addi $rt, $rs, $0
?
Edit: I think I made a mistake with
addi
add $rt, $rs, $0
would be the same as
addi $rt, $rs, 0
since
add
adds registers, and I need a constant for the immediate foraddi
-
izelkay over 8 yearsThanks, yeah I thought so. I edited my question to reflect this just as you answered, but I understand now.
-
Yu Chen over 6 yearsAre there any performance benefits to using one instruction rather than the other?
-
paxdiablo over 6 years@YuChen, see stackoverflow.com/questions/44249629/…