- 论坛徽章:
- 0
|
回复 #17 thinshootout 的帖子
熊猫大哥不放看看这个:
- int a()
- {
- int a[ 3 ] = { 10, 20, 30 };
- int sum = a [ 0 ] + a[ 1 ];
- return sum;
- }
- int c = 10;
- int main()
- {
- a();
- }
复制代码
编译 gcc filename.c -S
- .file "a.c"
- .text
- .globl a
- .type a, @function
- a:
- pushl %ebp
- movl %esp, %ebp
- subl $16, %esp
- movl $10, -16(%ebp)
- movl $20, -12(%ebp)
- movl $30, -8(%ebp)
- movl -16(%ebp), %edx
- movl -12(%ebp), %eax
- leal (%edx,%eax), %eax
- movl %eax, -4(%ebp)
- movl -4(%ebp), %eax
- leave
- ret
- .size a, .-a
- .globl c
- .data
- .align 4
- .type c, @object
- .size c, 4
- c:
- .long 10
- .text
- .globl main
- .type main, @function
- main:
- leal 4(%esp), %ecx
- andl $-16, %esp
- pushl -4(%ecx)
- pushl %ebp
- movl %esp, %ebp
- pushl %ecx
- call a
- popl %ecx
- popl %ebp
- leal -4(%ecx), %esp
- ret
- .size main, .-main
- .ident "GCC: (GNU) 4.2.4 (Ubuntu 4.2.4-1ubuntu4)"
- .section .note.GNU-stack,"",@progbits
复制代码
中间把10, 20, 30放到哪里了?栈空间里面函数a的参数后面,无须符号表。 |
|