Skip to content

Instantly share code, notes, and snippets.

@shpark
Created January 19, 2021 07:43
Show Gist options
  • Save shpark/2375b067293493fb70d7db5fa42bc93a to your computer and use it in GitHub Desktop.
Save shpark/2375b067293493fb70d7db5fa42bc93a to your computer and use it in GitHub Desktop.
til

Look at the following x86 assembly code (from lua repository).

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

What does 1f, 1b, or 2f mean? In general, they are indicators to local labels (see 1: and 2:). In particular, xf will look for the local label x after current location, while xb will look for the local label x before current position. Find further information from this documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment