
44 Assembly Language Programming for the 68000 Family
Unfortunately these two instructions do not accomplish the desired result.
The first MOVE instruction has destroyed the contents of register Dl.
This is the value that must be placed in register DO by the second MOVE.
This second MOVE will erroneously result in the value of register DO
not being changed. To perform the swap correctly, a temporary storage
location is needed. This can be a register or a memory variable. The
instructions
MOVE.L D0,D2
MOVE.L D1,D0
MOVE.L D2,D1
will perform the swap correctly. However, register D2 has thus been
used as a temporary storage location, and we may not wish to destroy its
contents either. The use of a memory location as a temporary frees the
registers but will cause the instructions to execute at a slower speed.
The 68000 EXG (exchange registers) is our salvation. We can swap
between any of the 16 registers but not between two memory locations
or between a memory location and a register. We can write the above
program as:
EXG.L D0,D1
The EXG instruction will operate on bytes, words, or longwords when
the proper instruction extension is specified. Of course, we can’t swap
two constants or a constant and anything else.
I didn’t mention it above, but a value cannot be moved into an address
register using the MOVE instruction; the MOVE A instruction must be
used. Its general form is
MOVEAI.<size>] <ea>,An
<size> = W or L
Any operations involving an address register as a destination can only use
the word or longword forms. In the case of a word form, the word is
sign-extended to 32 bits before being used. The entire address register is
always used.
Addition and Subtraction
While moving values from one register to another is an important
part of assembly language programming, arithmetic operations such as
addition and subtraction will allow you to start writing programs that
Kommentare zu diesen Handbüchern