问题描述
我们可以使用运营商的地址&放大器;内嵌GCC ARM汇编?如果是的话,我有一个结构core_regx,我需要传递strucutre成员R0到下面提及code的地址:
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)));
请检查该code是正确与否。
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 给撞名单。此外,M
说明可能是更好的。如果 core_reg
已经在 R0
,编译器可以使用 R0 $的偏移C $ C>成员,并产生code,例如,
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-&GT之间的关系; R0
。至少M
与的某些版本的胳膊-XXX-GCC
效果很好。运行 objdump的--disassemble
在code编译器生成,验证它是做你想要什么。
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手册中有很多信息,如的中的和。有在互联网上很多教程,如 ARM汇编食谱A> ,这是最好的一个。
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.
这篇关于我们可以使用运营商QUOT地址;&安培;"内嵌GCC ARM汇编?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!