324_Book

# The numbers along the left of the frames indicate the

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

This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ult += 10; /* Fall through */ case 103: result += 11; break; case 104: case 106: result *= result; break; default: result = 0; } return result; } code/asm/switch.c /* Next line is not legal C */ code *jt[7] = { loc_A, loc_def, loc_B, loc_C, loc_D, loc_def, loc_D }; int switch_eg_impl(int x) { unsigned xi = x - 100; int result = x; if (xi > 6) goto loc_def; /* Next goto is not legal C */ goto jt[xi]; loc_A: /* Case 100 */ result *= 13; goto done; loc_B: /* Case 102 */ result += 10; /* Fall through */ loc_C: /* Case 103 */ result += 11; goto done; loc_D: /* Cases 104, 106 */ result *= result; goto done; loc_def: /* Default case*/ result = 0; done: return result; } code/asm/switch.c (a) Switch statement. (b) Translation into extended C. Figure 3.14: Switch Statement Example with Translation into Extended C. The translation shows the structure of jump table jt and how it is accessed. Such tables and accesses are not actually allowed in C. 130 CHAPTER 3. MACHINE-LEVEL REPRESENTATION OF C PROGRAMS Set up the jump table access 1 2 3 4 leal -100(%edx),%eax cmpl \$6,%eax ja .L9 jmp *.L10(,%eax,4) Case 100 Compute xi = x-100 Compare xi:6 if >, goto done Goto jt[xi] 5 6 7 8 .L4: leal (%edx,%edx,2),%eax leal (%edx,%eax,4),%edx jmp .L3 Case 102 l...
View Full Document

## This note was uploaded on 09/02/2010 for the course ELECTRICAL 360 taught by Professor Schultz during the Spring '10 term at BYU.

Ask a homework question - tutors are online