Assembly: loop statement

while

void while01()
{
    
    
	int i = 0;
	while (i<20)
	{
    
    
		i++;
	}
}

i<20:jge
i<=20:jg
i>20:jle
i>=20:jl

push ebp
mov ebp,esp
sub esp,44
push ebx
push esi
push edi
mov dword ptr ss:[ebp-4],0
cmp dword ptr ss:[ebp-4],14
jge 0623_x86_x64_asm.411841
mov eax,dword ptr ss:[ebp-4]
add eax,1
mov dword ptr ss:[ebp-4],eax
jmp 0623_x86_x64_asm.411830
pop edi
pop esi
pop ebx
mov esp,ebp
pop ebp
ret 

for

void for01()
{
    
    
	for(int i=0;i<20;i++)
	{
    
    

	}
}

i<20:jge
i<=20:jg
i>20:jle
i>=20:jl

push ebp
mov ebp,esp
sub esp,44
push ebx
push esi
push edi
mov dword ptr ss:[ebp-4],0
jmp 0623_x86_x64_asm.41177B
mov eax,dword ptr ss:[ebp-4]
add eax,1
mov dword ptr ss:[ebp-4],eax
cmp dword ptr ss:[ebp-4],14
jge 0623_x86_x64_asm.411783
jmp 0623_x86_x64_asm.411772
pop edi
pop esi
pop ebx
mov esp,ebp
pop ebp
ret

dowhile

void dowhile01()
{
    
    
	int i = 0;
	do
	{
    
    
		i++;
	} while (i < 20);

}

i<20:jl
i<=20:jle
i>20:jg
i>=20:jge

push ebp
mov ebp,esp
sub esp,44
push ebx
push esi
push edi
mov dword ptr ss:[ebp-4],0
mov eax,dword ptr ss:[ebp-4]
add eax,1
mov dword ptr ss:[ebp-4],eax
cmp dword ptr ss:[ebp-4],14
jl 0623_x86_x64_asm.411770
pop edi
pop esi
pop ebx
mov esp,ebp
pop ebp
ret 

Flags affected by CMP

CF: If the highest bit generates a carry or borrow, CF is set to 1, otherwise it is set to 0
ZF: 0 flag, 0 is 1, not 0 is 0
OF: Overflow flag, acid overflow is 1, no overflow is 0 SF:
Sign bit, 0 is positive, 1 is negative
AF: Auxiliary carry flag, if the lower 4 bits of the low byte generate Carry or borrow, set 1, otherwise set 0 PF: Parity
flag

Conditions required for conditional jump
JG------------ZF=0&&SF=OF
JGE----------SF=OF
JL ------------SF!=OF
JLE-----------ZF=1||SF!=OF

Guess you like

Origin blog.csdn.net/sanqiuai/article/details/124395359