teddy
teddy

Reputation: 197

Inline asm in iOS error

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

Answers (3)

teddy
teddy

Reputation: 197

I have found my solution:

asm volatile("mov %0, sp \n\t":"=r"(x));

Upvotes: 3

Timothy Baldwin
Timothy Baldwin

Reputation: 3675

You are trying assemble x86 assembly for an ARM CPU.

Upvotes: 0

FrankH.
FrankH.

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

Related Questions