debug

  • do···while
23:     int nSum = 0;
00A572AE C7 45 F8 00 00 00 00 mov dword ptr [nSum],0
24: int nIndex = 0;
00A572B5 C7 45 EC 00 00 00 00 mov dword ptr [nIndex],0
25: do
26: {
27: nSum += nIndex;
00A572BC 8B 45 F8 mov eax,dword ptr [nSum]
00A572BF 03 45 EC add eax,dword ptr [nIndex]
00A572C2 89 45 F8 mov dword ptr [nSum],eax
28: nIndex++;
00A572C5 8B 45 EC mov eax,dword ptr [nIndex]
00A572C8 83 C0 01 add eax,1
00A572CB 89 45 EC mov dword ptr [nIndex],eax
29: } while(nIndex <= nCount);
00A572CE 8B 45 EC mov eax,dword ptr [nIndex]
00A572D1 3B 45 08 cmp eax,dword ptr [nCount]//先执行循环体,后判断
00A572D4 7E E6 jle LoopDO+2Ch (0A572BCh)
30: return nSum;
00A572D6 8B 45 F8 mov eax,dword ptr [nSum]
  • while
34:     int nSum = 0;
00A5738E C7 45 F8 00 00 00 00 mov dword ptr [nSum],0
35: int nIndex = 0;
00A57395 C7 45 EC 00 00 00 00 mov dword ptr [nIndex],0
36: while (nIndex <= nCount)
00A5739C 8B 45 EC mov eax,dword ptr [nIndex]
00A5739F 3B 45 08 cmp eax,dword ptr [nCount] //先判断,后循环
00A573A2 7F 14 jg LoopWhile+48h (0A573B8h)
37: {
38: nSum += nIndex;
00A573A4 8B 45 F8 mov eax,dword ptr [nSum]
00A573A7 03 45 EC add eax,dword ptr [nIndex]
00A573AA 89 45 F8 mov dword ptr [nSum],eax
39: nIndex++;
00A573AD 8B 45 EC mov eax,dword ptr [nIndex]
00A573B0 83 C0 01 add eax,1
00A573B3 89 45 EC mov dword ptr [nIndex],eax
40: }
00A573B6 EB E4 jmp LoopWhile+2Ch (0A5739Ch)
41: return nSum;
00A573B8 8B 45 F8 mov eax,dword ptr [nSum]
  • for
46:     int nSum = 0;
00A5731E C7 45 F8 00 00 00 00 mov dword ptr [nSum],0
47: for (int nIndex = 0; nIndex <= nCount; ++nIndex)
00A57325 C7 45 EC 00 00 00 00 mov dword ptr [ebp-14h],0 //先初始化计数器变量
00A5732C EB 09 jmp LoopFor+37h (0A57337h)
00A5732E 8B 45 EC mov eax,dword ptr [ebp-14h]
00A57331 83 C0 01 add eax,1 //步长
00A57334 89 45 EC mov dword ptr [ebp-14h],eax
00A57337 8B 45 EC mov eax,dword ptr [ebp-14h]
00A5733A 3B 45 08 cmp eax,dword ptr [nCount] //判断循环条件
00A5733D 7F 0B jg LoopFor+4Ah (0A5734Ah)
48: {
49: nSum += nIndex;
00A5733F 8B 45 F8 mov eax,dword ptr [nSum]
00A57342 03 45 EC add eax,dword ptr [ebp-14h]
00A57345 89 45 F8 mov dword ptr [nSum],eax
50: }
00A57348 EB E4 jmp LoopFor+2Eh (0A5732Eh)
51: return nSum;
00A5734A 8B 45 F8 mov eax,dword ptr [nSum]

release

int GoToDo(int nCount)
{
int nSum = 0;
int nIndex = 0;
GOTO_DO:
nSum += nIndex;
nIndex++;
if (nIndex <= nCount)
{
goto GOTO_DO;
}
return nSum;
}

printf("%d \r\n", GoToDo(5));

00D01143  | 33C9            | xor ecx,ecx              | looptype.cpp:83
00D01145 | 33C0 | xor eax,eax |
00D01147 | 03C8 | add ecx,eax |
00D01149 | 40 | inc eax |
00D0114A | 83F8 05 | cmp eax,0x5 |
00D0114D | 7E F8 | jle looptype.D01147 |
00D0114F | 51 | push ecx |
00D01150 | 68 9401D400 | push looptype.D40194 | D40194:"%d \r\n"
00D01155 | E8 76000000 | call <looptype.printf> |
00D0115A | 83C4 08 | add esp,0x8 |

int LoopDO(int nCount)
{

int nSum = 0;
int nIndex = 0;
do
{
nSum += nIndex;
nIndex++;
} while(nIndex <= nCount);
return nSum;
}

printf("%d \r\n", LoopDO(5));

00D0115D  | 33C9            | xor ecx,ecx              | looptype.cpp:84
00D0115F | 33C0 | xor eax,eax |
00D01161 | 03C8 | add ecx,eax |
00D01163 | 40 | inc eax |
00D01164 | 83F8 05 | cmp eax,0x5 |
00D01167 | 7E F8 | jle looptype.D01161 |
00D01169 | 51 | push ecx |
00D0116A | 68 9401D400 | push looptype.D40194 | D40194:"%d \r\n"
00D0116F | E8 5C000000 | call <looptype.printf> |

 

// 强度降低
void DoRate(int argc)
{
int t = 0;
int i = 0;
while (t < argc)
{
t = i * 99;
i++;
}
printf("%d", t);

}

00D011A6  | 8B55 08         | mov edx,dword ptr ss:[eb | looptype.cpp:88
00D011A9 | 83C4 08 | add esp,0x8 | looptype.cpp:87
00D011AC | 33C9 | xor ecx,ecx |
00D011AE | 85D2 | test edx,edx |//while优化为do···while结构,添加一个判断
00D011B0 | 7E 0B | jle looptype.D011BD |
00D011B2 | 33C0 | xor eax,eax |
00D011B4 | 8BC8 | mov ecx,eax |
00D011B6 | 83C0 63 | add eax,0x63 |循环体, *99优化为+99
00D011B9 | 3BCA | cmp ecx,edx |
00D011BB | 7C F7 | jl looptype.D011B4 |
00D011BD | 51 | push ecx |
00D011BE | 68 9001D400 | push looptype.D40190 | D40190:"%d"
00D011C3 | E8 08000000 | call <looptype.printf> |
00D011C8 | 83C4 08 | add esp,0x8 |

c++ 反汇编 循环结构的更多相关文章

  1. Python学习--04条件控制与循环结构

    Python学习--04条件控制与循环结构 条件控制 在Python程序中,用if语句实现条件控制. 语法格式: if <条件判断1>: <执行1> elif <条件判断 ...

  2. Swift -运算符和循环结构

    p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo; color: #4dbf56 } p.p2 { margin: 0.0px 0. ...

  3. 浅析PHP中for与foreach两个循环结构遍历数组的区别

    遍历一个数组是编程中最常见不过的了,这里跟大家讨论下for和foreach两种方法.用这两种方法执行遍历的场景太多太多了,这里我们只针对以下两个数组作为例子来讨论.所谓管中窥豹,多少能理清一点两者的区 ...

  4. PHP流程控制之循环结构

    计算机程序最擅长的功能之一就是按规定的条件,重复执行某些操作.循环结构可以减少源程序重复书写的工作量,即在给定条件成立时,反复执行某程序段,直到条件不成立为止.给定的条件称为循环条件,反复执行的程序段 ...

  5. python基础之循环结构以及列表

    python基础之编译器选择,循环结构,列表 本节内容 python IDE的选择 字符串的格式化输出 数据类型 循环结构 列表 简单购物车的编写 1.python IDE的选择 IDE的全称叫做集成 ...

  6. C语言-循环结构及break、continue

    循环结构 --1-- 结构循环 1.1 while循环 1.2 do…while循环 1.3 for循环 --2-- break和continue 2.1 break关键字 2.2 continue关 ...

  7. 黑马程序员——C语言基础 流程控制 选择结构和循环结构

    ---恢复内容开始--- Java培训.Android培训.iOS培训..Net培训.期待与您交流! (以下内容是对黑马苹果入学视频的个人知识点总结) (一)流程控制 1> 顺序结构:默认的流程 ...

  8. Java 第8章 循环结构进阶

    循环结构进阶 什么是二重循环? 二重循环的执行顺序是什么?

  9. luogg_java学习_03_流程控制及循环结构

    本文为博主辛苦总结,希望自己以后返回来看的时候理解更深刻,也希望可以起到帮助初学者的作用. 转载请注明 出自 : luogg的博客园 谢谢配合! 程序流程控制 顺序结构 分支结构:if-else,sw ...

随机推荐

  1. Pycharm缺少环境变量+无法获取libcudnn.so.6

    在终端输入: echo LD_LIBRARY_PATH, 并将其内容 添加至Pycharm的 run -> Edit configuration -> Environment variab ...

  2. 图解 H5 与 WebView 数据通信原理

    图解 H5 与 WebView 数据通信原理 Android / iOS / RN / Flutter H5 接受数据 自定义 schema H5 调用原生 API 拍照,扫码 原生 调用 H5 AP ...

  3. WebAssembly in Action

    WebAssembly in Action 数据加密,反爬虫,防盗链,版权保护,数据追踪,埋点 blogs 加密,js 禁用检测,权限控制 WebAssembly 防盗链 wasm online id ...

  4. HTTP/2 & Push Cache

    HTTP/2 & Push Cache HTTP/2 & 推送缓存 https://caniuse.com/#search=http2 https://jakearchibald.co ...

  5. svg click event bug & css pointer-events

    svg click event bug & css pointer-events svg click event not working Error OK ??? css class /* d ...

  6. flutter 让app跟随系统的theme

    首先你需要在"MaterialApp"设置两套theme MaterialApp( theme: myTheme, // light darkTheme: ThemeData.da ...

  7. 算法型稳定币USDN有什么价值和用途?

    USDN的标签是"数字美元",与大多数稳定资产一样,USDN是一种金融服务产品.基于NGK公链发行的算法型稳定币USDN,USDN是和美元1:1锚定的加密数字货币,1USDN等于1 ...

  8. SSL/TLS协议详解(上):密码套件,哈希,加密,密钥交换算法

    本文转载自SSL/TLS协议详解(上):密码套件,哈希,加密,密钥交换算法 导语 作为一名安全爱好者,我一向很喜欢SSL(目前是TLS)的运作原理.理解这个复杂协议的基本原理花了我好几天的时间,但只要 ...

  9. vue_webpack

    1.生成项目工程描述文件 npm init 2.安装webpack开发依赖 (本地安装):npm install -D 3.(webpack4.0版本以上安装webpack cli) npm inst ...

  10. TERSUS无代码开发(笔记09)-简单实例前端样式设计

    前端常用样式设计 =========================================================================================== ...