我们可以使用运算符“&"的地址吗?内联 GCC ARM 程序集? [英] Can we use Address of operator "&" inline GCC ARM assembly?
问题描述
我们可以使用运算符&"的地址吗内联 GCC ARM 程序集?如果是,那么我有一个结构 core_regx,我需要将该结构的成员 r0 的地址传递到下面提到的代码中:
Can we use Address of operator "&" inline GCC ARM assembly? If yes then I have a structure core_regx and I need to pass the address of a member r0 of that strucutre into the below mentioned code:
asm volatile("ldr r3, [%0,#0]":: "r" (&(core_reg->r0)));
请检查此代码是否正确.
Please check if this code is correct or not.
推荐答案
是的,您当然可以使用 &.但是,我建议您的汇编程序说明符可能存在一些问题和更好的选择.
Yes, you certainly can use &. However, I would suggest that your assembler specifiers may have some issues and better options.
asm volatile("ldr r3, %0":: "m" (core_reg->r0) : "r3");
您绝对应该将 r3 添加到 clobber 列表中.此外, "m"
说明符可能更好.如果 core_reg
已经在 r0
中,编译器可以使用 r0
成员的偏移量并生成代码如,
You definitely should add r3 to the clobber list. Also, the "m"
specifier is probably better. If core_reg
is already in r0
, the compiler can use the offset of r0
member and generate code such as,
add r0, r0, #12 ; assuming r0 is core_reg.
ldr r3, [r0]
编译器知道core_reg
和core_reg->r0
之间的关系.至少 "m"
可以很好地与 arm-xxx-gcc
的某些版本配合使用.对编译器生成的代码运行 objdump --disassemble
以验证它正在执行您想要的操作.
The compiler knows the relation between core_reg
and core_reg->r0
. At least "m"
works well with some versions of arm-xxx-gcc
. Run objdump --disassemble
on the code the compiler generates to verify it is doing what you want.
GCC 手册有很多信息,例如 Gcc 汇编器约束,机器特定 和 一般信息.网上有很多教程,比如ARM assembler cookbook,这是最好的之一.
The GCC manual has lots of information, such as Gcc assembler contraints, Machine specific and General Info. There are many tutorials on the Internet such as the ARM assembler cookbook, which is one of the best.
这篇关于我们可以使用运算符“&"的地址吗?内联 GCC ARM 程序集?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!