Hardware Reference
In-Depth Information
Source
file 1
Object
module 1
Executable
binary
program
Source
file 2
Object
module 2
Translator
Linker
Source
file 3
Object
module 3
Figure 7-12. Generation of an executable binary program from a collection of
independently translated source procedures requires using a linker.
statement in one source procedure would require all the procedures to be retran-
slated.
If the separate-object-module technique of Fig. 7-12 is used, it is only neces-
sary to retranslate the modified procedure and not the unchanged ones, although it
is necessary to relink all the object modules again. Linking is usually much faster
than translating, however; thus the two-step process of translating and linking can
save a great deal of time during the development of a program. This gain is espe-
cially important for programs with hundreds or thousands of modules.
7.4.1 Tasks Performed by the Linker
At the start of pass one of the assembly process, the instruction location count-
er is set to 0. This step is equivalent to assuming that the object module will be lo-
cated at (virtual) address 0 during execution. Figure 7-13 shows four object mod-
ules for a generic machine. In this example, each module begins with a BRANCH
instruction to a MOVE instruction within the module.
In order to run the program, the linker brings the object modules from the disk
into main memory to form the image of the executable binary program, as shown
in Fig. 7-14(a). The idea is to make an exact image of the executable program's
virtual address space inside the linker and position all the object modules at their
correct locations. If there is not enough (virtual) memory to form the image, a disk
file can be used. Typically, a small section of memory starting at address zero is
used for interrupt vectors, communication with the operating system, catching
uninitialized pointers, or other purposes, so programs often start above 0. In this
figure we have (arbitrarily) started programs at address 100.
The program of Fig. 7-14(a), although loaded into the image of the executable
binary file, is not yet ready for execution. Consider what would happen if execu-
tion began with the instruction at the beginning of module A . The program would
not branch to the MOVE instruction as it should, because that instruction is now at
 
 
Search WWH ::




Custom Search