Skip to content

Instantly share code, notes, and snippets.

@Themaister
Created June 17, 2011 00:29
Show Gist options
  • Select an option

  • Save Themaister/1030643 to your computer and use it in GitHub Desktop.

Select an option

Save Themaister/1030643 to your computer and use it in GitHub Desktop.
// ABI: fastcall
asm (
".text\n"
ASM_CO_SWAP_DEF
"movl %esp, (%edx) # Save stack pointer, and restore it again.\n"
"movl (%ecx), %esp\n"
"popl %eax\n"
"movl %ebp, 0x4(%edx) # Save non-volatile registers to buffer.\n"
"movl %esi, 0x8(%edx)\n"
"movl %edi, 0xc(%edx)\n"
"movl %ebx, 0x10(%edx)\n"
"movl 0x4(%ecx), %ebp # Restore non-volatile registers from buffer.\n"
"movl 0x8(%ecx), %esi\n"
"movl 0xc(%ecx), %edi\n"
"movl 0x10(%ecx), %ebx\n"
"jmp *%eax # Jump back to saved PC.\n"
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment