Hi
I need to store the current program counter in a C variable.
Any code examples?
Thanks,
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.
Hi
I need to store the current program counter in a C variable.
Any code examples?
Thanks,
I don't think we have any codes that do this specifically, but you could trigger an incidental interrupt, then when in the ISR store the PC (the contents of which have been pushed on the stack) in a variable, then return. See figure 2-7 of the 1xx User's Guide
Yes this is what I would like to do.
I would like to be able to get the SP value into a C variable and then I would manage to recover the PC using pointers. I am just not familiar with assembly,
int StackPointerVar;
StackPointerVar = ???
Any suggestions?
Thanks,
Before serving an ISR, the PC + SR are automatically pushed on the stack. If you use a compiler like IAR, it also automatically pushes R4 to R11.
The way the PC is saved on the stack depends wether the MSP430 has 16 or 20 bits register:
unsigned short savedPC = (unsigned short *) (__get_SP_register() + 9); //Stack grows towards lower addresses...
unsigned long savedPC = (unsigned short *) (__get_SP_register() + 9) + ((((unsigned short *) (__get_SP_register() + 8)) & 0xF000) << 4);
This is not tested so there may be conceptual or code errors:)
Thanks Cyberstorm,
That exactly what I was looking for. ;)
I dont really get the + 9 and + 8 though.
Since just got into interrupt I expect the
(SP) to be pointing to Previous SR
(SP + 2) to be pointing to the previous PC
Am I missing something?
Hi Al,
I added the +8 because the compiler also stores 8 registers(R4 to R11) on the stack, but you may check if this applies also for your compiler.
Program Counter in case of MSP430X is splitted on two registers, hence the +8 and +9.
OK,
I got it working with the following code in CCE with f5438 with +24 and +26 offsets.
Thanks again
**Attention** This is a public forum