Note that in two's complement, non-negative numbers have an implicit infinite number of leading 0's, and negative numbers have an implicit infinite number of leading 1's.
For example,
0 = 00000000 = 00000000 00000000( = 010 )00010 = 00000010 = 00000000 00000010( = 210 )11110 = 11111110 = 11111111 11111110( = -210 )01101 = 00001101 = 00000000 00001101( = 1310 )10011 = 11110011 = 11111111 11110011( = -1310 )
addu, subu, and
            addiu all ignore overflow (unsigned integer
            calculations); the "sign bit" gives
            an extra digit's worth of positive numbers we can express.
            Prove: -x = x + 1
[In our examples, we will assume that integers are 8 bits long, but the proof applies to binary integers of any length (e.g., 16 bits, 32 bits, 64 bits).]
Let
xrepresent the one's complement ofx.Note that in two's complement, the definition of
-1is11111111(the result of subtracting1from0).Note that
x + x = 11111111 = -1. This is true because for every0inx, the corresponding bit inxis1, yielding a sum bit of1, and for every1inx, the corresponding bit inxis0, again yielding a sum bit of1. For example:0000110113+ 11110010one's complement of 13----------11111111Since
we can add one to both sides and getx + x = -1x + x + 1 = 0Now, by definition,
so, substitutingx + (-x) = 0x + (-x)for 0 in our previous result, we haveorx + x + 1 = x + (-x)orx + 1 = (-x)(-x) = x + 1