Page 1 of 1

need help understanding the carry flag..

Posted: Fri Aug 11, 2017 5:44 pm
by malis2007
Hello there :)
i have a problem understanding the carry flag :/
i added these lines to the SUB instruction in the CE's step 2 TUT

Code: Select all

pushad
pushfd
mov eax,2
add eax,1
popfd
popad
after the add instruction, why is the carry flag being set? (CF=1)
Image
and why is it cleared (CF=0) when i replaced this code:

Code: Select all

mov eax,2
with either 7,A or even F the carry flag is cleared? (CF=0)
e.g.

Code: Select all

mov eax,F
Image

Thanks for reading, and your help inadvanced.. :)

Re: need help understanding the carry flag..

Posted: Tue Aug 15, 2017 2:09 pm
by gir489
[Link], the CF is set if an arithmetic operation generates a carry of the most significant bit. It also indicates an overflow condition for unsigned integers.

You'll notice that the AF flag was set on your 2nd permutation of the code. That's the Adjust Flag. This means that the lower 4 bits were carried instead.

Re: need help understanding the carry flag..

Posted: Thu Aug 17, 2017 3:05 pm
by malis2007
gir489 wrote:
Tue Aug 15, 2017 2:09 pm
[Link], the CF is set if an arithmetic operation generates a carry of the most significant bit. It also indicates an overflow condition for unsigned integers.

You'll notice that the AF flag was set on your 2nd permutation of the code. That's the Adjust Flag. This means that the lower 4 bits were carried instead.
Thanks for your reply,

but how does it set the carry flag when we add 2 to 1?
0010
+0001
-----
0011

Re: need help understanding the carry flag..

Posted: Fri Aug 18, 2017 3:15 pm
by gir489
0 was carried.