|
发表于 2005-3-13 11:23:15
|
显示全部楼层
用gcc -S可以得到汇编代码:
- .file "tt.c"
- .section .rodata
- .LC0:
- .string "Return value is: %s\n"
- .LC1:
- .string "%X\n"
- .text
- .globl main
- .type main, @function
- main:
- pushl %ebp
- movl %esp, %ebp
- subl $24, %esp
- andl $-16, %esp
- movl $0, %eax
- subl %eax, %esp
- call beyond_boundary
- movl %eax, -4(%ebp)
- movl -4(%ebp), %eax
- movl %eax, 4(%esp)
- movl $.LC0, (%esp)
- call printf
- movl -4(%ebp), %eax
- movl %eax, 4(%esp)
- movl $.LC1, (%esp)
- call printf
- leave
- ret
- .size main, .-main
- .section .rodata
- .LC2:
- .string "auto string"
- .text
- .globl beyond_boundary
- .type beyond_boundary, @function
- beyond_boundary:
- pushl %ebp
- movl %esp, %ebp
- subl $24, %esp
- movl $.LC2, -4(%ebp)
- movl -4(%ebp), %eax
- movl %eax, 4(%esp)
- movl $.LC1, (%esp)
- call printf
- movl -4(%ebp), %eax
- leave
- ret
- .size beyond_boundary, .-beyond_boundary
- .section .note.GNU-stack,"",@progbits
- .ident "GCC: (GNU) 3.3.3 20040412 (Gentoo Linux 3.3.3-r6, ssp-3.3.2-2, pie-8.7.6)"
复制代码
可以看出,字符串是放在数据段上的。不是在堆栈分配的。 |
|