Assignment 1, Solutions

Part of the homework for 22C:112, Spring 2012
by Douglas W. Jones
THE UNIVERSITY OF IOWA Department of Computer Science

  1. What is your E-mail address?

    No solution offered

    Homework questions based on prerequisite material

  2. A Question: A typical program uses three memory segments, commonly referred to as the code segment, the stack segment, and the static segment. Identify the segment or segments that would typically holds each of the following: (0.2 points each)

    a) A subroutine.

    The code segment, fairly obviously.

    b) An integer local variable.

    Local variables are stored in activaiton records, also known as stack frames, that are stored in the stack segment.

    c) A string constant.

    Constants are best stored in the code segment, but in some cases, they are stored in the static segment.

    d) A global variable.

    Global variables are usually statically allocated, and this usually places them in the static segment. In rare cases, they are stored at the base of the stack segment.

    e) The method table shared by all members of a class in an object-oriented language.

    In compiled object-oriented languages with a static class hierarchy, the method table for each class is constant and may be stored with other constants in the code segment.

  3. Background: Typical computers include a number of addressing modes. We use absolute addressing, PC-relative addressing, indexed addressing and other modes. For each of the following, indicate the addressing mode most likely to be used. (0.2 points each)

    a) Reference to a statically allocated global variable.

    Absolute or direct memory addressing works for this on most computer architectures.

    b) Reference to another instruction in the current subroutine (for example, as used in a conditional branch instruction).

    PC-relative addressing is commonly used for this when it is available.

    c) Reference to a local variable.

    Indexed addressing with the stack-pointer as the index register is common for this, or alternatively with the frame-pointer as the index register.

    d) Reference to a field of the record representing an object.

    Indexed addressing with the pointer to the record stored in the index register.

    e) Reference to a separately compiled subroutine resolved by the linker.

    Absolute addressing is common for this, although some linkers can link using PC-relative addressing.

    Homework questions based on new material

  4. Background: Read the article by D.L. Parnas on the concept of transparency (either the tech report or the CACM article -- they are substantially the same).

    a) Why is transparency dangerous. (0.5 points)

    Transparency allows the user to enter potentially dangerous system states, for example, in Parnas's cart example, independent steering of the front wheels can force the cart to crash if the driver makes the wheels non-parallel while moving at high speed.

    b) Why is transparency useful. (0.5 points)

    Transparency allows the user to optimize performance by fine-tuning the use of the system. for example, in Parnas's cart example, independent steering of the front wheels allows the driver to turn about a center that is between the rear wheels, something that would be impossible with a steering linkage.