Skip to content

Instantly share code, notes, and snippets.

@gnuvince
Created August 15, 2018 17:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gnuvince/212fc4f54e61fe7a5e813c7e2bf5eeeb to your computer and use it in GitHub Desktop.
Save gnuvince/212fc4f54e61fe7a5e813c7e2bf5eeeb to your computer and use it in GitHub Desktop.
/* C code */
int add(int x, int y) {
return x+y;
}
void caller() {
int a = add(3, 4);
}
/* x86 assembly */
caller:
# Prelude
pushl %ebp
movl %esp, %ebp
subl $16, %esp
# Push arguments onto the stack
pushl $4
pushl $3
# Call `add`
call add
# Pop the two arguments
addl $8, %esp
...
/* amd64 assembly */
caller:
# Prelude
pushq %rbp
movq %rsp, %rbp
subq $16, %rsp
# Put arguments in registers
movl $4, %esi
movl $3, %edi
# Invoke `add`
call add
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment