简体   繁体   English

如何使用C的内联汇编器访问ARM Cortex M3的r11寄存器

[英]How to access r11 register of ARM Cortex M3 with inline assembler of C

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 我尝试了下面的代码,但未能在http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0472f/Cihfhjhg.html的以下引用下从r11读取正确的值

volatile int top_fp;
__asm
{
    mov top_fp, r11
}

r11's value is 0x20009DCC top_fp's value is 0x00000004 r11的值为0x20009DCC top_fp的值为0x00000004

[update] Solution, we have to use embedded assembler: [更新]解决方案,我们必须使用嵌入式汇编程序:

__asm int getRegisterR11()
{
    mov r0,r11
    BX LR //return, must not omitted!!!
}

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. 您发布的链接仅引用lr(R13),sp(R14),pc(R5),以获得旧版本代码对ARM ADS的旧版本的代码支持,不适用于通用寄存器。

In ARM's compiler (also used in Keil's MDK-ARM): 在ARM的编译器(也用于Keil的MDK-ARM)中:

The inline assembler provides no direct access to the physical registers of an ARM processor. 内联汇编器不提供对ARM处理器的物理寄存器的直接访问。 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. 如果将ARM寄存器名称用作嵌入式汇编程序指令中的操作数,则它将成为对同名变量的引用,而不是对物理ARM寄存器的引用。

(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. ARM编译器中的内联汇编程序会像其内联的C或C ++代码一样受到优化,因为这种编译器在任何情况下都可能生成与您编写的代码不同的代码。 If you want assembler code to be generated exactly as you have written you must use embedded assembler rather the inline assembler 如果要完全按照编写的方式生成汇编代码,则必须使用嵌入式汇编程序而不是内联汇编程序

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM