Assignment 1, Solutions
Part of
the homework for 22C:112, Fall 2012
|
No solution offered.
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.
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.
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.