|
-
Mar 18th, 2002, 05:32 PM
#1
Thread Starter
New Member
carry flag
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...
-
Mar 19th, 2002, 10:02 AM
#2
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.
-
Mar 21st, 2002, 09:49 AM
#3
Thread Starter
New Member
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....
-
Mar 21st, 2002, 01:12 PM
#4
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.
-
Mar 21st, 2002, 03:07 PM
#5
Thread Starter
New Member
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....
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|