- 一、实验过程
- 二、实验分析
本次实验反汇编的C语言程序为:
使用gcc –S –o main.s main.c -m32命令将main.c中的程序编译成汇编代码,并生成main.s文件,使用cat main.s查看编译结果如下图所示:
删除多余的代码段后得到的汇编代码如下:
g: pushl %ebp movl %esp, %ebp movl 8(%ebp), %eax addl $2813, %eax popl %ebp ret f: pushl %ebp movl %esp, %ebp subl $4, %esp movl 8(%ebp), %eax movl %eax, (%esp) call g leave ret main: pushl %ebp movl %esp, %ebp subl $4, %esp movl $2813, (%esp) call f addl $1, %eax leave ret
对该段汇编代码的分析如下:
其中需要注意的几点:
- 调用函数的现场保护
体现出的保护代码如下,主要起到对当前堆栈栈顶的保护
pushl %ebp movl %esp, %ebp
- 参数的传递与获取
调用函数时要传递的参数通过压栈的方式传递给被调用函数:
subl $4, %esp movl $2813, (%esp)
参数获取时需要从堆栈中获取:
movl 8(%ebp), %eax
工作过程中堆栈的变化过程如图所示:



