Skip to content

Instantly share code, notes, and snippets.

@DmitrySoshnikov
Last active May 23, 2017 18:22
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 DmitrySoshnikov/8eb0cc0b4ec116c906307302aebc493d to your computer and use it in GitHub Desktop.
Save DmitrySoshnikov/8eb0cc0b4ec116c906307302aebc493d to your computer and use it in GitHub Desktop.
stack-params.c
// https://godbolt.org/g/2xOK3B
int foo(int x) {
int y = 20;
return x + y;
}
int main() {
foo(10);
return 0;
}
/* asm
foo(int): # @foo(int)
pushq %rbp
movq %rsp, %rbp
movl %edi, -4(%rbp)
movl $20, -8(%rbp)
movl -4(%rbp), %edi
addl -8(%rbp), %edi
movl %edi, %eax
popq %rbp
retq
main: # @main
pushq %rbp
movq %rsp, %rbp
subq $16, %rsp
movl $10, %edi
movl $0, -4(%rbp)
callq foo(int)
xorl %edi, %edi
movl %eax, -8(%rbp) # 4-byte Spill
movl %edi, %eax
addq $16, %rsp
popq %rbp
retq
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment