开发者

Unsigned binary subtraction when numbers are too large to form two's complement

I am in computer architecture and my prof. hasn't been able to give a satisfactory answer.

Assuming we have a 32-bit processor, if we have two unsigned integers x and y, both of which are greater than 231 (so that they are too large to be converted properly to two's complement form) how do we perform subtraction?

If the subtrahend was a constant I can see how the compiler 开发者_如何学运维could compensate for this in static analysis. But how do we deal with this possibility at runtime, especially in a statically-compiled language like C? Does this just throw an overflow error or do some architectures subu support special operations?

Everything I find for MIPS says that it just performs two's complement subtraction, but that shouldn't work in this case, should it?


The situation you pose is not a problem. Specific example:

  0xFFFFFFFF -  0xFFFF0000
= 0xFFFFFFFF + -0xFFFF0000
= 0xFFFFFFFF +  0x00010000
= 0x0000FFFF
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜