1

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 for addi

izelkay
  • 47
  • 2
  • 2
  • 7

1 Answers1

2

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
paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953
  • Thanks, yeah I thought so. I edited my question to reflect this just as you answered, but I understand now. – izelkay Sep 14 '15 at 03:17
  • Are there any performance benefits to using one instruction rather than the other? – Yu Chen Jan 31 '18 at 01:36
  • 1
    @YuChen, see https://stackoverflow.com/questions/44249629/mips-amount-of-cycles-for-i-type-instructions-addi – paxdiablo Jan 31 '18 at 01:39