Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 342797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T10:50:17+00:00 2026-05-12T10:50:17+00:00

The following GCC inline asm is taken from LuaJit’s coco library. Can someone provide

  • 0

The following GCC inline asm is taken from LuaJit’s coco library. Can someone provide a line by line explanation of what it does?

static inline void coco_switch(coco_ctx from, coco_ctx to)
{
  __asm__ __volatile__ (
    "movl $1f, (%0)\n\t" 
    "movl %%esp, 4(%0)\n\t" 
    "movl %%ebp, 8(%0)\n\t"
    "movl 8(%1), %%ebp\n\t" 
    "movl 4(%1), %%esp\n\t" 
    "jmp *(%1)\n" "1:\n"
    : "+S" (from), "+D" (to) : : "eax", "ebx", "ecx", "edx", "memory", "cc");
}

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T10:50:17+00:00Added an answer on May 12, 2026 at 10:50 am

    My ASM is a bit fuzzy about the details, but I think I can give you a general idea.

    ESP: Stack pointer, EBP: Base pointer.

    movl $1f, (%0)
    

    Move address of label 1 (defined on last line) into parameter 0 (from).

    movl %%esp, 4(%0)
    

    Move the content of register ESP into (from + 4).

    movl %%ebp, 8(%0)
    

    Move the content of register EBP into (from + 8).

    movl 8(%1), %%ebp
    

    Move the content of (to + 8) into register EBP.

    movl 4(%1), %%esp
    

    Move the content of (to + 4) into register ESP.

    jmp *(%1)
    

    Jump to address contained in (to).

    The “1:” is a jump label.

    “+S” declares a “source” (read) parameter, “+D” a destination (write) parameter. The list of registers at the end of the statement is the “clobber” list, a list of registers possibly modified by the ASM code, so the compiler can take steps to maintain consistency (i.e., not relying on e.g. ECX still containing the same value as before).

    I guess that coco_ctx means “coco context”. So: The function saves the current stack frame in the “from” structure, and sets the stack frame to what’s saved in the “to” structure. Basically, it jumps from the current function into another function.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can someone elaborate on the following gcc error? $ gcc -o Ctutorial/temptable.out temptable.c temptable.c:
I'm still fighting with GCC - compiling the following inline assembly code (with -fasm-blocks
I want to compile the following line of code from http://code.google.com/p/enhsim : enh::eout <<
gcc does not like the following code: inline const plus(unsigned x,unsigned y) __attribute__((pure)); inline
If you want to call a C/C++ function from inline assembly, you can do
gcc 4.5.1 c89 I am using the following code to read in a line
I want to test inline asm capabilty on gcc. So, I type and compile
Running the following program on gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3 and Intel(R) Core(TM)2 Duo CPU,
I compiled the following program with gcc -fprofile-arcs -ftest-coverage test.c: int main() { int
I've recently found myself using the following macro with gcc 4.5 in C++11 mode:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.