147/317
6 - STMicroelectronics Programming Tools
All segments found later in the program with the same class name will be allocated after this
one. To make this work, the module that defines the classes has to be first in the object file list
when you invoke the linker.
If two seg ments of the sam e class have the same name, they are put at successive ad-
dresses, in the order they arrive in the list of object files. When all the segments with the same
name have been placed, then the next name is processed and all segments of that name in
the same class are laid out sequentially in memory. This process continues until all the seg-
ments have been allocated.
If a segment and/or a class have been given stringent requirement in terms of addressing
(both a start address and an end address are given), and if all segments in the list do not fit in
that space, the linker generates an error message.
As you can see, the process of allocating segments is fairly straightforward. The linker looks
in the class definitions, then in each class for absolute segment definitions; these segments
are allocated at the specified addresses. Then, all other segments are allocated in sequence,
starting in each class with the next segment of the same name, then with the first segment of
the next name, and so on until all the segments have been allocated. The result is that objects
that are in sequence in a source text may be dispersed in the memory; and on the other hand,
objects that are scattered thoughout the various modules may be contiguous in memory, if
they belong to segments defined in this way.
This mechanism is slightly altered when a segment is specified with the
common
combine op-
tion. As said above, all segments that have the same name and the same class and that have
the
common
option share the same memory area. This area will have the size of the largest
segment of that group. This leads to having objects that overlap in memory. While the main
task of the linker is to avoid this situation, the programmer may want some objects to overlap
on purpose. There may be two reasons for this:
To save memory. If two or more routines each use temporary variables that are not
preserved on exit, and if these routines do not call each other, it is possible to save memory
by overlapping the local variables of these routines.
To allow data to change its type. In many circumstances, it is necessary to consider some
data in various ways at the same time. For example, a long variable (double word) may need
to be considered also as four successive one-byte variables. This corresponds to the notion
of Conditional Records In Pascal or Unions in C. This can be done by defining two sets of
data and giving the common attribute to their segments, as in the following example:
data1
SEGMENT byte common 'DATA'
Содержание ST7 Series
Страница 1: ...ST7 8 BIT MCU FAMILY USER GUIDE JANUARY 1999 1 ...
Страница 238: ...238 317 8 C Language and the C Compiler 08 Burn bmp Then use the EPROMer programmer software as described in Chapter 7 ...
Страница 289: ...289 317 10 Second Application a Sailing Computer 10 befor Bs Rw Vw VMG AlphaR AlphaV Before the wind ...