I am trying to write a small part of my code in extended asm (x86-64 target) in the GCC style, and I am having problems coding for structural offsets.
I have struct s with an element size_t a[] , a pointer to such a structure and an index, both of which are generated inside the asm block.
Now I need to access this element in asm
asm ( "mov %[displ](%[s], %[index], 8), %%rbx" : [s] "+r" (s) , [index] "+r" (i) : "memory", "cc", "rax", "rbx" );
How can I encode displ into asm block? Passing offsetof(struct s, a) as an immediate prefix using $ and generates an invalid assembly.
asm ( "mov %[displ](%[s], %[index], 8), %%rbx" : [s] "+r" (s) , [index] "+r" (i) : [displ] "i" (offsetof(struct s, a)) : "memory", "cc", "rax", "rbx" );
source share