It is possible to access Sp, Lr, and Pc and store them in normal C variable?... if yes then how to do it.? please explain it with c code..
I'm using arm gcc compiler
It is possible to access Sp, Lr, and Pc and store them in normal C variable?... if yes then how to do it.? please explain it with c code..
I'm using arm gcc compiler
In GCC:
uint32_t some_variable;
__asm__ __volatile__ ("mov %0, lr" : "=r" (some_variable));
This tells the compiler to allocate a register for some_variable (which is represented by the placeholder %0), and then emit the instruction mov %0, lr. The effect is to store the value of lr into some_variable.
__volatile__ tells the compiler not to reorder this instruction, which I assume you want.
This should also work with pc or sp. (Or any other register, but doing it with "normal" registers won't be very useful - among other things, the compiler might choose to allocate some_variable to the register you're trying to look at)