|
我有一个代码:
- #include <unistd.h>
- char* get_str(void)
- {
- char str* = {"abcdefghijk"};
- return str;
- }
- int main(int argc, char* argv[])
- {
- char* p = get_str();
- printf("%s\n",p);
- return 0;
- }
复制代码
gcc -S a.c之后生成的汇编文件如下
- ……
- get_str:
- pushl %ebp
- movl %esp, %ebp
- subl $16, %esp
- movl .LC0, %eax
- movl %eax, -12(%ebp)
- movl .LC0+4, %eax
- movl %eax, -8(%ebp)
- movl .LC0+8, %eax
- movl %eax, -4(%ebp)
- leal -12(%ebp), %eax
- leave
- ret
- .size get_str, .-get_str
- .globl main
- .type main, @function
- main:
- leal 4(%esp), %ecx
- andl $-16, %esp
- pushl -4(%ecx)
- pushl %ebp
- movl %esp, %ebp
- pushl %ecx
- subl $20, %esp
- call get_str
- movl %eax, -8(%ebp)
- movl -8(%ebp), %eax
- movl %eax, (%esp)
- call puts
- movl $0, %eax
- addl $20, %esp
- popl %ecx
- popl %ebp
- leal -4(%ecx), %esp
- ret
- .size main, .-main
- ……
复制代码
main函数开头为
leal 4(%esp), %ecx
andl $-16, %esp
pushl -4(%ecx)
为何有一个偏移量4呢? esp要和-16与,最后又不用与了呢?
谢谢 |
|