Mathematically, you are not adding a signed or unsigned number. There are only modulo 2 32 values (assuming you have 32-bit registers). These values cover a range of 2,332 consecutive integers, but you can interpret this range as a start almost anywhere. “Signed” and “unsigned” are just two such interpretations.
In other words, with 4-bit registers, the unsigned interpretation of “1011” is eleven, and the signed interpretation is minus five. But there is only one meaning (which mathematicians usually call "eleven modulo 2 4 " because mathematicians traditionally love an unsigned interpretation). For example, if you add “0110” to this value (which is “six” in both signed and unsigned interpretations), then you get “0001”, which is the correct value: minus five plus six lessons one, and eleven plus six - seventeen, which is also equal to one when decreasing modulo 2 4 (seventeen is one plus sixteen, "decreasing modulo 2 4 " means dividing by sixteen (2 4 ] and keeping only the remainder).
Another way of saying this is as follows: the number of (binary) digits for a numerical value is conceptually infinite to the left. The CPU register stores only 32 of the rightmost bits. An unsigned interpretation assumes that conditionally all left bits are equal to zero. The signed interpretation is the assumption that it is conditional that all left bits have the same meaning as bit 31 (i.e., all are equal to zero or they are all equal to one). In any case, when you perform addition (or subtraction or multiplication), the transfer propagates from right to left, and not vice versa, so the values of those ignored bits have nothing to do with the 32-bit result. Thus, there is only one “add” operation code, which does not bother at all about whether its operands are in the programmer’s brain, “signed” or “unsigned”.
When performing an operation that is incompatible with modular arithmetic, the signature must be taken into account. Converting to a sequence of decimal digits for display is such an operation. However, a more frequent case is comparison. Modulo 2 32 values are not ordered; they are in the form of a cyclic loop (when you add 1 to 2 32 -1 and decrease modulo 2 32 you return to 0). Comparison makes sense only when you consider integers in the entire range of integers. At this point, you must decide whether you are using a signed or unsigned interpretation. That is why x86 processors offer both jg (leap, if greater, signed interpretation), and ja (leap, if higher, unsigned interpretation).
source share