I am confused about the difference between add and addu.
The MIPS instruction reference says:
My understanding is to use add with signed operands and addu with unsigned operands.
But let's consider this example (with only 6bit):
overflow | V 1 | 1 1 1 <- carry | 1 1 1 1 0 1 + | 1 1 1 1 1 0 = ----------------- | 1 1 1 0 1 1
And this is my reasoning:
Now my questions are:
The instruction names are misleading. Use addu
for both signed and unsigned operands, if you do not want a trap on overflow.
Use add
if you need a trap on overflow for some reason. Most languages do not want a trap on signed overflow, so add
is rarely useful.