Hi smart guys out there,
I am using µVision with TIs eval-kit LM3S9B92. I use µVisions C-Compiler.
I learned that it is not possible to read the CPU-Registers with C and I have to use asembler for that.
I have no idea of asembler and actually I don't work with it in future and I hope I never have to again :-) ...but right now I need to know the status of the carrybit.
So all I am asking is for a piece of code that gets me the status of bit 29 in the register 17 :) and how to implement that in my project.
I hope this doesn't sound sassy ;-) - at least it isn't meant that way.
Thank you so much.
Hi Susan
Couple of options:
Use this standardized CMSIS function portable between popular toolchains
__get_APSR(void)
Or use MDK/RVCT specific named register variables
uint32_t apsr __asm("APSR"); if (apsr & APSR_C) // do this else // do that
Hope this helps Marcus
Note that you can manage quite well without ever knowing the content of the carry bit.
if (b >= a) { b -= a; // no borrow } else { b -= a; // handle borrow }
unsigned a,b,c; c = a+b; if (c < a || c < b) { // addition overflow }
Marcus, I tried yours, too.
Do I need a special header or include file for this? Cause µVision tells me:
undefined symbol __get_APSR();
identifier "APSR_C" is undefined, respectively (when trying the other one)
__get_APSR() is defined in CMSIS, so yes, you do need to include a header file, namely core_cmFunc.h.
The identifier APSR_C was just a made up example, perhaps defined as macro, to demonstrate that you need to compare with a numeric value. BTW, CMSIS also defines a structure APSR_Type so that you could perhaps write something like:
if ((APSR_Type)apsr.b.C) // do this else // do that
But as others have said already: For your purposes, this is completely unnecessary.
Best regards Marcus