EasyManua.ls Logo

ST ST7 - Page 149

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...
149/317
6 - STMicroelectronics Programming Tools
rectly during debugging; but when the product is put into production or, even worse, later at
the customer, the byte could then have a value that makes the program behave wrongly. The
consequences would then be very serious.
To provide a more convenient way of initializing all the variables that need to be, and to guar-
antee that they are all initialized without exception, the assembler has a feature that we shall
describe here.
The idea is to put all variables that must be initialized (with values other than zero, since all
others will be zeroed by a clearing loop as said above), in a single segment in RAM. All varia-
bles need not be declared in the same module, provided they use the same segment name.
Then, data constants are defined in another segment in ROM, in the same order and with the
same size as those in RAM. This looks like the following:
The segment in RAM is declared as a series of DS statements since these are storage for var-
iables:
data segment 'INITDATA'
VARIABLES: EQU *
d1.w: DS.L
d2: DS.L
d3: DS.L
d4: DS.W
d5: DS.B
SIZE_RAM: EQU {* - VARIABLES}
The segment in ROM is declared as a series of DC statements, that give the initial values for
the corresponding variables:
data segment 'ROM'
INITIAL_VALUES: EQU *
cd1.w: DC.L $1234
cd2: DC.L 12
cd3: DC.L 131000
cd4: DC.W 50000
cd5: DC.B 50
Based on this, all the variables can then be initialized by inserting a loop, at the beginning of
the code, that copies every ROM byte to the corresponding RAM byte:
InitVariables: ld X, #{low SIZE_RAM}; Start from end of block to copy
InitVar1: ld A, ({INITIAL_VALUES-1},X) ; Copy one byte

Table of Contents

Related product manuals