32-Bits' Carry Flag Is Not Available in C/C++?
From: Bryan Parkoff (bryan.nospam.parkoff_at_nospam.com)
Date: 01/12/04
- Previous message: Nat Brown: "help optimizing an expensive loop?"
- Next in thread: Daniel Pfeffer: "Re: 32-Bits' Carry Flag Is Not Available in C/C++?"
- Reply: Daniel Pfeffer: "Re: 32-Bits' Carry Flag Is Not Available in C/C++?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 12 Jan 2004 07:21:42 +0000 (UTC)
Carry Flag is always available in x86 assembler because it can deal with
ADD and ADC instructions however C/C++ does not have the feature.
For Example,
unsigned int Low_DWord = 0xFFFFFFFF;
unsigned int High_DWord = 0x00000000;
unsigned char Carry = 0;
__asm
{
mov eax, dword ptr [Low_DWord]
mov ecx, dword ptr [High_DWord]
add eax, 1
adc ecx, 0
mov dword ptr [Low_DWord], eax
mov dword ptr [High_DWord], ecx
}
Low_DWord adds 1 that it equals to 0x00000000. Carry Flag is turned on
after ADD instruction is executed. High_DWord adds Carry that it equals to
0x00000001. Carry Flag is turned off after ADC instruction is executed.
I don't want to use inline __asm anymore. How can I overcome C/C++'s
limitation to use Carry Flag feature? IF Else statement is not the option
to update the Carry Flag. Without Carry Flag, High_DWord will never be
updated.
It would be useful for me to deal with 128 Bits integer that C/C++ does
not support 128 Bits integer. There must be another way. For example, one
ADD instruction for first 32 Bits, second ADC instruction for second 32
Bits, third ADC instruction for third 32 Bits, and fourth ADC instruction
for fourth 32 Bits. Carry Flag is useful to update between two 32 Bits so
128 Bits integer will always be correct.
I do not intend to use float nor double keyword, but I can create four
32 Bits variables before four 32 Bits variables can be updated together to
form 128 Bits.
Does it make sense? Any ideas are welcome. I appreciate your help.
-- Bryan Parkoff
- Previous message: Nat Brown: "help optimizing an expensive loop?"
- Next in thread: Daniel Pfeffer: "Re: 32-Bits' Carry Flag Is Not Available in C/C++?"
- Reply: Daniel Pfeffer: "Re: 32-Bits' Carry Flag Is Not Available in C/C++?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]