【发布时间】:2010-01-15 11:31:20
【问题描述】:
我只是好奇下面的例子
#include<stdio.h>
int test();
int test(){
// int a = 5;
// int b = a+1;
return ;
}
int main(){
printf("%u\n",test());
return 0;
}
我用 'gcc -Wall -o semicolon semicolon.c' 编译它以创建一个可执行文件 和 'gcc -Wall -S semicolon.c' 得到汇编代码:
.file "semicolon.c"
.text
.globl test
.type test, @function
test:
pushl %ebp
movl %esp, %ebp
subl $4, %esp
leave
ret
.size test, .-test
.section .rodata
.LC0:
.string "%u\n"
.text
.globl main
.type main, @function
main:
leal 4(%esp), %ecx
andl $-16, %esp
pushl -4(%ecx)
pushl %ebp
movl %esp, %ebp
pushl %ecx
subl $20, %esp
call test
movl %eax, 4(%esp)
movl $.LC0, (%esp)
call printf
movl $0, %eax
addl $20, %esp
popl %ecx
popl %ebp
leal -4(%ecx), %esp
ret
.size main, .-main
.ident "GCC: (Ubuntu 4.3.3-5ubuntu4) 4.3.3"
.section .note.GNU-stack,"",@progbits
因为我不是这样的汇编专家,我只知道 printf 打印 eax 中的内容 但我不完全理解 'movl %eax, 4(%esp)' 是什么意思,我假设在调用测试之前填充 eax 但那有什么价值呢? 4(%esp)是什么意思,esp的值是什么意思?
如果我取消注释 test() printf 中的行打印 6 - 这是用 eax 写的 ^^
【问题讨论】:
标签: c