Read carry flag

  • Follow


	Hi,

does the x86 ISA pport an instruction to read the 
carry flag and move it to a register?

Something like this:

mov ecx, 32
move edx, 0
loopL:
shl eax, 1
XXX ebx ; load carry flag into ebx (zero extended)
add edx, edx, ebx
loop loopL


Is there any instrtuction for XXX?

Regards,
Chris

0
Reply Christian 5/24/2006 12:32:42 PM

Christian Christmann wrote:
> mov ecx, 32
> move edx, 0
> loopL:
> shl eax, 1
> XXX ebx ; load carry flag into ebx (zero extended)
> add edx, edx, ebx
> loop loopL
> 
> 
> Is there any instrtuction for XXX?

Well, why don't you change the add to an adc? Are you going to use the 
carry flag in ebx for anything else?


Bjarni
-- 

                        INFORMATION WANTS TO BE FREE

0
Reply Bjarni 5/24/2006 6:48:50 PM


Christian Christmann wrote:
> Hi,
>
> does the x86 ISA pport an instruction to read the
> carry flag and move it to a register?
>
> Something like this:
>
> mov ecx, 32
> move edx, 0
> loopL:
> shl eax, 1
> XXX ebx ; load carry flag into ebx (zero extended)
> add edx, edx, ebx
> loop loopL
>
>
> Is there any instrtuction for XXX?
>
> Regards,
> Chris

Well, there is LAHF and SAHF (load/store AH / flags).
Of course,you can also use
mov 0, ebx
rcl ebx, 1

Cheers,
Randy Hyde

0
Reply randyhyde 5/24/2006 7:59:20 PM

Christian Christmann wrote:
> Hi,
>
> does the x86 ISA pport an instruction to read the
> carry flag and move it to a register?
>
> Something like this:
>
> mov ecx, 32
> move edx, 0
> loopL:
> shl eax, 1
> XXX ebx ; load carry flag into ebx (zero extended)
> add edx, edx, ebx
> loop loopL
>
>
> Is there any instrtuction for XXX?


There's not a single instruction to do exactly what you want, but if
the destination is cleared first, an adc or rcl will do the trick, a
setc will set an entire byte (but not all of ebx), and then you can
lahf or pushf/pop and extract the bit manually.

0
Reply robertwessel2 5/24/2006 9:55:19 PM

robertwessel2@yahoo.com <spamtrap@crayne.org> wrote in part:
> Christian Christmann wrote:
>> does the x86 ISA pport an instruction to read the
>> carry flag and move it to a register?
>>
> There's not a single instruction to do exactly what you want,

What about  `sbb eax,eax` ?  This will set EAX=0 if CF=0,
and EAX=0FFFFFFFFh if CF=1.

-- Robert

0
Reply Robert 5/24/2006 10:56:52 PM

Robert Redelmeier wrote:
> robertwessel2@yahoo.com <spamtrap@crayne.org> wrote in part:
> > Christian Christmann wrote:
> >> does the x86 ISA pport an instruction to read the
> >> carry flag and move it to a register?
> >>
> > There's not a single instruction to do exactly what you want,
>
> What about  `sbb eax,eax` ?  This will set EAX=0 if CF=0,
> and EAX=0FFFFFFFFh if CF=1.


That's good, I hadn't thought of that, but the OP did specify zero
extension.

0
Reply robertwessel2 5/25/2006 1:00:05 AM

Robert Redelmeier wrote:
> robertwessel2@yahoo.com <spamtrap@crayne.org> wrote in part:
>> Christian Christmann wrote:
>>> does the x86 ISA pport an instruction to read the
>>> carry flag and move it to a register?
>>>
>> There's not a single instruction to do exactly what you want,
> 
> What about  `sbb eax,eax` ?  This will set EAX=0 if CF=0,
> and EAX=0FFFFFFFFh if CF=1.

Then he'll still have to and it with 1 to make it 1.


Bjarni
-- 

                        INFORMATION WANTS TO BE FREE

0
Reply Bjarni 5/25/2006 1:10:36 AM

6 Replies
480 Views

(page loaded in 0.076 seconds)

Similiar Articles:













7/24/2012 8:33:26 AM


Reply: