Assignment 1, Solutions

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

  1. What is your E-mail address? (probably firstname-lastname@uiowa.edu, but this does not always work, for example, douglas-jones@uiowa.edu is not teaching this course.)

    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 hold each of the following: (0.2 points each)

    a) An integer global variable.

    The static segment. All globals go there.

    b) An floating point local variable.

    The stack segment. All locals go there.

    c) A string constant.

    On machines that permit mixing code and constant data, string constants may be embedded in the code segment. On machines where the MMU forces code-only code segments, string constants may be in the static segment. Either answer was accepted here.

    d) A method of a class.

    The method is code, so it goes in the code segment.

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

    The method table is constant data (pointers to the code of each method), so as with string constants, it goes in either the static or code segments, depending on the constraints imposed by the MMU.

  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) Storing to a statically allocated global integer.

    Absolute addressing.

    b) A conditional branch to another instruction in this subroutine.

    PC-relative addressing.

    c) Loading a local character.

    SP-relative addressing; that is, indexed off of the stack pointer.

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

    Indexed addressing using a register pointing to the object as a whole.

    e) Calling a separately compiled subroutine resolved by the linker.

    Absolute addressing.

    Homework questions based on new material

  4. Background: Read the article by D.L. Parnas on the concept of transparency cited in lecture 1 (either the tech report or the CACM article -- they are substantially the same; access to the CACM article is free from any on campus computer). A question: Parnas uses a vehicle to illustrate the risks and benefits of transparency. What are the instructions that matter to his example in the "lower-level virtual machine" of this example, and what are the corresponding non-transparent instructions in the upper level? (1.0 points)

    The low-level virtual machine involves separate controls for each front wheel, specifically, 2 ropes per wheel, one to turn the wheel left and one to turn the wheel right. This offers flexibility but is dangerous.

    The high-level virtual machine has a steering wheel that offers coordinated control of both front wheels. This limits flexibility but offers safety and ease of use.