Chinaunix首页 | 论坛 | 博客
  • 博客访问: 724123
  • 博文数量: 251
  • 博客积分: 10367
  • 博客等级: 上将
  • 技术积分: 2750
  • 用 户 组: 普通用户
  • 注册时间: 2007-05-10 14:43
文章分类

全部博文(251)

文章存档

2009年(2)

2008年(86)

2007年(163)

分类:

2008-03-16 01:12:17

/*   code.c  */

int accum = 0;


int sum( int x,int y ){
     int t = x + y;
     accum += t;

     return t;
}



;code.s (部分)

注意参数x,y的进栈顺序:y 在先,x在后

sum:
    pushl    %ebp
    movl    %esp, %ebp
    movl    12(%ebp), %eax      ; 12(%ebp) ==> y
    addl    8(%ebp), %eax        ; 8(%ebp) ==> x
    addl    %eax, accum
    popl    %ebp
    ret


[heixia@localhost program]$ gcc -O2 -c code.c
[heixia@localhost program]$ gdb code.o
(gdb) x/19xb
0x0 <sum>: 0x55 0x89 0xe5 0x8b 0x45 0x0c 0x03 0x45
0x8 <sum+8>: 0x08 0x01 0x05 0x00 0x00 0x00 0x00 0x5d
0x10 <sum+16>: 0xc3 Cannot access memory at address 0x11

反汇编工具objdump
[heixia@localhost program]$ objdump -d code.o

code.o: file format elf32-i386

Disassembly of section .text:

00000000 <sum>:
   0: 55                    push %ebp
   1: 89 e5                mov %esp,%ebp
   3: 8b 45 0c            mov 0xc(%ebp),%eax
   6: 03 45 08             add 0x8(%ebp),%eax
   9: 01 05 00 00 00 00   add %eax,0x0
   f: 5d                   pop %ebp
  10: c3                   ret

阅读(800) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~