Skip to content

Instantly share code, notes, and snippets.

@slembcke
Created May 12, 2010 18:00
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 slembcke/398902 to your computer and use it in GitHub Desktop.
Save slembcke/398902 to your computer and use it in GitHub Desktop.
#include <stdio.h>
void func2(int a, int b, int c){
printf("%d %d %d\n", a, b, c);
}
void func1(int c){
func2(1,2,c);
}
int main(void){
func1(3);
return 0;
}
-----------
func1 replaced with the following assembly
_func1:
# use ecx as the base pointer
movl %esp, %ecx
# allocate more stack in 16 byte increments
subl $16, %esp
# copy the return address to top of the stack
movl (%ecx), %eax
movl %eax, (%esp)
# copy the old parameter
movl 4(%ecx), %eax
movl %eax, 12(%esp)
# add the two new ones
movl $2, 8(%esp)
movl $1, 4(%esp)
jmp _func2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment