- 论坛徽章:
- 0
|
C程序如下
- #include <stdio.h>
- void func(long long a) { }
- int main()
- {
- func(0x400000002);
- return 0;
- }
复制代码 编译成汇编语言后如下
- .file "test.c"
- .text
- .globl func
- .type func, @function
- func:
- .LFB0:
- .cfi_startproc
- pushl %ebp
- .cfi_def_cfa_offset 8
- .cfi_offset 5, -8
- movl %esp, %ebp
- .cfi_def_cfa_register 5
- subl $8, %esp
- movl 8(%ebp), %eax ;; 这句
- movl %eax, -8(%ebp) ;; 这句
- movl 12(%ebp), %eax ;; 这句
- movl %eax, -4(%ebp) ;; 这句
- leave
- .cfi_restore 5
- .cfi_def_cfa 4, 4
- ret
- .cfi_endproc
- .LFE0:
- .size func, .-func
- .globl main
- .type main, @function
- main:
- .LFB1:
- .cfi_startproc
- pushl %ebp
- .cfi_def_cfa_offset 8
- .cfi_offset 5, -8
- movl %esp, %ebp
- .cfi_def_cfa_register 5
- andl $-8, %esp
- subl $8, %esp
- movl $2, (%esp)
- movl $4, 4(%esp)
- call func
- movl $0, %eax
- leave
- .cfi_restore 5
- .cfi_def_cfa 4, 4
- ret
- .cfi_endproc
- .LFE1:
- .size main, .-main
- .ident "GCC: (GNU) 4.7.0 20120507 (Red Hat 4.7.0-5)"
- .section .note.GNU-stack,"",@progbits
复制代码 我用的是GCC 4.7.0。麻烦各位看下func函数中有注释的那四句汇编代码,它居然把参数a复制到自己的堆
栈中了,我发现如果func的参数是int型的话则不会出现这种现象,请问各位这种设定是为
什么。。 |
|