User manual

ST assembler ST Assembler-Linker
26/89 Doc ID 11392 Rev 4
4.4 Segmentation
4.4.1 Segments explained
Segments are very important. You have to understand segments before you can use the
assembler. Take the time to understand them now and you will save yourself a lot of puzzling
later.
Segmentation is a way of 'naming' areas of your code and making sure that the linker
collates areas of the same name together in the same memory area, whatever the order of
the segments in the object files. Up to 128 different segments may be defined in each
module. The segment directive itself has four arguments, separated by spaces:
[<name>] SEGMENT [<align>] [<combine>] '<class>' [cod]
For example:
FILE1:
st7/
BYTES
segment byte at: 80-FF ‘RAM0’
counter.b ds.b ; loop counter
address.b ds.w ; address storage
ds.b 15 ; stack allocation
stack ds.b ; stack grows downward
segment byte at: E000-FFFF ‘eprom’
ld A,#stack
ld S,A ; init stack pointer
end
FILE2:
st7/
segment ‘RAM0’
serialtemp ds.b
serialcou ds.b
WORDS
segment ‘eprom’
serial_in ld A,#0
end
In the preceding example, FILE1 and FILE2 are two separate modules belonging to the
same program. FILE1 introduces two classes: 'RAM0' and 'eprom'. The class-names
may be any names you choose up to 30 characters.
The first time a class is used, introduced, you have to declare the default alignment, the start
and the end addresses of the class, and of course, the name of the class.
Users generally specify a new class for each 'area' of their target system.
In the examples above, the user has one class for the 128 bytes of on-chip RAM from 0080
to 00FF ('RAM0') and another for the 'eprom'.
The code is stored from E000 to FFFF ('eprom'). You have to supply all this information
the very first time you use a new class, otherwise only the class-name is necessary, as in
FILE2.