设为首页 友情链接
在线留言 发表文章
加入收藏 广告联系

刺猬首页

| 专案技术 | 网络技术 | 图形图象 | 网络编程 | 网页设计 | 操作系统 | 服务器 | 技术白皮书 | 在线实验室 | 刺猬论坛 |
小说专版  | 数据库 | 设计赏析 | 存储频道 | 网络安全 | 私服架设 |  Solaris | 网站评估 | PC维护技巧 | 下载中心 | 博 客 |
专   题: | Linux | java | cisco | 防病毒 | 刀片 | SOA | iscsi | ASP.NET | SQL | Oracle |
您现在的位置: IT公社 IT community >> Linux专题 >> 开源空间 >> 教程正文 用户登录 新用户注册
专 题 栏 目
最 新 热 门
最 新 推 荐
相 关 文 章
让Firefox自动调用下载器
让firefox自动调用下载器
linux 的 umask 函数详解
Linux内核分析--系统调用…
Linux2.6对新型CPU快速系…
VFS层拦截read/write fi…
Linux常用C函数-终端控制…
Linux常用C函数-环境变量…
Linux常用C函数-接口处理…
Linux常用C函数-信号处理…
  调用函数时 寄存器到底发生了那些变化           
调用函数时 寄存器到底发生了那些变化
 

直存在比较模糊的概念,因此用一个例子强化记忆。

linux x86 gcc3.2.3 AT&T格式的汇编

代码如下:

void

fun()

{

int a = 'A';

}

void

main()

{

int b;

fun();

return;

}

开始调试

[sanool@sanool ex2]$ gdb a.out

GNU gdb Red Hat Linux (6.0post-0.20031117.6rh)

Copyright 2003 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.

This GDB was configured as "i386-redhat-linux-gnu"...(no debugging symbols found)...Using host libthread_db library "/lib/tls/libthread_db.so.1".

(gdb) disas main

Dump of assembler code for function main:

0x08048323 : push %ebp

0x08048324 : mov %esp,%ebp

0x08048326 : sub $0x8,%esp

0x08048329 : and $0xfffffff0,%esp

0x0804832c : mov $0x0,%eax

0x08048331 : sub %eax,%esp

0x08048333 : call 0x8048314

0x08048338 : leave

0x08048339 : ret

0x0804833a : nop

0x0804833b : nop

End of assembler dump.

(gdb) disas fun

Dump of assembler code for function fun:

0x08048314 : push %ebp

0x08048315 : mov %esp,%ebp

0x08048317 : sub $0x4,%esp

0x0804831a : movl $0x41,0xfffffffc(%ebp)

0x08048321 : leave

0x08048322 : ret

End of assembler dump.

解释如下:

**当程序下一步执行 0x08048333 : call 0x8048314

esp = 0xbfffe660 (运行时)

ebp = 0xbfffe668 (运行时)

eip = 0x08048333

**然后执行 call 0x8048314 也就是

push %eip ( 相当于 sub $4 %esp 再 mov %eip %esp )

movl $0x8048314, %eip

则0xbfffe65c 处为 eip = 0x08048338

且esp = 0xbfffe65c

eip = 0x8048314

ebp = 0xbfffe668

**执行0x08048314 : push %ebp后

esp = 0xbfffe658

ebp = 0xbfffe668

0xbfffe658处的值为 ebp = 0xbfffe668

**继续0x08048315 : mov %esp,%ebp

将esp的值赋值给ebp

即 ebp = esp = 0xbfffe658

**开始执行 0x08048321 : leave 前

eip = 0x08048321

ebp = 0xbfffe658

esp = 0xbfffe654

**开始执行 0x08048321 : leave 时

即进行

movl %ebp, %esp ( 即 esp = ebp = 0xbfffe658)

pop %ebp ( 也就是 mov %esp,%ebp 再 add $4,%esp )

此时 ebp = 0xbfffe668 回到了原函数的ebp值,

**再执行 0x08048322 : ret

即 pop %eip

( 也就是 mov %esp,%eip 再 add $4,%esp )

此时 eip = 0x08048338

程序继续执行 main 中的 leave

调用fun函数结束。

频道声明:本频道的文章除部分特别声明禁止转载的专稿外,可以自由转载.但请务必注明出出处和原始作者 文章版权归本频道与文章作者所有.对于被频道转载文章的个人和网站,我们表示深深的谢意。

原始作者:佚名 录入时间:2007-3-31 2:11:15
信息来源:不详 投稿信箱:itqoo@126.com
教程录入:itqoo    责任编辑:itqoo 
  • 上一个教程:

  • 下一个教程:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
      网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)
    - 关于我们 - 合作伙伴 - 友情链接 - 广告刊登 - 投稿热线 - 在线留言版权声明联系方式 -
    IT公社版权所有 粤ICP备05127012号
    Copyrigh@2005-2006 itqoo.com.Inc All Rights Reserved  推荐分辨率 1024*768
    联系站长:E-Mail:itqoo@126.com     MSN:urchincc@hotmail.com    QQ:点击这里给我发消息
    特别感谢:亿太网络提供空间支持