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.
You definitely should add r3 to the clobber list. Also, the
"m"
specifier is probably better. Ifcore_reg
is already inr0
, the compiler can use the offset ofr0
member and generate code such as,The compiler knows the relation between
core_reg
andcore_reg->r0
. At least"m"
works well with some versions ofarm-xxx-gcc
. Runobjdump --disassemble
on the code the compiler generates to verify it is doing what you want.Edit: 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.