EasyManua.ls Logo

ST ST7 - Page 150

ST ST7
317 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
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 withoutthis 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 RAM 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 exactly matches that of the constant
values declaration. So 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

Table of Contents

Related product manuals