如何访问的ARM Cortex M3的R11寄存器用C的内联汇编 [英] How to access r11 register of ARM Cortex M3 with inline assembler of C

查看:755
本文介绍了如何访问的ARM Cortex M3的R11寄存器用C的内联汇编的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试过低于code,但未能读取R11按照下面的http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0472f/Cihfhjhg.html

 挥发性INT top_fp;
__asm
{
    MOV top_fp,R11
}

R11的价值是0x20009DCC top_fp的值是0x00000004

[更新]解决方案,我们必须使用嵌入式汇编:

  __ ASM INT getRegisterR11()
{
    MOV R0,R11
    BX LR //返回,绝不能省略!
}


解决方案

您发布的链接仅指LR(R13),SP(R14),PC(R5)遗留code支持code的对于旧版本的ARM ADS和不适用于通用寄存器。

在ARM的编译器(在Keil的MDK-ARM也使用):


  

内联汇编器提供对物理寄存器的非直接访问
  的ARM处理器。如果ARM寄存器名称用作操作数
  内联汇编指令就变成一个变量的引用
  相同的名称,而不是物理ARM寄存器。


(参考:内联汇编和寄存器访问

在ARM的编译器内联汇编受到类似于C优化或C ++ code是内成荫,这样编译器可能会产生code,从你写在任何情况下是不同的。如果你想生成汇编code完全按照你写,你必须使用的 嵌入式汇编宁的内联汇编

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!!!
}

解决方案

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

这篇关于如何访问的ARM Cortex M3的R11寄存器用C的内联汇编的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆