Created
May 12, 2010 18:00
-
-
Save slembcke/398902 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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