else if…
#include<stdio.h>
int main()
{
int flag=0;
if(flag > 0)
{
printf("%d\n",flag);
}
else if(flag == 0)
{
printf("else if \n");
}
else
{
printf("else (flag < 0)\n");
}
return 0;
}
汇编
int main()
3: {
00401010 push ebp
00401011 mov ebp,esp
00401013 sub esp,44h
00401016 push ebx
00401017 push esi
00401018 push edi
00401019 lea edi,[ebp-44h]
0040101C mov ecx,11h
00401021 mov eax,0CCCCCCCCh
00401026 rep stos dword ptr [edi]
4:
5: int flag=0;
00401028 mov dword ptr [ebp-4],0
6:
7: if(flag > 0)
0040102F cmp dword ptr [ebp-4],0
00401033 jle main+38h (00401048) //进入 else if 判断
8: {
9: printf("%d\n",flag);
00401035 mov eax,dword ptr [ebp-4]
00401038 push eax
00401039 push offset string “%d\n” (0042201c)
0040103E call printf (004010c0)
00401043 add esp,8
10: }
11: else if(flag == 0)
00401046 jmp main+5Ah (0040106a) //执行了if ,结束后面判断
00401048 cmp dword ptr [ebp-4],0
0040104C jne main+4Dh (0040105d) //进入 else判断
12: {
13: printf(“else if \n”);
0040104E push offset string “else if \n” (00422fb8)
00401053 call printf (004010c0)
00401058 add esp,4
14: }
15: else
0040105B jmp main+5Ah (0040106a) //执行了 else if,结束后面判断
16: {x`
17: printf(“else (flag < 0)\n”);
0040105D push offset string “else \n” (00422fa4)
00401062 call printf (004010c0)
00401067 add esp,4
18: }
19:
20: return 0;
0040106A xor eax,eax
21: }
0040106C pop edi
0040106D pop esi
0040106E pop ebx
0040106F add esp,44h
00401072 cmp ebp,esp
00401074 call __chkesp (00401140)
00401079 mov esp,ebp
0040107B pop ebp
0040107C ret
结论
jmp XXX
cmp …
jcc …
多分支前 jmp的地址XXX一样。