กฐ Note : Solutions proceeding with * are for reference only
2. Suppose that a computer primarily uses direct addressing, but has several different
instruction formats. What problems does this create for the relocation-bit approach to
program relocation? How might these problems be solved?
The bit-mask approach described in the text will not work in this case,
because it defines one relocation bit for each 3-byte field of the object program.
Instructions that may vary in length will not pack neatly into these 3-byte fields.
Even if all the instruction formats are 3 bytes in length, the subfields that require
modification may be in different locations within the instruction.
10. Suppose that you have been given the task of writing an "unloader" - that is,
a piece of software that can take the image of a program that has geen loaded and write
out an object program that could later be loaded and executed. The computer system uses
a relocating loader, so the object program you produce must be capable of being loaded
at a location in memory that is different from where your unloader took it. What problems
do you see that would prevent you from accomplishing this task?
The significant problem in writing the unloader is that there is no way to determine
which parts the object program have been relocated, that is there is no way to tell
data items that represent address (required relocation) from those that represent other
types of data
11. Suppose that you are given two images of a program as it would appear after loading
at two different locations in memory. Assume that the images represent the program after
it is loaded and relocated, but before any imformation could be used to accomplish the
"unloading" task mentioned in Exercise 10.
With this additional information, the "unloading" task becomes relatively easy. Any
differences in the two images must be due to relocation operations. by knowing the
starting address of either image, the unloader could compute the "un-relocated" value
of each part of the object program that has been modified. Each of these parts would
then be flagged as a relocatable value in the output from the unloader.
13. Suggest a design for a one-pass linking loder. What restrictions (if any) would be
required? What would be the advantages and disadvantages of such a one-pass loader?
1) The main problem faced by a onepass linking loader would be forward references during
linking that could be handled by a technique similar to that described for a one-pass
assembler (see Section 2.4.2).
2) Advantaes : Save an extra pass over object programs.
3) Disadvantages : require more momory.
3. Suppose that the loader is to produce a listing that shows not only the addresses
assigned to external symbols, but also the cross-references between control sections
in the program being loaded. What information might be useful in such a listing? Briefly
describe how you might implement this feature and include a description of any data
One way is to build a linked list attached to the entry for each symbol in the external
symbol table. A node is created in this linked list each time a Modification record in
another control section refers to that symbol the node contains the address of the location
that is being modified. at the end of Pass 2, the external symbol table and associated
linked lists contain all the information that is needed to produce the cross-reference.
3. Consider the following possibilities for the storage, linking, and execution of a
a) Store the source program only; reassemble the program and use a linking loader
each time it is to be executed.
b) Store the source and object versiions of the program; use a linking loader each
time the program is to executed.
c) Store the source program and the linked version with external references to library
subroutines left unresolved. Use a linking loader each time the program is to be executed.
d) Store the source program and the linked version with all external references
resolved. Use a relocating loader each time the program is to be executed.
e) Store the source program and the linked version with all external references
resolved and all relocation performed. Use an absolute loader each time the program is to
Under what conditions might each of these approaches be appropriate? Assume that no
changes are required in the source progam from one execution to the next.
Alternative (a) requires least storage space but must be reassembled, linked and relocated
for each execution; Alternative (d) and (e) require little overhead to run.
The choice of Alternatives for a given situation depends on how often the program is to be
run. The decision is also influenced by the relative importance of disk space and CPU time
on a particular system - that is, which of these is the more critical resource to conserve.
Other factors to consider include how much linking needs to be done, how many library
subroutines are sued and how large they are, and whether or not the load address for the
program is predictible.
4. Dynamic linking, as described in Section 3.4.2, works for transfers of control only.
How could the implementation be extended so that data references could also cause dynamic
loading to occur?
1) A data reference table must be build in memory to keep symbolic name of data and
2) Instead of transferring control to called subroutines, Dynamic loader look sup the data
reference table to find the data value, then fill the value in the subfield of the original
insturction. At last, dynamic loader returns control to calling program.