Notch carry flag

I am using MASM32.

With this code:

mov eax,5
sub eax,10

The CF status flag will be set. But, using my pencil and paper, I really see that there are no transfers from MSB. Yes, I know that by subtracting from a smaller amount of a large number, CF is set. But I want to know why?

Because using this code:

mov eax,5
mov ebx,10
not ebx
add ebx,1
add eax,ebx

The CF flag will never be set.

+5
source share
2 answers
5 - 10 = 5 + (-10) = 0x05 + (0xF5 + 1) = 0x05 + 0xF6 = 0xFB

  00000101 -- 0x05
  11110101 -- 0xF5
+ 00000001 -- 0x01
==========
  11111011 -- 0xFB

And this goes on for 16 or 32 or 64 bits 0 + 1 + 0 = 1, carry 0

You are right in the sense that this is not being done. Subtraction is an addition with the second operand inverted and the translation in the translation. Some processor families invert some of them. It looks like you are looking at what inverts execution to subtract.

, 5 - 10 (), 10 - 5 , ( ).

- , , , , .

+5

, . , eax 8- ,

    eax=00000101=05
    ebx=00010000=10
not ebx=11101111
         +     1
---------------------
        11110000
         +  0101
 ---------------------
        11110101

, .

+1

All Articles