标签:反汇编
int func(int a,int b) { int c=a+b; int i; for(i=0;i<50;i++){ c=c+i; } return c; } void main(){ int sum; sum=func(2,5); return 0; }
1: 2: int func(int a,int b) 3: { //初始工作,和前面一致。 00401020 push ebp 00401021 mov ebp,esp 00401023 sub esp,48h 00401026 push ebx 00401027 push esi 00401028 push edi 00401029 lea edi,[ebp-48h] 0040102C mov ecx,12h 00401031 mov eax,0CCCCCCCCh 00401036 rep stos dword ptr [edi] //这里进行加法运行 变量a、b、c都从堆栈中取出 4: int c=a+b; 00401038 mov eax,dword ptr [ebp+8] 0040103B add eax,dword ptr [ebp+0Ch] 0040103E mov dword ptr [ebp-4],eax 5: int i; 6: for(i=0;i<50;i++){ //将局部变量 i 置0 i从堆栈中取出 00401041 mov dword ptr [ebp-8],0 //跳转到00401053 处执行 比较i的值 00401048 jmp func+33h (00401053) //这里用ecx寄存器装载变量i的值 进行累加 0040104A mov ecx,dword ptr [ebp-8] 0040104D add ecx,1 00401050 mov dword ptr [ebp-8],ecx //这里用 i 和 50(32h) 比较 00401053 cmp dword ptr [ebp-8],32h //大于或者等于则跳转到00401064处 00401057 jge func+44h (00401064) //进行加法运算 局部变量c的值从栈中取出 7: c=c+i; 00401059 mov edx,dword ptr [ebp-4] 0040105C add edx,dword ptr [ebp-8] 0040105F mov dword ptr [ebp-4],edx 8: } //无条件跳转到0040104a处进行循环累加 00401062 jmp func+2Ah (0040104a) 9: return c; //循环结束,将变量c的值赋给eax, eax保存返回值 00401064 mov eax,dword ptr [ebp-4] 10: } //恢复各个寄存器的值 00401067 pop edi 00401068 pop esi 00401069 pop ebx 0040106A mov esp,ebp 0040106C pop ebp //返回 0040106D ret //主函数调用相同 11: 12: void main(){ 00401070 push ebp 00401071 mov ebp,esp 00401073 sub esp,44h 00401076 push ebx 00401077 push esi 00401078 push edi 00401079 lea edi,[ebp-44h] 0040107C mov ecx,11h 00401081 mov eax,0CCCCCCCCh 00401086 rep stos dword ptr [edi] 13: int sum; 14: sum=func(2,5); 00401088 push 5 0040108A push 2 0040108C call @ILT+5(_func) (0040100a) 00401091 add esp,8 00401094 mov dword ptr [ebp-4],eax 15: return 0; 16: } 00401097 pop edi 00401098 pop esi 00401099 pop ebx 0040109A add esp,44h 0040109D cmp ebp,esp 0040109F call __chkesp (0040d470) 004010A4 mov esp,ebp 004010A6 pop ebp 004010A7 ret
int func(int a,int b) { int c=a+b; int i; while(c<100){ c=c+i; } return c; } void main(){ int sum; sum=func(2,5); return 0; }
//前面的基本相同 不做详解 5: while(c<100){ //这里比较变量C和100(64h)的值 00401041 cmp dword ptr [ebp-4],64h //大于或者等于则跳转到00401052处退出循环 00401045 jge func+32h (00401052) 6: c=c+i; //加法运算 00401047 mov ecx,dword ptr [ebp-4] 0040104A add ecx,dword ptr [ebp-8] 0040104D mov dword ptr [ebp-4],ecx 7: } //无条件跳转到00401041处继续进行比较 00401050 jmp func+21h (00401041) 8: return c; 00401052 mov eax,dword ptr [ebp-4] 9: } 00401055 pop edi 00401056 pop esi 00401057 pop ebx 00401058 mov esp,ebp 0040105A pop ebp 0040105B ret
int func(int a,int b) { int c=a+b; int i; do{ c=c+i; }while(c<100); return c; } void main(){ int sum; sum=func(2,5); return 0; }
//前面的基本相同 不做详解 5: do{ 6: c=c+i; 00401041 mov ecx,dword ptr [ebp-4] 00401044 add ecx,dword ptr [ebp-8] 00401047 mov dword ptr [ebp-4],ecx 7: }while(c<100); //用变量c和100(64h)作比较 0040104A cmp dword ptr [ebp-4],64h //小于则跳转到00401041处执行循环体内加法 0040104E jl func+21h (00401041) 8: return c; 00401050 mov eax,dword ptr [ebp-4] 9: } 00401053 pop edi 00401054 pop esi 00401055 pop ebx 00401056 mov esp,ebp 00401058 pop ebp 00401059 ret
标签:反汇编
原文地址:http://blog.csdn.net/soldiers5/article/details/37597889