Reverse Assembly _ dowhile statement Disassembly
By: for example
The sample code is as follows:
1 #include"stdio.h" 2 int function(int a,int b) 3 { 4 int c=a+b; 5 int i=0; 6 do 7 { 8 c=c+i; 9 }while(i<50);10 return c;11 }12 void main()13 {14 function(1,2);15 }
Disassembly code
1 #include "stdio.h"2 3 4 int function(int a,int b)5 6 {
012e1a40 push EBP
012e1a41 mov EBP, ESP
012e1a43 sub ESP, 0d8h
012e1a49 push EBX; save the environment
012e1a4a push ESI
012e1a4b push EDI
012e1a4c Lea EDI, [ebp-0D8h]; initialized to 0xcc
012e1a52 mov ECx, 36 h
012e1a57 mov eax, 0 cccccccch
012e1a5c rep STOs dword ptr es: [EDI]
1 int c=a+b;
012e1a5e mov eax, dword ptr [A]
012e1a61 add eax, dword ptr [B]
012e1a64 mov dword ptr [c], eax
1 int i=0;
012e1a67 mov dword ptr [I], 0
do { c=c+i;
012e1a6e mov eax, dword ptr [c]; in the previous two chapters, I am familiar with this structure.
012e1a71 add eax, dword ptr [I]
012e1a74 mov dword ptr [c], eax
1 }while(i<50);
012e1a77 cmp dword ptr [I], 32 h; compare whether it is greater than 50; if it is smaller than it, jump up
012e1a7b JL Function + 2EH (12e1a6eh)
1 return c;
012e1a7d mov eax, dword ptr [c]}
012e1a80 pop EDI
012e1a81 pop ESI
012e1a82 pop EBX
012e1a83 mov ESP, EBP
012e1a85 pop EBP
012e1a86 RET
Conclusion: The do while loop is relatively easy to recognize.
Do_begin
..
...
Jxx
Do_beginHere is a jump-up process; execute the statement block first, and then compare it. When the condition is set, the statement will continue to be executed quickly,