Lecture Slides 04 047-X86-Switch
Lecture Slides 04 047-X86-Switch
of Washington
•
Approximate
Transla;on
•
target = JTab[x]; •
goto *target;
Targn-1: Code
Block
n–1
x86
University
of
Washington
x86
University
of
Washington
Jump
Table
Jump
table
.section .rodata switch(x) {
.align 4 case 1: // .L56
.L62: w = y*z;
.long .L61 # x = 0 break;
.long .L56 # x = 1 case 2: // .L57
.long .L57 # x = 2 w = y/z;
.long .L58 # x = 3 /* Fall Through */
.long .L61 # x = 4 case 3: // .L58
.long .L60 # x = 5 w += z;
.long .L60 # x = 6 break;
case 5:
case 6: // .L60
w -= z;
break;
default: // .L61
w = 2;
}
x86
University
of
Washington
x86
University
of
Washington
x86
University
of
Washington
Assembly
Code
switch_eg:
. . .
ja .L61 # if > goto default
jmp *.L62(,%edx,4) # goto JTab[x]
x86
University
of
Washington
Disassembled
Targets
8048630: bb 02 00 00 00 mov $0x2,%ebx
8048635: 89 d8 mov %ebx,%eax
8048637: 5b pop %ebx
8048638: c9 leave
8048639: c3 ret
804863a: 8b 45 0c mov 0xc(%ebp),%eax
804863d: 99 cltd
804863e: f7 f9 idiv %ecx
8048640: 89 c3 mov %eax,%ebx
8048642: 01 cb add %ecx,%ebx
8048644: 89 d8 mov %ebx,%eax
8048646: 5b pop %ebx
8048647: c9 leave
8048648: c3 ret
8048649: 29 cb sub %ecx,%ebx
804864b: 89 d8 mov %ebx,%eax
804864d: 5b pop %ebx
804864e: c9 leave
804864f: c3 ret
8048650: 8b 5d 0c mov 0xc(%ebp),%ebx
8048653: 0f af d9 imul %ecx,%ebx
8048656: 89 d8 mov %ebx,%eax
8048658: 5b pop %ebx
8048659: c9 leave
804865a: c3 ret
x86
University
of
Washington
Ques;on
¢ Probably
not:
§ Don’t
want
a
jump
table
with
52001
entries
(too
big)
x86