IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> C++知识库 -> 反汇编 之C 内联函数 -> 正文阅读

[C++知识库]反汇编 之C 内联函数

#include <stdio.h>

/*
?* 内联函数
?*/

inline int max(int a, int b)
{
??? if (a > b)
??????? return a;

??? return b;
}

int max(int a, int b);

int main(int argc, char **argv)
{
??? printf("%x\n", max(0x666, 0x777));
??? printf("%x\n", max(0x666, argc));
??? printf("%x\n", max(0x666, argc));

??? return 0;
}

#if 0

/*
?* intel
?*/

0000000000001149 <max>:
??? 1149:?? ?f3 0f 1e fa???????? ??? ?endbr64
??? 114d:?? ?55????????????????? ??? ?push?? %rbp?? ??? ??? ??? ?// rsp=rsp-8, rsp=rbp ===> subq $8,%rsp, movq %rbp,(%rsp)
??? 114e:?? ?48 89 e5??????????? ??? ?mov??? %rsp,%rbp?? ??? ?// rbp=rsp
??? 1151:?? ?89 7d fc??????????? ??? ?mov??? %edi,-0x4(%rbp)?? ?// edi = parameter1, 0x666
??? 1154:?? ?89 75 f8??????????? ??? ?mov??? %esi,-0x8(%rbp)?? ?// esi = parameter2, 0x777
??? 1157:?? ?8b 45 fc??????????? ??? ?mov??? -0x4(%rbp),%eax?? ?// eax = parameter1
??? 115a:?? ?3b 45 f8??????????? ??? ?cmp??? -0x8(%rbp),%eax?? ?// parameter1 - parameter2
??? 115d:?? ?7e 05?????????????? ??? ?jle??? 1164 <max+0x1b>?? ?// CMP指令的第一个操作表达式小于或等于(不大于)第二个表达式,JLE将跳转到指令所标明的地址;
??? 115f:?? ?8b 45 fc??????????? ??? ?mov??? -0x4(%rbp),%eax?? ?// eax = return value = parameter1, 0x666
??? 1162:?? ?eb 03?????????????? ??? ?jmp??? 1167 <max+0x1e>?? ?// 跳转到函数结尾
??? 1164:?? ?8b 45 f8??????????? ??? ?mov??? -0x8(%rbp),%eax?? ?// eax = return value = parameter2, 0x777
??? 1167:?? ?5d????????????????? ??? ?pop??? %rbp?? ??? ??? ??? ?// rbp=rsp, rsp+8 ===> movq %rsp,(%rbp), addq $8, (%rsp)
??? 1168:?? ?c3????????????????? ??? ?retq?? ??? ??? ??? ??? ?// ===> pop %rip

0000000000001169 <main>:
??? 1169:?? ?f3 0f 1e fa???????? ??? ?endbr64
??? 116d:?? ?55????????????????? ??? ?push?? %rbp?? ??? ??? ??? ?// rsp=rsp-8, rsp=rbp ===> subq $8,%rsp, movq %rbp,(%rsp)
??? 116e:?? ?48 89 e5??????????? ??? ?mov??? %rsp,%rbp?? ??? ?// rbp=rsp
??? 1171:?? ?48 83 ec 10???????? ??? ?sub??? $0x10,%rsp?? ??? ?// rsp=rsp-0x10
??? 1175:?? ?89 7d fc??????????? ??? ?mov??? %edi,-0x4(%rbp)?? ?// rbp-0x4 = edi = argc
??? 1178:?? ?48 89 75 f0???????? ??? ?mov??? %rsi,-0x10(%rbp)?? ?// rbp=0x10 = rsi = argv
??? 117c:?? ?be 77 07 00 00????? ??? ?mov??? $0x777,%esi?? ??? ?// esi = 0x777
??? 1181:?? ?bf 66 06 00 00????? ??? ?mov??? $0x666,%edi?? ??? ?// edi = 0x666
??? 1186:?? ?e8 be ff ff ff????? ??? ?callq? 1149 <max>?? ??? ?// max(edi, esi)
??? 118b:?? ?89 c6?????????????? ??? ?mov??? %eax,%esi?? ??? ?// esi = return value
??? 118d:?? ?48 8d 3d 70 0e 00 00 ?? ?lea??? 0xe70(%rip),%rdi??????? # 2004 <_IO_stdin_used+0x4> // rdi = "%x\n"
??? 1194:?? ?b8 00 00 00 00????? ??? ?mov??? $0x0,%eax?? ??? ?// eax = 0
??? 1199:?? ?e8 b2 fe ff ff????? ??? ?callq? 1050 <printf@plt>?? ?// printf(rdi, esi)
??? 119e:?? ?8b 45 fc??????????? ??? ?mov??? -0x4(%rbp),%eax?? ?// eax = rbp-0x4 (argc)
??? 11a1:?? ?89 c6?????????????? ??? ?mov??? %eax,%esi?? ??? ?// esi = eax
??? 11a3:?? ?bf 66 06 00 00????? ??? ?mov??? $0x666,%edi?? ??? ?// edi = 0x666
??? 11a8:?? ?e8 9c ff ff ff????? ??? ?callq? 1149 <max>?? ??? ?// max(edi, esi)
??? 11ad:?? ?89 c6?????????????? ??? ?mov??? %eax,%esi?? ??? ?// esi = return value
??? 11af:?? ?48 8d 3d 4e 0e 00 00 ?? ?lea??? 0xe4e(%rip),%rdi??????? # 2004 <_IO_stdin_used+0x4> // rdi = "%x\n"
??? 11b6:?? ?b8 00 00 00 00????? ??? ?mov??? $0x0,%eax?? ??? ?// eax = 0
??? 11bb:?? ?e8 90 fe ff ff????? ??? ?callq? 1050 <printf@plt>?? ?// printf(rdi, esi)
??? 11c0:?? ?8b 45 fc??????????? ??? ?mov??? -0x4(%rbp),%eax?? ?// eax = rbp-0x4 (argc)
??? 11c3:?? ?89 c6?????????????? ??? ?mov??? %eax,%esi?? ??? ?// esi = eax
??? 11c5:?? ?bf 66 06 00 00????? ??? ?mov??? $0x666,%edi?? ??? ?// edi = 0x666
??? 11ca:?? ?e8 7a ff ff ff????? ??? ?callq? 1149 <max>?? ??? ?// max(edi, esi)
??? 11cf:?? ?89 c6?????????????? ??? ?mov??? %eax,%esi?? ??? ?// esi = return value
??? 11d1:?? ?48 8d 3d 2c 0e 00 00 ?? ?lea??? 0xe2c(%rip),%rdi??????? # 2004 <_IO_stdin_used+0x4> // rdi = "%x\n"
??? 11d8:?? ?b8 00 00 00 00????? ??? ?mov??? $0x0,%eax?? ??? ?// eax = 0
??? 11dd:?? ?e8 6e fe ff ff????? ??? ?callq? 1050 <printf@plt>?? ?// printf(rdi, esi)
??? 11e2:?? ?b8 00 00 00 00????? ??? ?mov??? $0x0,%eax?? ??? ?// return value 0
??? 11e7:?? ?c9????????????????? ??? ?leaveq?? ??? ??? ??? ??? ?// ===> mov %rbp,%rsp, pop %rbp
??? 11e8:?? ?c3????????????????? ??? ?retq?? ??? ??? ??? ??? ?// ===> pop %rip
??? 11e9:?? ?0f 1f 80 00 00 00 00 ?? ?nopl?? 0x0(%rax)?? ??? ?// 流水线指令优化

/*
?* arm
?*/

000000000040055c <max>:
? 40055c:?? ?d10043ff ?? ?sub?? ?sp, sp, #0x10?? ??? ??? ?// sp = sp-0x10
? 400560:?? ?b9000fe0 ?? ?str?? ?w0, [sp, #12]?? ??? ??? ?// sp+12 = w0
? 400564:?? ?b9000be1 ?? ?str?? ?w1, [sp, #8]?? ??? ??? ?// sp+8 = w1
? 400568:?? ?b9400fe1 ?? ?ldr?? ?w1, [sp, #12]?? ??? ??? ?// w1 = sp+12
? 40056c:?? ?b9400be0 ?? ?ldr?? ?w0, [sp, #8]?? ??? ??? ?// w0 = sp+8
? 400570:?? ?6b00003f ?? ?cmp?? ?w1, w0?? ??? ??? ??? ??? ?// w1-w0
? 400574:?? ?5400006d ?? ?b.le?? ?400580 <max+0x24>?? ?// <=?? ?
? 400578:?? ?b9400fe0 ?? ?ldr?? ?w0, [sp, #12]?? ??? ??? ?// w0 = sp+12
? 40057c:?? ?14000002 ?? ?b?? ?400584 <max+0x28>?? ??? ?// 跳转到函数结尾
? 400580:?? ?b9400be0 ?? ?ldr?? ?w0, [sp, #8]?? ??? ??? ?// w0 = sp+8
? 400584:?? ?910043ff ?? ?add?? ?sp, sp, #0x10?? ??? ??? ?// sp = sp+0x10
? 400588:?? ?d65f03c0 ?? ?ret

000000000040058c <main>:
? 40058c:?? ?a9be7bfd ?? ?stp?? ?x29, x30, [sp, #-32]!?? ?// sp=sp-32, sp=x29=fp, sp+8=x30=lr
? 400590:?? ?910003fd ?? ?mov?? ?x29, sp?? ??? ??? ??? ??? ?// x29=fp=sp
? 400594:?? ?b9001fa0 ?? ?str?? ?w0, [x29, #28]?? ??? ??? ?// x29+28=w0=argc
? 400598:?? ?f9000ba1 ?? ?str?? ?x1, [x29, #16]?? ??? ??? ?// x29+16=x1=argv
? 40059c:?? ?5280eee1 ?? ?mov?? ?w1, #0x777??????????????? ??? ?// #1911
? 4005a0:?? ?5280ccc0 ?? ?mov?? ?w0, #0x666??????????????? ??? ?// #1638
? 4005a4:?? ?97ffffee ?? ?bl?? ?40055c <max>?? ??? ??? ?// max(w0, w1)
? 4005a8:?? ?2a0003e1 ?? ?mov?? ?w1, w0?? ??? ??? ??? ??? ?// w1=w0=return value
? 4005ac:?? ?90000000 ?? ?adrp?? ?x0, 400000 <_init-0x3e8>
? 4005b0:?? ?911ac000 ?? ?add?? ?x0, x0, #0x6b0?? ??? ??? ?// x0="%x\n"
? 4005b4:?? ?97ffffa7 ?? ?bl?? ?400450 <printf@plt>?? ??? ?// printf(x0, w1)
? 4005b8:?? ?b9401fa1 ?? ?ldr?? ?w1, [x29, #28]?? ??? ??? ?// w1 = x29+28 = argc
? 4005bc:?? ?5280ccc0 ?? ?mov?? ?w0, #0x666??????????????? ??? ?// #1638
? 4005c0:?? ?97ffffe7 ?? ?bl?? ?40055c <max>?? ??? ??? ?// max(w0, w1)
? 4005c4:?? ?2a0003e1 ?? ?mov?? ?w1, w0?? ??? ??? ??? ??? ?// w1 = w0 = return value
? 4005c8:?? ?90000000 ?? ?adrp?? ?x0, 400000 <_init-0x3e8>
? 4005cc:?? ?911ac000 ?? ?add?? ?x0, x0, #0x6b0?? ??? ??? ?// x0="%x\n"
? 4005d0:?? ?97ffffa0 ?? ?bl?? ?400450 <printf@plt>?? ??? ?// printf(x0, w1)
? 4005d4:?? ?b9401fa1 ?? ?ldr?? ?w1, [x29, #28]?? ??? ??? ?// w1 = x29+28 = argc
? 4005d8:?? ?5280ccc0 ?? ?mov?? ?w0, #0x666??????????????? ??? ?// #1638
? 4005dc:?? ?97ffffe0 ?? ?bl?? ?40055c <max>?? ??? ??? ?// max(w0, w1)
? 4005e0:?? ?2a0003e1 ?? ?mov?? ?w1, w0?? ??? ??? ??? ??? ?// w1 = w0 = return value
? 4005e4:?? ?90000000 ?? ?adrp?? ?x0, 400000 <_init-0x3e8>
? 4005e8:?? ?911ac000 ?? ?add?? ?x0, x0, #0x6b0?? ??? ??? ?// x0="%x\n"
? 4005ec:?? ?97ffff99 ?? ?bl?? ?400450 <printf@plt>?? ??? ?// printf(x0, w1)
? 4005f0:?? ?52800000 ?? ?mov?? ?w0, #0x0????????????????? ??? ?// #0
? 4005f4:?? ?a8c27bfd ?? ?ldp?? ?x29, x30, [sp], #32?? ??? ?// fp=x29=sp, lr=x30=sp+8, sp=sp+32
? 4005f8:?? ?d65f03c0 ?? ?ret
? 4005fc:?? ?00000000 ?? ?.inst?? ?0x00000000 ; undefined

#endif

  C++知识库 最新文章
【C++】友元、嵌套类、异常、RTTI、类型转换
通讯录的思路与实现(C语言)
C++PrimerPlus 第七章 函数-C++的编程模块(
Problem C: 算法9-9~9-12:平衡二叉树的基本
MSVC C++ UTF-8编程
C++进阶 多态原理
简单string类c++实现
我的年度总结
【C语言】以深厚地基筑伟岸高楼-基础篇(六
c语言常见错误合集
上一篇文章      下一篇文章      查看所有文章
加:2022-03-30 18:05:26  更:2022-03-30 18:06:09 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/24 2:48:35-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码