Include as much information as you can about the

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: nt branches of the switch statement. Observe that the block of code labeled loc_def will be executed either when x is outside the range 100 to 106 (by the initial range checking) or when it equals either 101 or 105 (based on the jump table). Note how the code for the block labeled loc_B falls through to the block labeled loc_C. 132 CHAPTER 3. MACHINE-LEVEL REPRESENTATION OF C PROGRAMS Practice Problem 3.13: In the following C function, we have omitted the body of the switch statement. In the C code, the case labels did not span a contiguous range, and some cases had multiple labels. int switch2(int x) { int result = 0; switch (x) { /* Body of switch statement omitted */ } return result; } In compiling the function, GCC generates the following assembly code for the initial part of the procedure and for the jump table. Variable x is initially at offset 8 relative to register %ebp. 1 2 3 4 5 Setting up jump table access movl 8(%ebp),%eax Retrieve x Jump table for switch2 1 2 3 4 5 6 7 8 addl $2,%eax cmpl $6,%eax ja .L10 jmp *.L11(,%eax,4) .L11: .long .long .long .long .long .long .long .L4 .L10 .L5 .L6 .L8 .L8 .L9 From this determine: A. What were the values of the case labels in the switch...
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