143/317
6 - STMicroelectronics Programming Tools
the way that these functions communicate with each other has been defined, and that some
common writing rules have been set out.
Since the program is divided into several files, a problem arises because each programmer
does not know at which address his program should start. Supposing a colleague did as-
semble his own work, and that he told you the last address used by his piece of program, you
would also have to know the address of each of the routines of the other file that you have to
call from your own file.
This is why the concept of relocation has been created.
Relocation means that each programmer writes his own code without bothering about the lo-
cation of his part of the program in memory. The addresses of the objects (data and routines)
that he uses in his piece of code are left open like a plane return ticket. Such unknown ad-
dresses are just declared External, that is, not known at this time. Then, the programmer can
assemble his own piece of code. All external references are given null addresses; all labels
and data defined in that piece of code are given increasing addresses from zero.
When all the pieces have been assembled, all the object files (in machine language) are fed to
yet another translator program called a Linker. This program puts all the pieces together,
placing the pieces of code one after the other in memory, and does the same for the variables
defined throughout the files. Then, all external references made in each piece are adjusted to
match the true addresses of the referenced objects.
The object files fed to the linker, having no absolute memory addresses, are called relocatable
objects, which means that they can later be placed in memory at any address. The linker pro-
duces two files. The first one is the complete program, in machine language, with all the ad-
dresses fixed. This file is called the absolute object file, as opposed to the relocatable files that
were input. The second file is a text file, called the Map File, that indicates start address of
each piece of program, and the addresses of all labels and data used across modules. This
file is helpful for debugging, to know exactly where a certain object is in memory.
6.1.5.2 Segment definition
The linker is the translator that places the various program pieces in the memory map. Though
a particular sequence of instructions, or data storage area is not influenced by the absolute
position it occupies in memory, the linker has to apply some memory allocation rules for the
following reasons:
The memory map is typically divided in four classes: Read Only Memory, Read-W rite
Memory, Input-output, and non-existant.
Each of these classes have a definite position in the addressable space which is fixed by
hardware.