need help understanding the carry flag..

malis2007

What is cheating?
Jul 31, 2017
4
0
1
#1
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:
pushad
pushfd
mov eax,2
add eax,1
popfd
popad
after the add instruction, why is the carry flag being set? (CF=1)

and why is it cleared (CF=0) when i replaced this code:
Code:
mov eax,2
with either 7,A or even F the carry flag is cleared? (CF=0)
e.g.
Code:
mov eax,F


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

gir489

RCE Fanatics
Talents
May 8, 2017
191
13
18
#2
According to the x86 official documentation from Intel, 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.
 

malis2007

What is cheating?
Jul 31, 2017
4
0
1
#3
gir489 post_id=15407 time=1502806177 user_id=3979 said:
According to the x86 official documentation from Intel, 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
 
Top Bottom