
Advanced Arithmetic 143
the high-order longwords. The carry condition, C, is set/reset as a result
of our first addition. All we have to do is somehow add the carry bit to
our high-order addition. But wait, the MOVE instruction used to save the
low-order result will clear the carry bit. In fact, we can’t even get a hold
of the high-order longword without destroying the carry bit. The 68000
designers anticipated this problem. They provided the extend condition
or X bit in the condition code register. This bit is always a copy of the
carry bit for arithmetic operations. However, it is not cleared, or modified
in any way, as a result of a MOVE instruction.
The ADDX, SUBX and NEGX instructions are provided to utilize the
value in the extend bit. Their general forms are:
ADDX[.<size>] Dy,Dx
ADDXl.<size>] -(Ay),-(Ax)
SUBXt.<size>] Dy,Dx
SUBX[.<size>] -(Ay),-(Ax)
NEGX[.<size>] <ea>
<size> = B, W, L
They work like ADD, SUB and NEG, except that the extend bit is
factored into the calculation, and the addressing modes are restricted
to those shown. For ADDX, the extend bit is added to the result; for
SUBX and NEGX it is subtracted—this is equivalent to a borrow for a
subtraction. The ADDX, SUBX, and NEGX instructions all set the C and
X bits after a calculation. The remaining instructions needed to complete
the calculation are:
MOVE.L A,DO
MOVE.L B,D1
ADDX.L D1,D0
MOVE.L D0,C
The above procedure can be used to add numbers of any precision. An
ADD instruction is used for the lowest order byte, word, or longword,
and all other additions are performed with the ADDX instruction.
Multiple precision subtraction can be performed in a similar manner,
using the SUB instruction and the subtract-with-extend instruction, SUBX.
The following instructions will subtract the three-byte variable A from B
and store the result in C:
MOVE.B B+2,D0
SUB.B A+2,D0
MOVE.B DO,C+2
MOVE.B B+l,D0
MOVE.B A+l,D1
SUBX.B D1,D0
MOVE.B D0,C+1
MOVE.B B,D0
Kommentare zu diesen Handbüchern