
78 Assembly Language Programming for the 68000 Family
LOOPs
PINI
LEA
MOVE.B
BEQ
JSR
BRA
STR,A0
(A0)+,D0
PINI
PUTC
LOOP
GET ADDRESS OF STRING
GET NEXT CHARACTER
DONE?
NO, OUTPUT THE CHARACTER
BACK FOR MORE
DONE
Another useful example is in moving a string from one place to
another. This same technique can be used to move one area of memory
to another. Here, address register indirect with postincrement addressing
is used for both the source and destination operands. We will move string
SI to string S2. S2 must be large enough to contain SI.
LEA SI,AO AO -> SOURCE
LEA S2,A0 A1 -> DESTINATION
LOOP: MOVE.B (A0)+,(A1) + MOVE A BYTE
BNE LOOP LOOP TILL ZERO BYTE
It may come as a shock that the loop consists of just one instruction, but
that is all it takes. One nice feature of the 68000 instruction set is that all
condition codes except X are set for a MOVE instruction. This allows us
to perform the conditional branch immediately following the MOVE.
As a final example of the use of this addressing mode, here is a simple
program to compare two strings.
LEA
SI,AO
A0 -> SI
LEA
S2,A1
Al -> S2
LOOP:
TST.B
(A0)
NULL?
BEQ
LAST
YES
CMPM.B
(A0) +, (Al) +
NO, COMPARE BYTES
BEQ
LOOP
CONTINUE WHILK =
BRA
DIFF
NOT =
LAST:
TST.B
(Al)
NULL?
BEQ
SAME
DIFF:
•
HERE WHEN STRINGS
SAME:
#
HERE WHEN STRINGS
The CMPM instruction is a special version of the compare instruction
that must be used when both the operands are register indirect with
postincrement addressing. We end up at label DIFF if the strings are
different and at label SAME if they are the same. The first TST.B is
needed to ensure that we don’t continue to compare memory locations
beyond the strings. The TST.B at LAST is needed to make sure that the
Kommentare zu diesen Handbüchern