I try to use lea rax, [rip]
in a c
program. My program is following:
...
asm volatile ("lea %%rax, %[rip]"
:);
...
However, the program does not compile, throwing an error: undefined name operand
. My platform is Ubuntu 1404 on a x86-64 architecture (as virtual machine).
In order to use lea rax, [rip]
in inline assembly with GCC you need to convert it to AT&T syntax and the quote it correctly so the % characters aren't interpreted as operand substitutions. So for example:
asm volatile ("lea (%%rip),%%rax"
::: "rax");
Note that since this doesn't actually do anything useful, you have no access to the value stored in RAX in your C code, you should specify an output operand:
long long ip;
asm ("lea (%%rip),%0"
: "=r" (ip));
This will let you access the value through the variable ip
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.