
146/317
6 - STMicroelectronics Programming Tools
ld a, #cpudiv2
ld miscr, a
; fq 8MHz /2 = CPU clock = 4MHz
etc.
For a block of code, the
SEGMENT
directive may only occur after either an unconditional jump or
a return instruction. This is because two segments are independent objects, that can be put in
different places in memory. In other words, two segments that are consecutive in the source
file may be put in non-consecutive places in memory. The only condition that allows for this is
that the last instruction before the
END
statement or the
SEGMENT
pseudo-op must be a jump,
that will be adjusted at link time.
Dividing a program into segments is not just done for fun; it must be to make the allocation of
the program in memory easier. You should only divide the source code where this is neces-
sary; you should not feel you have to cut your program into slices just to make it look impres-
sive.
6.1.5.4 Segment allocation
When all the source files are assembled, each segment in the object file starts at address
zero, except the segments with the combine option
AT
(see above) that start at the specified
address.
Such segments are called absolute segments. They apply a constraint to the linker, since the
linker is not free to place them anywhere there is room, but at a precise address. This can lead
to conflicts, if two absolute segments overlap by mistake. This is why absolute segments must
only be used where necessary.
There are two cases where this is necessary: at the start of a class, and for input-output reg-
isters.
As shown in the previous paragraph, the notion of class is intended to distinguish the main
areas in addressable space. For example, the ST72251 has an input-output area from 0 to
7Fh; a page zero RAM area from 80 to 0FFh; a RAM area from 100h to 13Fh; a STACK area
of 140h to 17Fh; and a ROM area from 0E000h to 0FFFFh. The start (and perhaps the end)
address must be specified when the first segment of that class is introduced, using a state-
ment like:
.Program
SEGMENT byte AT 0E000 'ROM'
Please note that the value after
AT
must be hexadecimal and that any radix, prefix or suffix is
forbidden. This statement declares that the
ROM
class starts at 0E000h as does the segment
Program
that belongs to that class.