Moving a label to a 64-bit register - inline assembly (GCC / CLANG)

) I am trying to move the address of a label to a 64 bit register and it won't let me.

I get:

fatal error: error in backend: 32-bit absolute addressing is not supported in 64-bit mode

      

Here's an example of what I'm trying to do:

asm ("mov $label, %rax"); // Tried movq, movl (No difference)
...
asm volatile("label:");
...

      

Why won't he let me in? does it only allow you to move a label to a 32 bit register? I have to insert this label address in 64 bit register, how do I achieve this?

thank

+3


source to share


1 answer


Try either of these two asm statements:

asm ("movabs $label, %rax");
asm ("lea label(%rip), %rax");

      



The first uses a 64-bit immediate operand (and therefore 64-bit absolute movement), and the second uses RIP relative addressing. The second option is probably the best as it is shorter, although it needs to label

be within 2 ^ 31 bytes.

However, as David Walferd pointed out, your code is unlikely to work.

+1


source







All Articles