Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Value in Carry Flag

Tags:

x86

assembly

masm

If I do the following (where cx has 0b1011 or 11 in decimal prior to the shift):

 shl cx, 1

After shl, the carry flag should be set. As shl will move 0b1011 to 0b0110 and 1 will be in CF.

My question is: how do I access the value in the carry flag? Let's say I want to append it to register bx, obviously mov bx, cf does not work so how would you go about doing that?

like image 841
user3211189 Avatar asked Dec 26 '22 13:12

user3211189


2 Answers

That's what "add-with-carry" is for:

adc bx, 0   ; adds "0" plus the value of CF to bx

If you want to set a (byte) register exactly equal to the value of the carry flag, use "set-if-carry":

setc bl     ; BL = CF ? 1 : 0
like image 77
Kerrek SB Avatar answered Dec 31 '22 14:12

Kerrek SB


You should probably use the JC and JNC conditional branching instructions to determine if the flag is set or not.

There is also the PUSHFD instructions to dump the entire EFLAGS to the stack.

like image 42
typ1232 Avatar answered Dec 31 '22 14:12

typ1232