If a large number is subtracted from a smaller number then borrow is needed. The carry flag plays the role of borrow during the subtraction operation.
Now suppose we want to subtract 66 from 56, obviously the borrow is needed and carry flag will be set. Now how this subtraction is performed to get the result -10, how computer will distinguish that the result is going to be a negative number. Please explain the process.
If a large number is subtracted from a smaller number then borrow is needed.
Share
Normally, subtraction is implemented as a negate, then add. So for your example, the CPU would internally take 56 and add -66. On an x86 (or most other modern processors) the negate will be done with two’s complement, which means negate translates to “complement all the bits, then add one (and ignore any carry out).”
The second operand is transformed as follows:
So the operation that’s carried out is:
This result can be viewed as either 246 (as an unsigned number) or -10 (as a signed number).