Page 117 - Introduction to Microcontrollers Architecture, Programming, and Interfacing of The Motorola 68HC12
P. 117
94 Chapter 4 Assembly Language Programming
N, However, the contents of N are not assigned a value, in contrast to a directive DC
discussed later. The contents of N are undefined; they are the data that happen to be at
location $868 at the time the program is started. The DS directive does not do anything
to the value of a variable. We say the memory is allocated but is not initialized.
We have covered everything in the program of Figure 4.2 except the label LOOP,
which appears in the label field for a machine instruction, not assembler directives. When
a label is used with a machine instruction, it is given the value of the address of the first
byte of that instruction. Notice that the value of LOOP in Figure 4.3 is $8a4. This value
is also the address of the opcode byte of the EMAXD instruction. Thus the container
LOOP is the address $8A4, while the contents of LOOP are the bits of the opcode byte
for the EMAXD instruction.
Looking at other common assembler directives, the EQU directive (for EQUate)
assigns a specific value to a label. In Figure 4.2, the label N is given the value 3 by the
EQU directive. Generally, equates can be used to assign values to containers. Used this
way, they are like DS directives, where the programmer assigns an address to the
container rather than letting the assembler choose the value automatically. The EQU
directive enables you to control where variables are stored, as in hand coding, but allows
symbolic addresses to be used, as in assembly-language coding to improve readability,
We will find EQU directives useful in fixing addresses in monitor programs and in fixing
the addresses of I/O devices. These directives are often used to replace constants, to
improve readability, and to simplify the modification of programs. For example, the
instruction LDY #3 has been replaced, in Figure 4.2, by the lines
N: EQU 3
LDY #N
where the EQU directive is put near the top of the program. Using EQU directives makes
the program more readable and self-documenting, to an extent. It also makes it easier to
modify the program if a different count N is used. The value of the count is in the EQU
directive near the beginning of the program. If all changeable parts are kept in this area,
it is fairly easy to modify the program for different applications by rewriting the EQU
statements in this area. With an EQU directive, the label field cannot be empty, and the
operand field can be an expression as well as a number. As we shall see later, there is a
small restriction on the labels used in an expression of an EQU directive.
The DC (define constant) directive puts the values in the operand field into
successive memory locations starting with the next available memory location. DC. B
(define constant byte) allocates and initializes an 8-bit word for each item in the list in its
operand field. The suffix . B is the default; DC is the same as DC. B. A label, if used, is
assigned the address of the first value in the operand field. As an example
TABLE: DC.B 14,17,19,30 (4)
appearing in a program generates four consecutive bytes whose values are 14,17,19, and
30 and whose locations are at TABLE, TABLE+1, TABLE+2, and TABLE+3, as shown,
TABLE -> $OE
TABLE+1 -> $11
TABLE+2 -> $13
TABLE+3 -> $1E