Results 1 to 5 of 5

Thread: carry flag

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2002
    Posts
    13

    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...

  2. #2
    jim mcnamara
    Guest
    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.

  3. #3

    Thread Starter
    New Member
    Join Date
    Jan 2002
    Posts
    13
    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....

  4. #4
    jim mcnamara
    Guest
    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.

  5. #5

    Thread Starter
    New Member
    Join Date
    Jan 2002
    Posts
    13
    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
  •  



Click Here to Expand Forum to Full Width