c语言函数调用详细过程副本.doc

  1. 1、本文档共10页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
作者: Badcoffee Email: blog.oliver@ 2004年10月 原文出处: /yayong 这是作者在学习X86汇编过程中的学习笔记,难免有错误和疏漏之处,欢迎指正。 1. 编译环境 ?? OS: Axianux 1.0 ?? Compiler: gcc 3..2.3 ?? Linker: Solaris Link Editors 5.x ?? Debug Tool: gdb ?? Editor: vi !--[if !supportLineBreakNewLine]-- !--[endif]-- 2. 最简C代码分析 !--[if !supportLineBreakNewLine]-- !--[endif]-- 为简化问题,来分析一下最简的c代码生成的汇编代码: ??? # vi test1.c? ??? int main() ??? { ?? ?? ? return 0; ??? }?? ???? 编译该程序,产生二进制文件: ??? # gcc -o start start.c # file start??? ? start: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.2.5, dynamically linked (uses shared libs), not stripped ???? start是一个ELF格式32位小端(Little Endian)的可执行文件,动态链接并且符号表没有去除。这正是Unix/Linux平台典型的可执行文件格式。 ???? 用gdb反汇编可以观察生成的汇编代码: [wqf@15h166 attack]$ gdb start GNU gdb Asianux (6.0post-017.1AX) Copyright 2004 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type show copying to see the conditions. There is absolutely no warranty for GDB.?Type show warranty for details.r This GDB was configured as i386-asianux-linux-gnu...(no debugging symbols found)...Using host libthread_db library /lib/tls/libthread_db.so.1. (gdb) disassemble main牋牋牋牋?--- 反汇编main函数 Dump of assembler code for function main: 0main+0:??? push?? %ebp?? ---ebp寄存器内容压栈,即保存main函数的上级调用函数的栈基地址 0main+1:??? mov??? %esp,%ebp ?--- esp值赋给ebp,设置main函数的栈基址 0main+3:??? sub??? $0x8,%esp? ---通过ESP-8来分配8字节堆栈空间 0main+6:??? and??? $0xfffffff0,%esp ---使栈地址16字节对齐 0main+9:??? mov??? $0x0,%eax? ---? 无意义 0x0804831e main+14:?? sub??? %eax,%esp? ---? 无意义 0main+16:?? mov??? $0x0,%eax? ?--- 设置函数返回值0 0main+21:?? leave???? ---将ebp值赋给esp,pop先前栈内的上级函数栈的基地址给ebp,恢复原栈基址. !--[if !supportLineBreakNewLine]-- !--[endif]-- 0main+22:?? ret?? --- main函数返回,回到上级调用. 0main+23:?? nop End of assembler dump. 注:这里得到的汇编语言语法格式

您可能关注的文档

文档评论(0)

kehan123 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档