linux反汇编理解
来源:互联网 发布:如何提高党性知乎 通俗 编辑:程序博客网 时间:2024/05/22 10:31
Linux反汇编代码理解
2011-04-27 23:20:14| 分类:Assemble |字号 订阅
int triangle( int width, int height)
{
int arr{0,1,2,3,4};
int area;
area = width * height /2;
return (area);
}
void main()
{
triangle(5,4);
}
~~~~~gdb反汇编代码
$ gdb example
(gdb) disass main
Dump of assembler co
0x080483f6 <+0>: push %ebp
0x080483f7 <+1>: mov %esp,%ebp
0x080483f9 <+3>: sub $0x8,%esp
0x080483fc <+6>: movl $0x4,0x4(%esp)
0x08048404 <+14>: movl $0x5,(%esp)
0x0804840b <+21>: call 0x80483b4 <triangle>
0x08048410 <+26>: leave
0x08048411 <+27>: ret
End of assembler dump.
(gdb) disass triangle
Dump of assembler co
0x080483b4 <+0>: push %ebp
0x080483b5 <+1>: mov %esp,%ebp
0x080483b7 <+3>: sub $0x20,%esp
0x080483ba <+6>: movl $0x0,-0x18(%ebp)
0x080483c1 <+13>: movl $0x1,-0x14(%ebp)
0x080483c8 <+20>: movl $0x2,-0x10(%ebp)
0x080483cf <+27>: movl $0x3,-0xc(%ebp)
0x080483d6 <+34>: movl $0x4,-0x8(%ebp)
0x080483dd <+41>: mov 0x8(%ebp),%eax
0x080483e0 <+44>: imul 0xc(%ebp),%eax
0x080483e4 <+48>: mov %eax,%edx
0x080483e6 <+50>: shr $0x1f,%edx
0x080483e9 <+53>: lea (%edx,%eax,1),%eax
0x080483ec <+56>: sar %eax
0x080483ee <+58>: mov %eax,-0x4(%ebp)
0x080483f1 <+61>: mov -0x4(%ebp),%eax
0x080483f4 <+64>: leave
0x080483f5 <+65>: ret
End of assembler dump.
~~~~~栈使用情况
~~~~~部分汇编代码解释
main:
mov %esp,%ebp ;esp-->ebp
sub $0x8,%esp ;esp-8-->esp
movl $0x4,0x4(%esp) ;4-->esp+4
movl $0x5,(%esp) ;5-->esp
call 0x80483b4 <triangle> ;跳转到0x80483b4,同时将下一条指令的地址(0x08048410)压栈(即ret)
triangle:
sub $0x20,%esp ;esp-20-->esp
movl $0x0,-0x18(%ebp) ;0-->ebp-18
movl $0x1,-0x14(%ebp) ;1-->ebp-14
movl $0x2,-0x10(%ebp) ;2-->ebp-10
movl $0x3,-0xc(%ebp) ;3-->ebp-c
movl $0x4,-0x8(%ebp) ;4-->ebp-8
mov 0x8(%ebp),%eax ;ebp+8(即param1:5)-->eax
imul 0xc(%ebp),%eax ;ebp+c(即param2:4)*eax(即param1:5)
mov %eax,%edx
shr $0x1f,%edx ;逻辑右移(高位补0)
lea (%edx,%eax,1),%eax
sar %eax ;算术右移
mov %eax,-0x4(%ebp) ;把运算结果放入area变量中
mov -0x4(%ebp),%eax
leave
ret
enter等价于push %ebp
mov %esp,%ebp
leave等价于mov %ebp,%esp
pop %ebp
ret num等价于pop %eip
add num,%esp
movl variable,%eax ;把variable作为一个地址,取地址为variable处的值赋给eax
movl $variable,%eax ;把variable作为一个立即数赋给eax
仍然不明白width*height/2是怎么执行的……
- linux反汇编理解
- linux 反汇编objdump
- 反汇编linux程序
- linux 反汇编
- linux反汇编
- Linux反汇编命令
- linux反汇编调试
- linux x86 ELF 反汇编
- linux下反汇编实例
- linux下如何反汇编
- 从反汇编理解堆栈及printf
- 反汇编RETN 0x0c的理解
- Linux Debugging(一): 使用反汇编理解C++程序函数调用栈
- Linux Debugging(七): 使用反汇编理解动态库函数调用方式GOT/PLT
- linux下反汇编一个程序,并通过分析汇编代码理解计算机是如何工作的
- linux 下使用 objdump 反汇编
- linux反汇编旁门左道小技巧一则
- Linux下的objdump反汇编工具
- 无线路由
- TCL中双引号和大括号的区别
- 开博记事
- Reorder List
- 将Image对象和byte[]互相转换
- linux反汇编理解
- 2013.11.10
- 哈希存储和冲突解决办法
- 从1.5K到18K 一个程序员的5年成长之路
- 解决Android emulator运行编译好的源码黑屏
- Linked List Cycle
- Solr学习(三) 牛刀小试之SolrJ
- Linked List Cycle II
- 硬件测试及故障检测