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