第39节:while循环语句介绍
例子:
#include "stdio.h"
#include "windows.h"
void MyPrint(int x)
{
int i = 0;
while(i<=x)
{
printf("%d\n",i);
i++;
}
return;
}
void main(){
MyPrint(100);
return;
}
反汇编代码:
4: void MyPrint(int x)
5: {
00401020 push ebp
00401021 mov ebp,esp
00401023 sub esp,44h
00401026 push ebx
00401027 push esi
00401028 push edi
00401029 lea edi,[ebp-44h]
0040102C mov ecx,11h
00401031 mov eax,0CCCCCCCCh
00401036 rep stos dword ptr [edi]
6: int i = 0;
00401038 mov dword ptr [ebp-4],0
7: while(i<=x)
0040103F mov eax,dword ptr [ebp-4]
00401042 cmp eax,dword ptr [ebp+8]
00401045 jg MyPrint+43h (00401063)
8: {
9: printf("%d\n",i);
00401047 mov ecx,dword ptr [ebp-4]
0040104A push ecx
0040104B push offset string "%d\n" (0042201c)
00401050 call printf (004010d0)
00401055 add esp,8
10: i++;
00401058 mov edx,dword ptr [ebp-4]
0040105B add edx,1
0040105E mov dword ptr [ebp-4],edx
11: }
00401061 jmp MyPrint+1Fh (0040103f)
12: return;
13: }
00401063 pop edi
例子:
#include "stdio.h"
#include "windows.h"
void MyPrint(int x)
{
int i = 0;
while(i<=x)
{
printf("%d\n",i);
i++;
}
return;
}
void main(){
MyPrint(100);
return;
}
反汇编代码:
4: void MyPrint(int x)
5: {
00401020 push ebp
00401021 mov ebp,esp
00401023 sub esp,44h
00401026 push ebx
00401027 push esi
00401028 push edi
00401029 lea edi,[ebp-44h]
0040102C mov ecx,11h
00401031 mov eax,0CCCCCCCCh
00401036 rep stos dword ptr [edi]
6: int i = 0;
00401038 mov dword ptr [ebp-4],0
7: while(i<=x)
0040103F mov eax,dword ptr [ebp-4]
00401042 cmp eax,dword ptr [ebp+8]
00401045 jg MyPrint+43h (00401063)
8: {
9: printf("%d\n",i);
00401047 mov ecx,dword ptr [ebp-4]
0040104A push ecx
0040104B push offset string "%d\n" (0042201c)
00401050 call printf (004010d0)
00401055 add esp,8
10: i++;
00401058 mov edx,dword ptr [ebp-4]
0040105B add edx,1
0040105E mov dword ptr [ebp-4],edx
11: }
00401061 jmp MyPrint+1Fh (0040103f)
12: return;
13: }
00401063 pop edi