为什么我们要使用 addiu 而不是 addi?

Why would we use addiu instead of addi?

在 MIPS 汇编中,使用 addiuaddi 有什么好处? addiu 不是无符号的吗(会破坏我们的计算?)

and will ruin our calculations

不,MIPS 使用 two's complement,因此 addition/subtraction 的相同指令可用于有符号和无符号操作。结果没有区别。

位指令、非扩展乘法和许多其他操作也是如此。参见

  • Which arithmetic operations are the same on unsigned and two's complement signed numbers?
  • Difference between signed and unsigned on bitwise operations

它们之间的唯一区别是 addi 在溢出时生成陷阱,而 addiu 则不会。所以 addi 及其溢出家族(addsub...)通常是无用的。事实上,它很少被使用,以至于 addi was removed in MIPSr6 将有价值的操作码 space 释放给其他指令

这里的指令名称极具误导性,因为它实际上并不是“无符号”加法。立即数仍然是 符号扩展 而不是零扩展。所以 addiu , , 0xFFFF 实际上会从 </code> 中减去 1,而不是加上 65535。</p> <blockquote> <p>Despite its name, add immediate unsigned (<code>addiu) is used to add constants to signed integers when we don't care about overflow. MIPS has no subtract immediate instruction, and negative numbers need sign extension, so the MIPS architects decided to sign-extend the immediate field.

Computer Organization and Design: The Hardware/software Interface By David A. Patterson, John L. Hennessy

阅读更多Difference between add and addu