Reverse Assembly _ while statement Disassembly
By: for example
Chapter 4, while statement Disassembly
Sample Code:
1 #include"stdio.h" 2 int function(int a,int b) 3 { 4 int c=a+b; 5 int i=0; 6 while(i<50) 7 { 8 c=c+i; 9 }10 return c;11 }12 void main()13 {14 function(1,2);15 }
Disassembly code:
1 #include "stdio.h"2 3 int function(int a,int b)4 5 {
00ae1a40 push EBP
00ae1a41 mov EBP, ESP
00ae1a43 sub ESP, 0d8h
00ae1a49 push EBX
00ae1a4a push ESI
00ae1a4b push EDI
00ae1a4c Lea EDI, [ebp-0D8h]
00ae1a52 mov ECx, 36 h
00ae1a57 mov eax, 0 cccccccch
00ae1a5c rep STOs dword ptr es: [EDI]; Start allocating 36 4-byte space, locate to EDI, EDI is from [ebp-od8h], locate to buffer header and initialize to CC,
1 int c=a+b;
00ae1a5e mov eax, dword ptr [A]; Variable A is put into eax,
00ae1a61 add eax, dword ptr [B]; Add variable A to variable B and put the result to eax.
00ae1a64 mov dword ptr [c], eax; Variable C is equal to variable A + variable B, equal to C = A + B;
1 int i=0;
00ae1a67 mov dword ptr [I], 0; variable d equals 0
1 while(i<50)
00ae1a6e cmp dword ptr [I], 32 h; compare whether variable D is greater than or equal to 0x32 h (hexadecimal)
00ae1a72 jge Function + 3fh (0ae1a7fh); if not greater than or equal to, point to the following statement; otherwise, jump 0x00ae1a7f
1 { 2 c=c+i;
00ae1a74 mov eax, dword ptr [c]; C = C + I
00ae1a77 add eax, dword ptr [I]
00ae1a7a mov dword ptr [c], eax
}
00ae1a7d JMP Function + 2EH (0ae1a6eh) can be restored to IF and else statements if this is the next hop
00ae1a7f mov eax, dword ptr [c]; put the result of C into eax. eax is the return value of the function, so the result is return C;
}
00ae1a82 pop EDI
00ae1a83 pop ESI
00ae1a84 pop EBX
00ae1a85 mov ESP, EBP
00ae1a87 pop EBP
00ae1a88 RET
Damn typographical, annoying