If someone is interested, I assembled the output of this program in Visual C++. The Switch uses some kind of calculation to get a jump address.
Code:
int main()
{
int Alpha = 0;
//If
if(Alpha == 1)
{
Alpha = 0;
}
else if(Alpha == 10)
{
Alpha = 0;
}
else if(Alpha == 56)
{
Alpha = 0;
}
else if(Alpha == 128)
{
Alpha = 0;
}
//Switch
switch(Alpha)
{
case 1:
Alpha = 0;
break;
case 10:
Alpha = 0;
break;
case 56:
Alpha = 0;
break;
case 128:
Alpha = 0;
break;
}
return 0;
}
The IF-part got this output:
Code:
; Line 6
cmp DWORD PTR _Alpha$[ebp], 1
jne SHORT $L268
; Line 8
mov DWORD PTR _Alpha$[ebp], 0
; Line 10
jmp SHORT $L274
$L268:
cmp DWORD PTR _Alpha$[ebp], 10 ; 0000000aH
jne SHORT $L270
; Line 12
mov DWORD PTR _Alpha$[ebp], 0
; Line 14
jmp SHORT $L274
$L270:
cmp DWORD PTR _Alpha$[ebp], 56 ; 00000038H
jne SHORT $L272
; Line 16
mov DWORD PTR _Alpha$[ebp], 0
; Line 18
jmp SHORT $L274
$L272:
cmp DWORD PTR _Alpha$[ebp], 128 ; 00000080H
jne SHORT $L274
; Line 20
mov DWORD PTR _Alpha$[ebp], 0
$L274:
The SWITCH-part got this output:
Code:
; Line 25
mov eax, DWORD PTR _Alpha$[ebp]
mov DWORD PTR -8+[ebp], eax
mov ecx, DWORD PTR -8+[ebp]
sub ecx, 1
mov DWORD PTR -8+[ebp], ecx
cmp DWORD PTR -8+[ebp], 127 ; 0000007fH
ja SHORT $L276
mov eax, DWORD PTR -8+[ebp]
xor edx, edx
mov dl, BYTE PTR $L287[eax]
jmp DWORD PTR $L288[edx*4]
$L279:
; Line 27
mov DWORD PTR _Alpha$[ebp], 0
; Line 28
jmp SHORT $L276
$L280:
; Line 31
mov DWORD PTR _Alpha$[ebp], 0
; Line 32
jmp SHORT $L276
$L281:
; Line 35
mov DWORD PTR _Alpha$[ebp], 0
; Line 36
jmp SHORT $L276
$L282:
; Line 39
mov DWORD PTR _Alpha$[ebp], 0
$L276:
This was, of course, made in VC, so I'm not saying all compilers does it like this.