EmbDev.net

Forum: ARM programming with GCC/GNU tools Geting PC register value


Author: sughibughi (Guest)
Posted on:

Rate this post
0 useful
not useful
Hello,

I use gcc to compile my code for STM32F407VGT6. I am trying to print the 
value of PC register and in order to do this I use this code:

unsigned int pc_value;

__asm__("mov %%R15,%0" : "=r" (pc_value));

My application crashes when it executes this line. If I replace R15 with 
another register (R1 for example) it does not crash anymore.
Is this because I am not allowed to read the value of PC ?

Thanks.

Author: A. K. (prx)
Posted on:

Rate this post
0 useful
not useful
You did load the PC with some unknown register contents.

While the GNU community often places the destination register last in 
the line, in old 68000 tradition, ARM prefers it as the left operand.

Author: sughibughi (Guest)
Posted on:

Rate this post
0 useful
not useful
pfff ... this explains it.
10x

Author: A. K. (prx)
Posted on:

Rate this post
0 useful
not useful
BTW: You'd better use "__asm__ volatile", or the optimizer might be 
tempted to move it around a little more than unavoidable.

Reply

Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]




Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.