Homework 1

22C:116, Spring 1997

Due Friday Aug 29, 1997, in class

Douglas W. Jones

This assignment is dominated by review questions that are not as much specific to the material in the book as they are to material you should have learned in prior courses or work experience.

  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: On most computers, the standard C calling sequence for an external procedure pushes all of the caller's registers on the stack along with the return address and the previous value of the frame pointer. Within the called procedure, the frame pointer (or local data pointer register) points to the base of the called procedure's activation record, and the saved registers are at fixed displacements from this.

    In all system programming languages, it is possible to take the address of a variable. In Ada, this involves an operation from the unsafe programming package; in C or C++, the ampersand operator does this; in system programming extensions to Pascal, it is typically done with a nonstandard address() function. In all cases, the address of a variable is a pointer and array addressing can be used to perform pointer arithmetic so long as the compiler does not generate code to check array bounds.

    Taking the address of a local variable in a procedure or function yields the address of a location in the activation record of that program unit, and arithmetic on this pointer can be used to create the address of any variable at a known offset within the activation record or relative to it.

    The Problem: Given the above, look up the standard C library routines longjmp() and setjmp() (these are defined in the on-line manual on most UNIX systems), and then -- without reference to the contents of <setjmp.h> write a definition of the declaration for the type jmp_buf and write C (or Pascal or Ada or ...) code for longjup() and setjmp().

    You may ignore the second parameter to longjmp() and the return value from setjmp() for the purpose of this assignment. You may also use defined constants with "unknown" values for offsets within the activation record. To make your code work under any particular compiler, you would have to set these constants appropriately, probably by experiment, but you are not required to find the values of these unknowns for this assignment!

  3. Can you explain how the above assignment relates to context switching? Explain this in a short paragraph.

  4. What is an interrupt? Explain this in a short paragraph.