- 論壇徽章:
- 0
|
C程序如下
- #include <stdio.h>
- void func(long long a) { }
- int main()
- {
- func(0x400000002);
- return 0;
- }
復(fù)制代碼 編譯成匯編語言后如下
- .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
復(fù)制代碼 我用的是GCC 4.7.0。麻煩各位看下func函數(shù)中有注釋的那四句匯編代碼,它居然把參數(shù)a復(fù)制到自己的堆
棧中了,我發(fā)現(xiàn)如果func的參數(shù)是int型的話則不會(huì)出現(xiàn)這種現(xiàn)象,請(qǐng)問各位這種設(shè)定是為
什么。。 |
|