Click to See Complete Forum and Search --> : carry flag
saridemir
Mar 18th, 2002, 04:32 PM
hi,
I have a new question.....
I need to know how can I get carry flag data (I learned in assmbler I dont know there is same in C++) during the sum....
thanks alot...
yilmaz...
jim mcnamara
Mar 19th, 2002, 09:02 AM
If you know 386 assembler, use the __asm directive in C++.
Look it up in help - it lets you put assembly code inside (inline)
C code.
saridemir
Mar 21st, 2002, 08:49 AM
hi
you are right we can do it __asm but I dont want to use it is there any visual c++ functions that do this...
I wrote this code
unsigned int __fastcall Add(unsigned int x,unsigned int y,unsigned int * carry){
unsigned int cr=0;
__asm
{
mov eax, x ; Get first argument
add eax, y ; sum
jnc Myc ; Check carry flag branch
mov cr,1 ; carry 0
jmp Exit
Myc:
mov cr,0 ; carry 1
jmp Exit
Exit:
mov x, eax ; set x result
}
*carry=cr;// set cr to carry
return x;
}
but it may not be correct for all operation systems....
jim mcnamara
Mar 21st, 2002, 12:12 PM
The carry flag is at the machine level, not part of OS architecture.
NT & W2K will let you check the carry flag in an __asm call.
NT OS family intercepts bios interrupts. It doesn't intercept what you are doing. Your code is portable.
There is no function in C++ to deal with what you want to do with the carry flag. You could try to emulate addition of two integers using arrays, and trap overflow or carry but it's going to be painfully slow.
The array approach is used to manipulate REALLY huge numbers - the arrays are usually char using 1 & 0 -- for numbers that exceed any datatype.
saridemir
Mar 21st, 2002, 02:07 PM
I can do every thing in asm is it get much faster ... (but I dont do this becouse I dont have enough time ) if it gets huge diffrenece between two program I can do it....
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.