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. Object Destructuring Assignment vs Object.assign

    Object Destructuring Assignment vs Object.assign // const params = Object.assign({}, this.$route.par ...

  2. Linux cp command All In One

    Linux cp command All In One $ man cp $ cp -h # 强制 $ cp -f # 递归,复制文件夹 $ cp -r demos cp -fr # ./folder ...

  3. Promise nested then execute order All In One

    Promise nested then execute order All In One Promise nested then nested Promise not return new Promi ...

  4. where is the storage location of the browser's HTTP cache? disk or memory

    where is the storage location of the browser's HTTP cache? disk or memory HTTP cache & storage l ...

  5. Chrome debug & string to object & copy format json

    Chrome debug & string to object & copy format json // save as global variable copy(JSON.stri ...

  6. web performance optimise & css

    web performance optimise & css 俄罗斯套娃 clients hints https://cloudinary.com/blog/automatic_respons ...

  7. nasm astrcpy_s函数 x86

    xxx.asm %define p1 ebp+8 %define p2 ebp+12 %define p3 ebp+16 section .text global dllmain export ast ...

  8. 算法型稳定币USDN有什么魔力引发市场热潮?

    最近比特币重新突破了8万大关,区块链行业又再次火爆起来,吸引了圈内圈外人的火热讨论,而这其中市场投资者讨论最频繁的就要属算法型稳定币USDN了. USDN是基于NGK.IO区块链中的稳定币, 1枚US ...

  9. 「NGK每日快讯」12.23日NGK第50期官方快讯!

  10. 开发Microsoft Teams选项卡应用安全注意事项

    我们都知道,为了方便广大的开发人员快速开发Microsoft Teams选项卡应用,微软提供了一个JS SDK,你可以通过这里 https://docs.microsoft.com/en-us/jav ...