第一题的习题,以及分析:
第二题的习题以及分析:
第二题的vc6++验证:
7: void fun(int x,int y) 8: { 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] 9: int i,j; 10: i=a; 00401038 mov eax,[a (00427c50)] 0040103D mov dword ptr [ebp-4],eax 11: j=2; 00401040 mov dword ptr [ebp-8],2 12: if(x>=y){ 00401047 mov ecx,dword ptr [ebp+8] 0040104A cmp ecx,dword ptr [ebp+0Ch] 0040104D jl fun+38h (00401058) 13: j=j+1; 0040104F mov edx,dword ptr [ebp-8] 00401052 add edx,1 00401055 mov dword ptr [ebp-8],edx 14: } 15: if(x<y){ 00401058 mov eax,dword ptr [ebp+8] 0040105B cmp eax,dword ptr [ebp+0Ch] 0040105E jge fun+4Bh (0040106b) 16: a=j; 00401060 mov ecx,dword ptr [ebp-8] 00401063 mov dword ptr [a (00427c50)],ecx 17: }else{ 00401069 jmp fun+57h (00401077) 18: a=i+j; 0040106B mov edx,dword ptr [ebp-4] 0040106E add edx,dword ptr [ebp-8] 00401071 mov dword ptr [a (00427c50)],edx 19: } 20: } 00401077 pop edi 00401078 pop esi 00401079 pop ebx 0040107A mov esp,ebp 0040107C pop ebp 0040107D ret
还原出来源代码为:
int fun(int x,int y,int z){ int i, j, k; i = 0; j = 1; k = 2; if (x <= y) { i = j - 1; } else if (y >= z) { i = k + 1; } else if (x > z) { i=j+k; }else{ i=j+k-1; } return i+1; }
VS2019验证
#include <stdio.h> #include <string.h> #include <stdlib.h> int fun(int x, int y, int z) { 00F01750 push ebp 00F01751 mov ebp,esp 00F01753 sub esp,0E4h 00F01759 push ebx 00F0175A push esi 00F0175B push edi 00F0175C lea edi,[ebp-0E4h] 00F01762 mov ecx,39h 00F01767 mov eax,0CCCCCCCCh 00F0176C rep stos dword ptr es:[edi] 00F0176E mov ecx,offset _BDB5FF94_main_127_128_129@cpp (0F0C008h) 00F01773 call @__CheckForDebuggerJustMyCode@4 (0F0130Ch) int i, j, k; i = 0; j = 1; k = 2; 00F01778 mov dword ptr [i],0 00F0177F mov dword ptr [j],1 00F01786 mov dword ptr [k],2 if (x <= y) 00F0178D mov eax,dword ptr [x] 00F01790 cmp eax,dword ptr [y] 00F01793 jg fun+50h (0F017A0h) { i = j - 1; 00F01795 mov eax,dword ptr [j] 00F01798 sub eax,1 00F0179B mov dword ptr [i],eax } 00F0179E jmp fun+83h (0F017D3h) else if (y >= z) 00F017A0 mov eax,dword ptr [y] 00F017A3 cmp eax,dword ptr [z] 00F017A6 jl fun+63h (0F017B3h) { i = k + 1; 00F017A8 mov eax,dword ptr [k] 00F017AB add eax,1 00F017AE mov dword ptr [i],eax } 00F017B1 jmp fun+83h (0F017D3h) else if (x > z) 00F017B3 mov eax,dword ptr [x] 00F017B6 cmp eax,dword ptr [z] 00F017B9 jle fun+76h (0F017C6h) { i = j + k; 00F017BB mov eax,dword ptr [j] 00F017BE add eax,dword ptr [k] 00F017C1 mov dword ptr [i],eax } 00F017C4 jmp fun+83h (0F017D3h) else { i = j + k - 1; 00F017C6 mov eax,dword ptr [k] 00F017C9 mov ecx,dword ptr [j] 00F017CC lea edx,[ecx+eax-1] 00F017D0 mov dword ptr [i],edx } return i+1; 00F017D3 mov eax,dword ptr [i] 00F017D6 add eax,1 } 00F017D9 pop edi 00F017DA pop esi 00F017DB pop ebx 00F017DC add esp,0E4h 00F017E2 cmp ebp,esp 00F017E4 call __RTC_CheckEsp (0F01230h) 00F017E9 mov esp,ebp 00F017EB pop ebp 00F017EC ret
VC6++验证:
23: int fun2(int x,int y,int z){ 0040D4D0 push ebp 0040D4D1 mov ebp,esp 0040D4D3 sub esp,4Ch 0040D4D6 push ebx 0040D4D7 push esi 0040D4D8 push edi 0040D4D9 lea edi,[ebp-4Ch] 0040D4DC mov ecx,13h 0040D4E1 mov eax,0CCCCCCCCh 0040D4E6 rep stos dword ptr [edi] 24: 25: int i, j, k; 26: i = 0; j = 1; k = 2; 0040D4E8 mov dword ptr [ebp-4],0 0040D4EF mov dword ptr [ebp-8],1 0040D4F6 mov dword ptr [ebp-0Ch],2 27: if (x <= y) 0040D4FD mov eax,dword ptr [ebp+8] 0040D500 cmp eax,dword ptr [ebp+0Ch] 0040D503 jg fun2+40h (0040d510) 28: { 29: i = j - 1; 0040D505 mov ecx,dword ptr [ebp-8] 0040D508 sub ecx,1 0040D50B mov dword ptr [ebp-4],ecx 30: } 31: else if (y >= z) 0040D50E jmp fun2+73h (0040d543) 0040D510 mov edx,dword ptr [ebp+0Ch] 0040D513 cmp edx,dword ptr [ebp+10h] 0040D516 jl fun2+53h (0040d523) 32: { 33: i = k + 1; 0040D518 mov eax,dword ptr [ebp-0Ch] 0040D51B add eax,1 0040D51E mov dword ptr [ebp-4],eax 34: } 35: else if (x > z) 0040D521 jmp fun2+73h (0040d543) 0040D523 mov ecx,dword ptr [ebp+8] 0040D526 cmp ecx,dword ptr [ebp+10h] 0040D529 jle fun2+66h (0040d536) 36: { 37: i=j+k; 0040D52B mov edx,dword ptr [ebp-8] 0040D52E add edx,dword ptr [ebp-0Ch] 0040D531 mov dword ptr [ebp-4],edx 38: 39: }else{ 0040D534 jmp fun2+73h (0040d543) 40: i=j+k-1; 0040D536 mov eax,dword ptr [ebp-0Ch] 0040D539 mov ecx,dword ptr [ebp-8] 0040D53C lea edx,[ecx+eax-1] 0040D540 mov dword ptr [ebp-4],edx 41: } 42: 43: 44: return i+1; 0040D543 mov eax,dword ptr [ebp-4] 0040D546 add eax,1 45: 46: } 0040D549 pop edi 0040D54A pop esi 0040D54B pop ebx 0040D54C mov esp,ebp 0040D54E pop ebp 0040D54F ret