Page 122 - Introduction to Microcontrollers Architecture, Programming, and Interfacing of The Motorola 68HC12
P. 122
4,4 Character String Operations 99
ORG $800
M: EQU 2
K: DS M
*
LDD K
ADDD #3
STD K
SWI
Figure 4.7. Program without Forward Reference
When the line K: DS M is assembled, the value of M is known. Usually, it is easy
to see which programs with forward referencing are assembled correctly just by
examining how the assembler works with that particular program. An "undefined
symbol" error occurs when K: DS M is assembled and M is not yet defined.
By now it should be obvious that for correct assembly a label can appear only once
in the label field. Multiple occurrences are given an error message. (However, in the next
chapter we will see a SET directive in which labels can be redefined.)
Looking at the instructions
BNE JUMP
JUMP: ADDA M
in a particular program, one might wonder what happens if the location JUMP is more
than 127 bytes below the BNE instruction. Does the assembler still proceed, not
knowing location JUMP, and then give an error message when it finds that JUMP is
beyond the 127-byte range on the second pass? Or does it immediately put in the long
branch equivalent
LBNE JUMP
and determine the right 2-byte relative address on the second pass? It might seem
reasonable to expect the latter, but the first possibility has been chosen because the latter
choice would force all forward branches to be long branches. In other words, the
assembler leaves the burden of picking the shortest branching instruction to the
programmer. For exactly the same reason, the programmer will want to use the
inequality sign "<" with forward references for relative addressing used with other
instructions. As an example, you should use LDAA <L,PCR instead of LDAA
L, PCR when the effective address L is a forward reference which is within 127 bytes of
the next byte after the LDAA instruction. Otherwise, the assembler will choose the 2-
byte relative offset option.
4.4 Character String Operations
Before we look into an assembler, we will study some operations that copy, search, and
manipulate character strings. These operations make it easier to understand how an
assembler works, which we cover in the next section. They also provide an opportunity
to show how assembly-language source code is written, in order to simplify your