汇编技术内幕(1)
为简化问题,来分析一下最简的c代码生成的
汇编代码:
main:
pushl
%ebp;ebp寄存器内容压栈,即保存main函数的上级调用函数的栈基地址
main+1:
movl
%esp,%ebp
; esp值赋给ebp,设置main函数的栈基址main+3:
subl
$8,%esp
main+6:
andl
$0xf0,%esp
main+1:
main+6:
main+9:
movl
$0,%eax
main+0xe:
subl
%eax,%esp
main+0x10:
movl
$0,%eax
; 设置函数返回值0
main+0x15:leave; 将ebp值赋给esp,pop先前栈内的上级函数栈的基地址给ebp,恢复原栈基址
main+0xe:
main+0x10:
main+0x15:
main+0x16:
ret
; main函数返回,回到上级调用
注:这里得到的汇编语言语法格式与Intel的手册有很大不同,Unix/Linux采用AT&T汇编格式作为汇编语言的语法格式