User manual

Linker ST Assembler-Linker
40/89 Doc ID 11392 Rev 4
5.4 Linking in detail
5.4.1 PUBLICs and EXTERNs
All labels declared external in the modules being linked together must have a corresponding
PUBLIC definition in another module. If it does not, it may be an error. Similarly, there must
only be one PUBLIC definition of a given label.
The bulk of the linker's job is filling those relative or external blanks left by the assembler in
the .OBJ files; to a lesser extent, it also handles special functions such as DATE or SKIP
directives. Equally important, it has to collate together and allocate addresses to segments.
5.4.2 Segments in the linker
A typical system may look like the diagram alongside: a good candidate for four different
segments, perhaps named RAM0, RAM1, EPROM and ROM.
If the reset and interrupt vectors live at the end of the map, perhaps from FFEE-FFFF then
we might mark a fifth segment called vectors at those addresses and truncate ROM to end
at FFED; that way the linker will warn us if ROM has so much code in it that it overflows into
where the vectors live. These classes would be introduced as follows:
segment byte at: 0-FF 'RAM0'
segment byte at: 100-027F 'RAM1'
segment byte at: 8000-BFFF 'EPROM'
segment byte at: C000-FFDF 'ROM'
segment byte at: FFE0-FFFF 'VECTORS'
After their full introduction that needs only be done once in the whole program, the rest of
the program can refer to the classes just by giving the class names in quotes, for example:
If this example followed immediately after the class instruction the 'xtemp' label would be
given the value 0, time would be given 2 and hex C000. If, however, the code was several
modules away from the introduction with segments of the classes 'RAM0' or 'ROM', then the
value allocated to all the labels will depend on how much space was used up by those
modules. The linker takes care of all this allocation. This is the way the linker handles the
problems of relocatability; keep in mind that this link system is going to have to handle
compiled code from high level languages and you will perhaps begin to understand why
things have to be generalized so much.
So far the segments we have looked at have had no <name> field, or, more accurately, they
all had a null <name> field. You can ensure that related segments of the same class,
perhaps scattered all over your modules with segments of the same class are collated
together in a contiguous area of the class memory by giving them the same name.
segment 'RAM0'
xtemp ds.w ; temp storage for X register
time ds.b ; timer count index
segment 'ROM'
hex ld A,#1
add A,#10
nop