Homework 1

22C:116, Fall 2000

Due Friday Aug 25, 2000, in class

Douglas W. Jones

Always, on every assignment, please write your name legibly as it appears on your University ID and on the class list!

  1. What is your E-mail address? (If you have more than one, give the address you'd prefer used for class purposes.)

  2. Background: An exception handler is a component of a program that takes over control when the program detects something unexpected. Typically, what the programmer needs is a mechanism that will allow a computation to be abandoned, returning control to the main program or to some outer level control structure and discarding a potentially large number of activation records that were pushed on the stack between the last time that outer level was running and the time the exception was discovered.

    Read the UNIX man pages for setjmp() and longjmp(). Note that the intended purpose of these routines is for exception handling. C or C++ program can use setjmp to remember the context of the outer loop of the program, and whenever a computation in an inner part of the program detects an error, perhaps in a function called by a function called by a function, a call to longjmp() will escape to the saved context.

    The steriotypical implementation of C (and Pascal, and Algol, and all related languages) stores all variables in memory at all times, using a single stack for both activation records and temporary variables. The CPU needed to execute a program in this model has only 3 registers, FP, the frame pointer, pointing to the base of the current activation record, SP, the stack pointer, pointing to the top of the stack, and PC, the program counter, pointing to the next instruction. Of course, real implementations are far more comples.

    The Problem: Consider the following implementation of the jump buffer:

    struct jumpbuffer {
        long int pc;  /* the saved program counter */
        long int sp;  /* the saved stack pointer */
    }
    
    What assumptions must be true of the code generated by the compiler to make this definition adequate?

  3. Explain the difference between an interrupt and a trap, as these terms are conventionally defined. You will typically need to refer to the material covered in an undergraduate operating system or computer architecture course to find the definitions of these terms.