3

I want to assign an array using inline assembly using the AT&T syntax. I want to achieve something like the following. Note that rsp here is the %rsp register.

long saved_sp[N];
long new_sp[N];

void some_function( unsigned int tid, ... )
{
 // These two lines should be in assembly
 saved_sp[tid] = rsp; 
 rsp = new_sp[tid];   
 ......
}

1 Answer 1

3

I'm sure I don't need to warn you...

__asm__ __volatile__ (

    "movq %%rsp, (%0, %2, 8)\n\t"
    "movq (%1, %2, 8), %%rsp\n\t"

    : : "r" (saved_sp), "r" (new_sp), "r" ((long) tid));

Perhaps "memory" should be added as a clobber, but it seems kind of redundant. Wherever you go after this, remember that the frame pointer "%rbp" will be invalidated.

Sign up to request clarification or add additional context in comments.

1 Comment

Oh Ok, I got what your are trying to do :)!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.