Originally Posted by
grumpy
Incorrect. A switch/case statement will be implemented as a jump table on any target machine that supports the necessary instructions.
To me this looks like an if-else tree.
Code:
; int switch_proc(int n)
push ebp
mov ebp,esp
; {
; switch(n)
@15:
mov eax,dword ptr [ebp+8]
cmp eax,546
jg short @23
je short @20
sub eax,6
je short @22
sub eax,228
je short @21
jmp short @16
@23:
sub eax,980
je short @19
sub eax,22
je short @18
jmp short @16
; {
; case 6: return 0;break;
@22:
xor eax,eax
@27:
pop ebp
ret
; case 1002: return 4;break;
@18:
mov eax,4
@28:
pop ebp
ret
; case 234: return 1;break;
@21:
mov eax,1
@29:
pop ebp
ret
; case 546: return 3;break;
@20:
mov eax,3
@30:
pop ebp
ret
; case 980: return 2;break;
@19:
mov eax,2
@31:
pop ebp
ret
; default: return -1;break;
@16:
or eax,-1
; }
; }
@26:
@24: