assembly - carry flag and subtraction issue -


If a large number is reduced by a small number then borrowing is necessary. The leary flag plays the role of borrowing during subtraction. Now suppose we want to subtract 56 from 66, obviously there is a need to borrow and the flag will be determined. Now the result of this subtraction is done to get -10, how the computer will distinguish that the negative result is going to be done. Please explain the process. Normally, subtraction is applied as a negation, then add.

So for your example, the CPU will internally carry 56 and add-66. On an x86 (or other other modern processor), the negation will be done with the complement of two, which means "to negate translations to complement all the bits, then add one (and ignore any kind of information ). "

  0011 1000 - 0100 0010 ---------  

The second operand has been changed as follows:

  Complementary Bits: 1011 1101 Enhance: 1011 1110  

The operation done is therefore:

  0011 1000 + 1011 1110 ------ ------- = 1111 0110  

This result can be seen as either 246 (as an unsigned number) or -10 (as a signed number) is.


Comments