mips - Difference between add and addu -


i confused difference between add , addu.

the mips instruction reference says:

  • add (with overflow)
  • add unsigned (no overflow)

my understanding use add signed operands , addu unsigned operands.

but let's consider example (with 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 reasoning:

  • if consider first , second operand signed numbers (two's complement), result correct (-3 + -2 = -5) , don't want overflow exception. use addu avoid exception, but, although result same, name suggests use addu unsigned numbers!
  • if consider first , second operand unsigned numbers, want exception raised (because 61 + 62 not equal 59). use add raise exception, , not addu, name suggest do.

now questions are:

  • assuming operands signed (negative in example above) numbers, should use addu (as reasoning suggests) or should use add (as name suggests)?
  • assuming operands unsigned (positive) numbers, should use add (as reasoning suggests) or addu (as name suggests)?

the instruction names misleading. use addu both signed , unsigned operands, if not want trap on overflow.

use add if need trap on overflow reason. languages not want trap on signed overflow, add useful.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -