1

I tried below code, but failed to read the correct value from r11 following below reference of http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0472f/Cihfhjhg.html

volatile int top_fp;
__asm
{
    mov top_fp, r11
}

r11's value is 0x20009DCC top_fp's value is 0x00000004

[update] Solution, we have to use embedded assembler:

__asm int getRegisterR11()
{
    mov r0,r11
    BX LR //return, must not omitted!!!
}
artless noise
  • 21,212
  • 6
  • 68
  • 105
bettermanlu
  • 627
  • 1
  • 9
  • 28

1 Answers1

1

The link you posted refers only to lr(R13), sp(R14), pc(R5) for legacy code support of code for old versions of ARM ADS and does not apply to general-purpose registers.

In ARM's compiler (also used in Keil's MDK-ARM):

The inline assembler provides no direct access to the physical registers of an ARM processor. If an ARM register name is used as an operand in an inline assembler instruction it becomes a reference to a variable of the same name, and not the physical ARM register.

(Ref: Inline assembler and register access)

Inline assembler in ARM's compiler is subject to optimisation like the C or C++ code it is in-lined within, as such the compiler may generate code that differs from that you have written in any case. If you want assembler code to be generated exactly as you have written you must use embedded assembler rather the inline assembler

Clifford
  • 88,407
  • 13
  • 85
  • 165
  • Thank you @Clifford for your comments. Could you help to transfer my code into embedded assembler? I am a really beginner of ARM assembler. Thanks a ton. I have read your embedded assembler reference, but have not found a solution yet. – bettermanlu Dec 07 '15 at 06:57
  • I'v figured it out. Thank you Clifford for your suggestion. – bettermanlu Dec 07 '15 at 08:20