Reputation: 197
int x;
__asm __volatile("movl %0, %%sp":"=r"(x)::"%sp");
I want to store sp to x.
The error:
error: unexpected token in operand
__asm __volatile("movl %0, %%sp":"=r"(x)::"%sp");
^
:1:13: note: instantiated into assembly here
movl r0, %sp
^
1 warning and 1 error generated.
Upvotes: 3
Views: 2743
Reputation: 18217
What works for this specific case is:
register void* sp __asm__("sp");
__asm__("" : "+r"(sp) :: "memory");
It's even portable between ARM and x86 ...
Upvotes: 2