There are two problems. First - you need a comma between registers in mov command:
"movq %%rbp, %0;\n"
Second, you need 64-bit variable to hold value of %rbp
. int
is 32-bit on x86_64 linux. You can use long
or preferably uint64_t
.
Вопрос
I am trying to read a value from the stack using the gcc inline assembly with the default at&t syntax. My code is
unsigned int ret_val;
__asm volatile(
"movq %%rbp %0;\n"
:"=r"(ret_val)
);
I am getting an error:
Assembler messages:
Error: junk `%eax' after register
What is the meaning of this error and how do I get rid of this. I already read through some similar questions on SO question but no help from them. I am more interested in knowing the cause behind the error and the correct way to do it.
The code is written for x86_64 ubuntu machine.
Thanks
Решение
There are two problems. First - you need a comma between registers in mov command:
"movq %%rbp, %0;\n"
Second, you need 64-bit variable to hold value of %rbp
. int
is 32-bit on x86_64 linux. You can use long
or preferably uint64_t
.