I'm trying to put the value of %rbp
into the %rax
register using __asm__
so that I can get a reference to the stack frame that won't be changed when I create an external variable.
I'm using the following code to do this:
int some_variadic_function(int n, ...)
{
__asm__("movl %rax, %rbp");
return 0;
}
int main() {
some_variadic_function(3, 1, 2, 3);
return 0;
}
However, when I try and compile this with clang I get the following error:
using_rbp.c:4:13: error: invalid operand for instruction
__asm__("movl %rax, %rbp");
^
<inline asm>:1:7: note: instantiated into assembly here
movl %rax, %rbp
^~~~~
1 error generated.
This seems to be implying that I can't put %rbp
directly into %rax
. Is that's what happening, or is there another issue with this code?
For reference, I'm on Mac with x86-64
hardware.