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. 记一次 Billu_b0x渗透

    目录: 0x01 寻找ip 1.这边我们是使用的nmap来寻找我们的靶机IP地址,开始Ip是1,结束是254,153是我kali的ip,所以158就是我们的靶机的ip地址了. 2. 查看端口服务 这边 ...

  2. when I was installing github for windows ,some errors occurred !

    1: 2: 3: 4: install.log error messages:

  3. Web 开发之 HTTP/2 & SPDY & HTTP 1.1 & HTTP 对比分析详解!

    1 https://zh.wikipedia.org/wiki/HTTP/2 HTTP/2 维基百科,自由的百科全书                         HTTP/2(超文本传输协议第2版 ...

  4. 如何正确的使用 Dart SDK API

    如何正确的使用 Dart SDK API dart-core dart:core library https://api.dart.dev/stable/2.9.1/dart-core/dart-co ...

  5. 生态建设者为何青睐低风险、低成本的NGK算力?

    自从BGV推向市场以来,生态建设者的目光都聚集于BGV这个去中心化金融的新星,其实NGK的其他项目也都在稳健进行当中. NGK在未来将推出"算力市场奖励计划",NGK将会对算力市场 ...

  6. vscode 配置表

    { "git.ignoreMissingGitWarning": true, "editor.multiCursorModifier": "ctrlC ...

  7. Winform 判断打印机是否可用,实现设置默认打印机功能

    Winform 判断打印机是否可用,实现设置默认打印机功能 http://www.cnblogs.com/zfanlong1314/p/3878563.html

  8. HBase ——Shell操作

    HBase --Shell操作 Q:你觉得HBase是什么? A:一种结构化的分布式数据存储系统,它基于列来存储数据. 基于HBase,可以实现以廉价PC机器集群存储海量数据的分布式数据库的解决方案. ...

  9. Python网络编程相关的库与爬虫基础

    PythonWeb编程 ①相关的库:urlib.urlib2.requests python中自带urlib和urlib2,他们主要使用函数如下: urllib: urlib.urlopen() ur ...

  10. 使用pycallgraph分析python代码函数调用流程以及框架

    技术背景 在上一篇博客中,我们介绍了使用量子计算模拟器ProjectQ去生成一个随机数,也介绍了随机数的应用场景等.但是有些时候我们希望可以打开这里面实现的原理,去看看在产生随机数的过程中经历了哪些运 ...