L62 jumping dierent address modes for target direct

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: f Washington Jump Table Structure Memory C code: switch(x) { case 1: <some code> break; case 2: <some code> case 3: <some code> break; case 5: case 6: <some code> break; default: <some code> } Code Blocks We can use the jump table when x <= 6: Jump Table if (x <= 6) target = JTab[x]; goto *target; else goto default; x86 0 1 2 3 4 5 6 University of Washington Jump Table Jump table .section .rodata .align 4 .L62: .long .L61 # .long .L56 # .long .L57 # .long .L58 # .long .L61 # .long .L60 # .long .L60 # x x x x x x x = = = = = = = switch(x) { case 1: // .L56 w = y*z; break; case 2: // .L57 w = y/z; /* Fall Through */ case 3: // .L58 w += z; break; case 5: case 6: // .L60 w -= z; break; default: // .L61 w = 2; } 0 1 2 3 4 5 6 x86 University of Washington Switch Statement Example (IA32) long switch_eg(unsigned long x, long y, long z) { long w = 1; switch(x) { ... } return w; } Setup: switch_eg: pushl %ebp movl %esp, %ebp pushl %ebx movl $1, %ebx movl 8(%ebp), %edx movl 16(%ebp), %ecx cmpl $6, %edx ja .L61 jmp *.L62(,%edx,4) x86 # # # # # # # # # Jump table .section .rodata .align 4 .L62: .long .L61 # .long .L56 # .long .L57 # .long .L58 # .long .L61 # .long .L60 # .long .L60 # Setup Setup Setup w=1 edx = x ecx = z x:6 if T> goto default ransla<on? goto JTab[x] x x x x x x x = = = = = = = 0 1 2 3 4 5 6 University of Washington Switch Statement Example (IA32) long switch_eg(unsigned long x, long y, long z) { long w = 1; switch(x) { ... } return w; } Setup: switch_eg: pushl %ebp movl %esp, %ebp pushl %ebx movl $1, %ebx movl 8(%ebp), %edx movl 16(%ebp), %ecx cmpl $6, %edx Indirect ja .L61 jump jmp *.L62(,%edx,4) x86 # # # # # # # # # Jump table .section .rodata .align 4 .L62: .long .L61 # .long .L56 # .long .L57 # .long .L58 # .long .L61 # .long .L60 # .long .L60 # Setup Setup Setup w=1 edx = x ecx = z x:6 if > goto default goto JTab[x] x x x x x x x = = = = = = = 0 1 2 3 4 5 6 University of Washington Assembly Setup ExplanaMon   Table Structure Jump table   Each target requires 4 bytes   Base address at .L62   Jumping: different address modes for target Direct: jmp .L61   Jump target is denoted by label .L61 .section .rodata .align 4 .L62: .long .L61 # .long .L56 # .long .L57 # .long .L58 # .long .L61 # .long .L60 # .long .L60 # x x x x x x x...
View Full Document

This document was uploaded on 04/04/2014.

Ask a homework question - tutors are online