循环指令的草稿
看过两天又给忘了 备份一下------------------------------------------------------
42: int nSum = 0;
0040D438 mov dword ptr ,0
43:
44: if (nSum < 0)
0040D43F cmp dword ptr ,0
0040D443 jge main+29h (0040d449)
45: return 0;
0040D445 xor eax,eax
0040D447 jmp main+85h (0040d4a5) // that over!
46:
------------------------------------------------------
47: for (int i = 0; i< 100 ;i++)
0040D449 mov dword ptr ,0
0040D450 jmp main+3Bh (0040d45b) // 赋值后JMP到判断条件 循环体
0040D452 mov eax,dword ptr
0040D455 add eax,1
0040D458 mov dword ptr ,eax
0040D45B cmp dword ptr ,64h
0040D45F jge main+4Ch (0040d46c) // 若条件失败 跳出循环体
48: {
49: nSum ++;
0040D461 mov ecx,dword ptr // 典型的赋值语句
0040D464 add ecx,1
0040D467 mov dword ptr ,ecx
50: }
0040D46A jmp main+32h (0040d452) // 循环指令结束后 要跳向i++指令用的是JMP
51:
------------------------------------------------------
52: int j = 0;
0040D46C mov dword ptr ,0
53: do
54: {
55: nSum --;
0040D473 mov edx,dword ptr
0040D476 sub edx,1
0040D479 mov dword ptr ,edx
56: j++;
0040D47C mov eax,dword ptr
0040D47F add eax,1
0040D482 mov dword ptr ,eax
57: } while (j<100);
0040D485 cmp dword ptr ,64h
0040D489 jl main+53h (0040d473) // do{ } while() 执行完代码后判断条件 成立则调向循环体
58:
------------------------------------------------------
59: int k = 0;
0040D48B mov dword ptr ,0
60:
61: while(k < 100)
0040D492 cmp dword ptr ,64h // 先判断 失败退出
0040D496 jge main+83h (0040d4a3)
62: {
63: nSum++;
0040D498 mov ecx,dword ptr
0040D49B add ecx,1
0040D49E mov dword ptr ,ecx
64: }
0040D4A1 jmp main+72h (0040d492) // 执行完循环体后 JMP 跳到判断条件处也用到JMP
------------------------------------------------------
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
for(int i = 0;i<100;i++)
01. 变量赋初值,JMP到判断条件,失败则跳出循环体,
02. 执行函数体,JMP到判断条件。
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
do
{
}while(i<100);
1. 执行函数体,判断条件,成立则跳向函数体;
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
while(i<100)
{
}
1. 判断条件,不成立则跳出循环体;
2. 执行函数体,JMP到判断条件
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 还有 break; continue;
if()条件的逻辑与 非 之间的关系
///////////////////////////////////////////////////
for (int i = 0; i < 100 ; i++)
{
if(i % 3 == 0)
break;
if(i % 5 == 1)
continue;
if(i % 7 == 9)
goto Here;
}
Here:
/////////////////////////////////////////////////
41: for (int i = 0; i < 100 ; i++)
0040D446 mov dword ptr ,0
0040D44D jmp main+38h (0040d458)
0040D44F mov eax,dword ptr
0040D452 add eax,1
0040D455 mov dword ptr ,eax
0040D458 cmp dword ptr ,64h
0040D45C jge Here (0040d498)
42: {
43: if(i % 3 == 0)
0040D45E mov eax,dword ptr
0040D461 cdq
0040D462 mov ecx,3
0040D467 idiv eax,ecx
0040D469 test edx,edx
0040D46B jne main+4Fh (0040d46f)
44: break;
0040D46D jmp Here (0040d498)
45: if(i % 5 == 1)
0040D46F mov eax,dword ptr
0040D472 cdq
0040D473 mov ecx,5
0040D478 idiv eax,ecx
0040D47A cmp edx,1
0040D47D jne main+61h (0040d481)
46: continue;
0040D47F jmp main+2Fh (0040d44f)
47: if(i % 7 == 9)
0040D481 mov eax,dword ptr
0040D484 cdq
0040D485 mov ecx,7
0040D48A idiv eax,ecx
0040D48C cmp edx,9
0040D48F jne main+76h (0040d496)
48: goto Here;
0040D491 jmp Here+0D9h (0040d571)
49: }
0040D496 jmp main+2Fh (0040d44f)
50: Here:
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
break; jmp over
continue; jmp 条件指令处
goto先跳到末尾 然后再通过另一个JMP返回
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
00401000/$56 PUSH ESI
00401001|.57 PUSH EDI
00401002|.33C9 XOR ECX,ECX
00401004|.BE 01000000 MOV ESI,1
00401009|>8BC1 /MOV EAX,ECX
0040100B|.BF 03000000 |MOV EDI,3
00401010|.99 |CDQ
00401011|.F7FF |IDIV EDI
00401013|.85D2 |TEST EDX,EDX
00401015|.74 23 |JE SHORT esitest.0040103A
00401017|.8BC1 |MOV EAX,ECX
00401019|.BF 05000000 |MOV EDI,5
0040101E|.99 |CDQ
0040101F|.F7FF |IDIV EDI
00401021|.3BD6 |CMP EDX,ESI
00401023|.74 0F |JE SHORT esitest.00401034
00401025|.8BC1 |MOV EAX,ECX
00401027|.BF 07000000 |MOV EDI,7
0040102C|.99 |CDQ
0040102D|.F7FF |IDIV EDI
0040102F|.83FA 09 |CMP EDX,9
00401032|.74 06 |JE SHORT esitest.0040103A
00401034|>41 |INC ECX
00401035|.83F9 64 |CMP ECX,64
00401038|.^ 7C CF \JL SHORT esitest.00401009 无优化版...release优化后的基本都是do while结构/:011 release版真是恶魔 …… /:001 6.0的还好..2010的优化太xx了,让人觉得完全没用汇编优化指令的必要
小兔子行行好,别删我贴了 = =/:QQ2
页:
[1]