This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Compiler/TM4C1290NCPDT: Access to Carry Bit

Part Number: TM4C1290NCPDT

Tool/software: TI C/C++ Compiler

Hi,

I'm adding to 32-Bit values (c-code) and want to evaluate the carry bit (TM4C129, launchpad). I think this bit is in Register APSR, but I have no idea howto access to the core registers in c. Is there any simple way?


Thanks for any help

Regards

Micky

  • As you are employing "C" - is not that level of detail, "managed for you?"
    Joseph Yiu's book, "The definitive guide to the ARM Cortex-M3/M4" provides the detail you seek. (should you really want to "raise the hood.")
  • Michael Schuster said:
    I'm adding to 32-Bit values (c-code) and want to evaluate the carry bit

    Why? I'm trying to think of cases where it would be a) useful and b) well defined. I can't come up with any (especially b).

    Robert

  • Hi was thinking of
    bisqwit.iki.fi/.../

    I could manage to read the register with:

    uint32_t ufnXPSR(void)
    {
    __asm(" mrs r0, xpsr\n"
    " bx lr\n");
    // satisfy Compiler
    return(0);
    }

    Anyway, the carry bit was not set after an overrun.
  • Well, that's assembler, not C but you still haven't indicated why you would want to do that.

    Robert
  • Hello Michael,

    I think we all are still a bit perplexed about why when using C code you would need to do assembly level addition... C functions will handle this automatically for you? Is there a purpose beyond just experimentation?
  • As so often noted - posters NEVER/EVER justify their (bit strange) requests...
    As the initial answering post stated - poster (claimed) to be using "C" (negating such a need) - this (use of C) may prove NOT the (real) case!

  • Hi Robert,

    did you see the link above (bisqwit.iki.fi/.../ and "Addition of larger integers than native register size").


    I want to add large ints and thought it might be easier to get the carry directly than with a comparison as with the pseudo code :
    uint_type a = original_1;
    uint_type b = original_2;
    uint_type result = a + b;
    bool carry = result < a;

  • @cb1_mobile: I didnot want to be impolite and asked in a normal manner, I hope. Additionally I did give the link with the large number addition.
  • Indeed - there was NO claim of (any) impoliteness - there was little (i.e. no) justification for "use of the carry bit" when C code (as you stated) was "in play!"
  • Michael Schuster said:
    did you see the link above (bisqwit.iki.fi/.../ and "Addition of larger integers than native register size").

    I don't follow links w/o at least some explanation of what hey are and I'm cautious even then.

    Michael Schuster said:
    I want to add large ints and thought it might be easier to get the carry directly than with a comparison as with the pseudo code :

    You do realize that there is native support for this, far more efficient than anything you could write. At least up to 64bits. Beyond that there are available libraries.

    Robert

  • I need 256 Bit. Well I can use the pseudo code, but I just was wondering howto have access to the carry bit.
  • Michael Schuster said:
    I need 256 Bit. Well I can use the pseudo code, but I just was wondering howto have access to the carry bit.

    There are readily available libraries that will do that for you .

    I don't think there is, on any processor, a sure way of accessing the carry bit  after an addition. At the very least you'd need to play games with volatile. By the time you were done you'd likely be as far or further ahead to use assembly.

    Robert

  • Hello Michael,

    As Robert suggested, you should seek out an already made library to handle that requirement rather than try to very painfully re-invent the wheel. Given the existence of such libraries and that I have no better idea on how to accomplish what you seek than you do, I can't offer any help/support for your endeavor as it stands now.