2023-03-17 09:45 PM
Solved! Go to Solution.
2023-03-18 06:56 AM
R14 == LR
R15 == PC
calledfromwhere ; subroutine returns address from whence it came
movs r0, lr
bx lr
Usage
bl calledfromwhere ; assembler
printf("%p\n", calledfromwhere() ); // C
2023-03-17 10:49 PM
In debug mode, place a breakpoint or stop the code, and view the disassembly window which will show you which address the PC value is. Or view the SFR core registers.... why do you need this?
2023-03-17 11:14 PM
I want to read PC value to use it for program and not for observation purpose. Is there any way sir?
2023-03-17 11:39 PM
Explain better what it is you're attempting to do.
In assembler you can move the value to other registers or do math directly with the PC. You could perhaps create a subroutine which moves LR to R0 and see where it was called from.
Perhaps learn MCU registers, instructions and assembler?
2023-03-17 11:43 PM
Yes, I have some programs running on flash, I want to save some values from register r0 to r15 and the value of register pc, so that I can go back and continue doing my old work.
2023-03-18 06:56 AM
R14 == LR
R15 == PC
calledfromwhere ; subroutine returns address from whence it came
movs r0, lr
bx lr
Usage
bl calledfromwhere ; assembler
printf("%p\n", calledfromwhere() ); // C
2023-03-18 07:00 AM
I will try it, thank you very much.
2023-03-18 01:46 PM
GCC has intrinsic function __builtin_return_address() exactly for this