Assembly Language for Beginners

(Jeff_L) #1

1.15. SWITCH()/CASE/DEFAULT


After the jump we are at0x010B103A: the code printing “two” will now be executed:


Figure 1.53:OllyDbg: now we at thecase:label

Non-optimizing GCC


Let’s see what GCC 4.4.1 generates:


Listing 1.153: GCC 4.4.1
public f
f proc near ; CODE XREF: main+10


var_18 = dword ptr -18h
arg_0 = dword ptr 8


push ebp
mov ebp, esp
sub esp, 18h
cmp [ebp+arg_0], 4
ja short loc_8048444
mov eax, [ebp+arg_0]
shl eax, 2
mov eax, ds:off_804855C[eax]
jmp eax

loc_80483FE: ; DATA XREF: .rodata:off_804855C
mov [esp+18h+var_18], offset aZero ; "zero"
call _puts
jmp short locret_8048450


loc_804840C: ; DATA XREF: .rodata:08048560
mov [esp+18h+var_18], offset aOne ; "one"
call _puts
jmp short locret_8048450


loc_804841A: ; DATA XREF: .rodata:08048564
mov [esp+18h+var_18], offset aTwo ; "two"
call _puts
jmp short locret_8048450


loc_8048428: ; DATA XREF: .rodata:08048568

Free download pdf