Page 113 - Introduction to Microcontrollers Architecture, Programming, and Interfacing of The Motorola 68HC12
P. 113
90 Chapter 4 Assembly Language Programming
ORG $868
N: EQU 3
RESULT: DS.B 2
Z; DS.B 50
*
LDX #Z ; Point X to the vector Z
LDY #N ; get count
LDD 2 , X+ ; Z(0) into D
LOOP: EMAXD 2 , X+ ; D- Z(i)
DBNE Y,LOOP ; Another number?
STD RESULT ; Store result
BGND ; Halt
Figure 4.2. Assembler Source Code for the Program MAX
Program segment (3) is clearer than program segment (2). An assembly-language source
code for the program in Figure 4.1 is shown in Figure 4.2.
Putting this assembly-language program into the assembler yields the output listing
shown in Figure 4.3. Although some new mnemonics have crept in, we can nevertheless
see that we do not have to refer to actual addresses, only labels. We can see that we have
not had to calculate relative offsets for the branching instructions, and we have not had to
find memory locations or machine code. We now look into some of the details.
An assembly-language source statement takes the following form, where the fields,
which are groups of consecutive characters, are separated by one or more one spaces:
Label Field Operation Field Operand Field Comment
The label field and the comment field may be empty and, depending on the operation,
the operand field may be empty.
Label Field
A label (or symbolic address), if present, must have a letter as the first character and
continue with letters, numbers, periods, or underscores. If a line's first character is an
asterisk (*) or semicolon (;), the whole line is treated as a comment. Finally, labels that
are identical to register names are not allowed (e.g., A, B, CC, X, Y, S, SP, PC, D, and
PCR). The label ends in a colon (:). In some assemblers the colon is mandatory after a
label; in some it cannot be used; and in others it is optional.
Operation Field
Except for comment lines, the operation field must consist of an instruction mnemonic
or assembler directive (more about these later). The mnemonic must be written with no
spaces: CLRA, TSTB, ADDD, and so on.
Operand Field
The operand field contains the addressing information for the instruction. Although
numbers can be used to specify addresses, you will find that symbolic addresses are
generally much easier to use in the operand field. For example, using the symbolic