
148/317
6 - STMicroelectronics Programming Tools
.LongValue
DS.L 1
; a long number
data1 SEGMENT byte common 'DATA'
.Byte1
DS.B 1
; first byte of the long value
.Byte2
DS.B 1
; second one
.Byte3
DS.B 1
; third one
.Byte4
DS.B 1
; fourth one
With this declaration, the four bytes
Byte1
to
Byte4
exactly overlap those of the value
Long-
Value
. It is then possible to access this storage either as a long value, or as four individual
bytes.
Obviously, the
common
attribute makes sense only for data storage.
6.1.5.5 Initialization of variables at power-on
The variables used in a program, being both read from and written to, have to be located in
RAM. This type of memory keeps the data as long as the power is applied; the contents of the
RAM are undefined at power on.
To start properly, a program must be able to rely on the values of the variables. It is good prac-
tice to design a program so that the default, or initial, or empty state of all variables is zero.
This means you initialize the RAM using a loop that sets all bytes in the RAM area to zero. This
is very easy to do, and for security, you should do it in all your programs .
There are variables, however, that must have an initial value other than zero. You must supply
values for them, and ensure that all the variables are initialized, each with its own value, be-
fore the main work of the program is activated.
This can be done using a string of load instructions that writes all the variables that need be in-
itialized, as in the example:
InitialValue1EQU 100
InitialValue2EQU 12
InitialValue3EQU -2
LD A, #InitialValue1
LD Variable1, A
LD A, #InitialValue2
LD Variable2, A
LD A, #InitialValue3
LD Variable3, A
etc.
Obviously, this method is cumbersome, a nd prone to having variables forgotten and left
floating. This is a very dangerous situation, because the value of a memory byte at power-on
is undetermined but often reproducible for a given chip. For example, by an unlucky chance an
uninitialized variable could have a value that does not prevent the program from working cor-