Skip to content

Instantly share code, notes, and snippets.

@jakedouglas
Created November 26, 2009 20:04
Show Gist options
  • Save jakedouglas/243634 to your computer and use it in GitHub Desktop.
Save jakedouglas/243634 to your computer and use it in GitHub Desktop.
// This code should align the stack to a 16 byte boundary for OSX function calls
push rbx // save rbx. joe says rbx is caller saved, but other things say its callee-saved?
mov rdx, 0 // move 0 into the first division register
mov rax, rsp // move rsp's address into the second division register
mov rbx, 16 // move the divisor, 16, into rbx
div rbx // perform the division using the value we just put into rbx
mov rbx, rdx // store the remainder into rbx so we have it when we return
subq rsp, rbx // grow the stack pointer by our offset
callq 0xdeadbeef // call out to the function
addq rsp, rbx // put the stack pointer back where it was
pop rbx // restore rbx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment