150/317
6 - STMicroelectronics Programming Tools
ld ({VARIABLES-1},X), A
dec X; Next byte
jrne InitVar1
This routine uses the addresses of both segments, and the length of one of the segments, as
calculated by the expression
SIZE_RAM: EQU {* - VARIABLES}
where the * character means
“the current address in memory”.
Each start address is decreased by one because the structure of the loop is such that the
index goes from
SIZE_RAM
to
1
instead of going from
SIZE_RAM-1
to
0
. This simplifies the loop,
and makes it faster. Note the expression
{low SIZE_RAM}
that returns the low byte of the
value. The label
SIZE_RAM
being calculated from two relocatable values, its type is
WORD
. Since
the
X
register requires a byte value, the assembler would produce an error without this precau-
tion.
This way of initializing the RAM variables works well, and indeed is used in high-level lan-
guages. However, it suffers from a major drawback: you have to take care that the two related
segments in ROM and RA M have exactly the same structure, otherwise the wrong values
would go to the wrong variables.
To avoid this problem, the assembler provides a syntax that allows to you create two seg-
ments at once for these data, using this sequence of declarations:
data
segment byte at 80 'INITDATA'
VARIABLES:
EQU *
data
segment byte at E100 'ROM'
INITIAL_VALUES: EQU *
data
segment byte 'INITDATA>ROM'
d1.w:
DC.L $1234
d2:
DC.L 12
d3:
DC.L 131000
d4:
DC.W 50000
d5:
DC.B 50
SIZE_RAM:
EQU {* - VARIABLES}
Here, we declare a composite segment. Based on its composite name, the addresses of the
objects it contains are situated in the segment at the left of the “>” sign (here
INITDATA
), but
all the objects it contains are constant declarations that are put in ROM. What this syntax
does, is automatically create the RAM segment that contains the memory reservations (the
DS
statements in the example above) whose structure exa ctly matches that of the consta nt
values declaration. S o you don’t have to take care of making the two memory blocks con-
sistant; each constant you declare in the composite segment automatically has its storage cre-
ated in RAM. Provided that you pay attention to the proper declaration of the three labels that
Содержание 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 ...