cpp反汇编之控制结构

控制结构主要是关于 if/else switch/case

废话不多说。。献上代码及反汇编分析。。

#include<stdio.h>int main(int argc , char *argv[]){int nInt = 9;//if(0 == nInt)__asm{cmp DWORD PTR [EBP – 4h] , 0 ;jle __exit;}//__asm{printf("%d\n" , nInt);/*push DWORD PTR [EBP – 4h];push offset string "%d\n";call printf ;add esp , 8h ; */}/*if(nInt > 9){printf("%d>9\n" , nInt);}else if(9 == nInt){printf("nInt = 9\n");}else if(8 == nInt){printf("nInt = 8\n");}*/switch(nInt){case 8 :nInt += 1; break;case 9 :nInt -= 9;break;default :nInt -= 1;break;}switch(nInt = scanf("%d" , &nInt)){case 1:printf("nInt = 1\n");break;case 2:printf("nInt = 2\n");break;case 3:printf("nInt = 3\n");break;case 5:printf("nInt = 5\n");break;case 6:printf("nInt = 6\n");break;case 7:printf("nInt = 7\n");break;case 100:printf("nInt = 100\n");break;case 400:printf("nInt = 400\n");break;case 500:printf("nInt = 500\n");break;default:break;}/*0040D76D leaedx,[ebp-4]0040D770 pushedx0040D771 pushoffset string "%d" (0042201c)0040D776 callscanf (0040fa20)0040D77B addesp,80040D77E movdword ptr [ebp-4],eax0040D781 moveax,dword ptr [ebp-4]0040D784 movdword ptr [ebp-0Ch],eax0040D787 movecx,dword ptr [ebp-0Ch]0040D78A subecx,1// case table index 0->max-10040D78D movdword ptr [ebp-0Ch],ecx0040D790 cmpdword ptr [ebp-0Ch],6//maxIndex0040D794 ja__exit (0040d7f8)0040D796 movedx,dword ptr [ebp-0Ch]0040D799 jmpdword ptr [edx*4+40D80Bh]//case table47:case 1:48:printf("nInt = 1\n");0040D7A0 pushoffset string "nInt = 1\n" (00422fe0)0040D7A5 callprintf (00401070)0040D7AA addesp,449:break;0040D7AD jmp__exit (0040d7f8) <strong> 执行一个判断就跳转到结尾处</strong>50:case 2:51:printf("nInt = 2\n");0040D7AF pushoffset string "nInt = 2\n" (00422fd4)0040D7B4 callprintf (00401070)0040D7B9 addesp,452:break;0040D7BC jmp__exit (0040d7f8)53:case 3:54:printf("nInt = 3\n");0040D7BE pushoffset string "nInt = 3\n" (00422fc8)0040D7C3 callprintf (00401070)0040D7C8 addesp,455:break;0040D7CB jmp__exit (0040d7f8)56:case 5:57:printf("nInt = 5\n");0040D7CD pushoffset string "nInt = 5\n" (00422fbc)0040D7D2 callprintf (00401070)0040D7D7 addesp,458:break;0040D7DA jmp__exit (0040d7f8)59:case 6:60:printf("nInt = 6\n");0040D7DC pushoffset string "nInt = 6\n" (00422fb0)0040D7E1 callprintf (00401070)0040D7E6 addesp,461:break;0040D7E9 jmp__exit (0040d7f8)62:case 7:63:printf("nInt = 7\n");0040D7EB pushoffset string "nInt = 7\n" (00422fa4)0040D7F0 callprintf (00401070)0040D7F5 addesp,464:break;65:default:66:break;67:}68: __exit:69:return 0;0040D7F8 xoreax,eax线性结构采用数组处理,用索引来引用。 0040FAED leaedx,[ebp-4]0040FAF0 pushedx0040FAF1 pushoffset string "%d" (0042201c)0040FAF6 callscanf (0040fa20)0040FAFB addesp,80040FAFE movdword ptr [ebp-4],eax0040FB01 moveax,dword ptr [ebp-4]0040FB04 movdword ptr [ebp-0Ch],eax0040FB07 cmpdword ptr [ebp-0Ch],64h0040FB0B jgmain+0B4h (0040fb34)0040FB0D cmpdword ptr [ebp-0Ch],64h#1000040FB11 je$L554+0Fh (0040fba5)0040FB17 movecx,dword ptr [ebp-0Ch]0040FB1A subecx,1#index0040FB1D movdword ptr [ebp-0Ch],ecx0040FB20 cmpdword ptr [ebp-0Ch],6#maxIndex0040FB24 ja__exit (0040fbd0)0040FB2A movedx,dword ptr [ebp-0Ch]0040FB2D jmpdword ptr [edx*4+40FBE3h]0040FB34 cmpdword ptr [ebp-0Ch],190h#4000040FB3B je$L554+1Eh (0040fbb4)0040FB3D cmpdword ptr [ebp-0Ch],1F4h#5000040FB44 je$L554+2Dh (0040fbc3)0040FB46 jmp__exit (0040fbd0)*/switch(nInt){case 2:printf("nInt = 2\n");break;case 3:printf("nInt = 3\n");break;case 8:printf("nInt = 8\n");break;case 10:printf("nInt = 10\n");break;case 35:printf("nInt = 35\n");break;case 37:printf("nInt = 37\n");break;case 666:printf("nInt = 666\n");break;}/*非线性,有另类的就采用二叉树处理。。/*0040FBD0 moveax,dword ptr [ebp-4]nInt -> eax0040FBD3 movdword ptr [ebp-10h],eax0040FBD6 cmpdword ptr [ebp-10h],0Ah> 100040FBDA jg$L554+60h (0040fbf6)0040FBDC cmpdword ptr [ebp-10h],0Ah= 100040FBE0 je$L554+0A4h (0040fc3a)0040FBE2 cmpdword ptr [ebp-10h],20040FBE6 je$L554+77h (0040fc0d)= 2 0040FBE8 cmpdword ptr [ebp-10h],3= 30040FBEC je$L554+86h (0040fc1c)0040FBEE cmpdword ptr [ebp-10h],80040FBF2 je$L554+95h (0040fc2b)=80040FBF4 jmp__exit (0040fc74)二叉树右枝0040FBF6 cmpdword ptr [ebp-10h],23h= 350040FBFA je$L554+0B3h (0040fc49)0040FBFC cmpdword ptr [ebp-10h],25h= 370040FC00 je$L554+0C2h (0040fc58)0040FC02 cmpdword ptr [ebp-10h],29Ah= 6660040FC09 je$L554+0D1h (0040fc67)0040FC0B jmp__exit (0040fc74)左枝结束*/__exit:return 0;}

,初初尝试着拥抱的人,一派新鲜幸福都来不及沉浸,

cpp反汇编之控制结构

相关文章:

你感兴趣的文章:

标签云: