Homework Set #6


  1. Problem 6.4 from the text. To clarify, the code is attempting to use semaphores to protect access to the shared variable iRecordCount.

  2. Problem 6.5 from the text.

  3. Write a short C program that includes a switch statement matching an integer variable against at least eight consecutive integer constants with distinct actions for each case. It should have the following form:
    switch (i) {
        case 0: actions_0; break;
        case 1: actions_1; break;
        case 2: actions_2; break;
        case 3: actions_3; break;
        case 4: actions_4; break;
        case 5: actions_5; break;
        case 6: actions_6; break;
        case 7: actions_7; break;
        default: actions_d; break;
    }
    
    where actions_i is an short sequence of C statements. Compile the program using the ECEn 425 tools and study the resulting .s file. Describe in detail the mechanism used to implement the flow of control through the switch statement.

    Write another C program that includes the switch statement again but this time have it match an integer variable against eight randomly chosen integer values (that you choose) between 0 and 1000. Compile the program and study the resulting .s file. Describe in detail the mechanism used to implement the flow of control through the switch statement.

    Compare and contrast the two implementations of switch statements that you discovered above. How are they different, and why are they different? On the basis of what you've seen can there be significant differences in overhead between switch statements that appear similar at the source code level? What lesson should a programmer learn from this?


Turn in your hard-copy solution for this assignment to the homework box before 4:45 PM on the due date.
Last updated 3 September 2013
James Archibald jka@ee.byu.edu