当前位置: 技术问答>linux和unix
helloworld disassemble 問題
来源: 互联网 发布时间:2016-05-06
本文导语: int main(int argc,char *argv[]) { printf("hello world!n"); return 1; } gdb disassemble 後,能否解釋一下大概的動作在作什麼,跟直接寫汇編不太一樣 (gdb) disassemble main Dump of assembler code for function main: 0x08048374 : ...
int main(int argc,char *argv[])
{
printf("hello world!n");
return 1;
}
gdb disassemble 後,能否解釋一下大概的動作在作什麼,跟直接寫汇編不太一樣
(gdb) disassemble main
Dump of assembler code for function main:
0x08048374 : lea 0x4(%esp),%ecx
0x08048378 : and $0xfffffff0,%esp
0x0804837b : pushl -0x4(%ecx)
0x0804837e : push %ebp
0x0804837f : mov %esp,%ebp
0x08048381 : push %ecx
0x08048382 : sub $0x4,%esp
0x08048385 : movl $0x804845c,(%esp)
0x0804838c : call 0x80482d4
0x08048391 : mov $0x1,%eax
0x08048396 : add $0x4,%esp
0x08048399 : pop %ecx
0x0804839a : pop %ebp
0x0804839b : lea -0x4(%ecx),%esp
0x0804839e : ret
End of assembler dump.
{
printf("hello world!n");
return 1;
}
gdb disassemble 後,能否解釋一下大概的動作在作什麼,跟直接寫汇編不太一樣
(gdb) disassemble main
Dump of assembler code for function main:
0x08048374 : lea 0x4(%esp),%ecx
0x08048378 : and $0xfffffff0,%esp
0x0804837b : pushl -0x4(%ecx)
0x0804837e : push %ebp
0x0804837f : mov %esp,%ebp
0x08048381 : push %ecx
0x08048382 : sub $0x4,%esp
0x08048385 : movl $0x804845c,(%esp)
0x0804838c : call 0x80482d4
0x08048391 : mov $0x1,%eax
0x08048396 : add $0x4,%esp
0x08048399 : pop %ecx
0x0804839a : pop %ebp
0x0804839b : lea -0x4(%ecx),%esp
0x0804839e : ret
End of assembler dump.
|
0x08048374 : lea 0x4(%esp),%ecx // 将 esp + 4 保存到 ecx,以便后面恢复原始堆栈
0x08048378 : and $0xfffffff0,%esp // esp 向下取整到 16 字节对齐边界
0x0804837b : pushl -0x4(%ecx) // 压入原 esp
0x0804837e : push %ebp // 压入 ebp
0x0804837f : mov %esp,%ebp // 将 esp 赋值给 ebp
0x08048381 : push %ecx // 压入 ecx
0x08048382 : sub $0x4,%esp // 保留 printf 的变参空间,但是在 printf 中不会使用到
0x08048385 : movl $0x804845c,(%esp) // 将 "hello world" 字符串的起始地址(指针)压入堆栈
0x0804838c : call 0x80482d4 // 调用函数 printf
0x08048391 : mov $0x1,%eax // 将返回值设置为 1
0x08048396 : add $0x4,%esp // 弹出"hello world"指针
0x08048399 : pop %ecx // 弹出 ecx
0x0804839a : pop %ebp // 弹出 ebp
0x0804839b : lea -0x4(%ecx),%esp // 恢复到进入 main 函数时的原始堆栈形态
0x0804839e : ret
|
因为没有引用stdio。h,所以,链接了内部函数
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。