- 论坛徽章:
- 0
|
可能是和操作系统有关
下面的程序
int main() {
return 0;
}
int f() {
int i=0;
i++;
return 0;
} |
在WinXP下编译(GCC 3.4.2)的结果是
.file "a.c"
.def ___main; .scl 2; .type 32; .endef
.text
.globl _main
.def _main; .scl 2; .type 32; .endef
_main:
pushl %ebp
movl %esp, %ebp
subl $8, %esp
andl $-16, %esp
movl $0, %eax
addl $15, %eax
addl $15, %eax
shrl $4, %eax
sall $4, %eax
movl %eax, -4(%ebp)
movl -4(%ebp), %eax
call __alloca
call ___main
movl $0, %eax
leave
ret
.globl _f
.def _f; .scl 2; .type 32; .endef
_f:
pushl %ebp
movl %esp, %ebp
subl $4, %esp
movl $0, -4(%ebp)
leal -4(%ebp), %eax
incl (%eax)
movl $0, %eax
leave
ret
|
同样的程序在Debian下编译(GCC 4.2.2)的结果是
.file "a.c"
.text
.globl main
.type main, @function
main:
leal 4(%esp), %ecx
andl $-16, %esp
pushl -4(%ecx)
pushl %ebp
movl %esp, %ebp
pushl %ecx
movl $0, %eax
popl %ecx
popl %ebp
leal -4(%ecx), %esp
ret
.size main, .-main
.globl f
.type f, @function
f:
pushl %ebp
movl %esp, %ebp
subl $16, %esp
movl $0, -4(%ebp)
addl $1, -4(%ebp)
movl $0, %eax
leave
ret
.size f, .-f
.ident "GCC: (GNU) 4.2.1 (Debian 4.2.1-5)"
.section .note.GNU-stack,"",@progbits
|
至于它们之间的区别,可能和运行库的实现有关,正在研究中 |
|