Motorola M68000 User's Guide Page 159

  • Download
  • Add to my manuals
  • Print
  • Page
    / 256
  • Table of contents
  • BOOKMARKS
  • Rated. / 5. Based on customer reviews
Page view 158
Advanced Arithmetic 145
ADDX.L -(A0),-(A1)
RTS
Moving the constant 4 into the CCR will clear all the bits except for the
Z condition. Remember, when the Z bit is set, there is a zero value. I will
get back to this point shortly. Notice that the subroutine first adjusts the
addresses to point to the longword just beyond the number, and then uses
address register indirect with predecrement addressing for the additions.
The values in AO and A1 will be restored to their original values when
the subroutine returns. This subroutine could be called as follows:
LEA A,AO
LEA B,A1
JSR DBADD
This call would result in adding double-precision value A to double
precision value B.
I mentioned that there is a reason to make sure the Z condition is set
in the CCR before starting a multiple precision calculation. The reason is
that we may want to test the result of our calculation to determine if it is
zero. Since this is a multiple precision calculation, what we really require
is that all the intermediate results are zero, as well as the final addition or
subtraction. ADDX, SUBX, and NEGX all have an interesting property
when it comes to the Z condition: the Z condition is cleared if a result is
non-zero, and unchanged otherwise. This means that once it is cleared it
will remain cleared. This indicates a non-zero result for our calculation.
A BEQ or BNE instruction can then be used to conditionally branch,
depending on the state of the Z bit.
The NEGX instruction is used to negate (subtract from zero) a
multiple precision value. The following instructions will negate the
double-precision longword in location COUNT:
MOVE.W #4,CCR
NEGX.L COUNT+4
NEGX.L COUNT
Notice that the Z bit must be set prior to execution of the first NEGX.
Address register indirect with predecrement addressing can also be used:
LEA COUNT+8/AO
MOVE.W #4/CCR
NEGX.L -(AO)
NEGX.L -(AO)
Multiplication and Division
The 68000 has two multiply and two divide instructions. One pair of
multiply and divide instructions is used for unsigned values and the other
Page view 158
1 2 ... 154 155 156 157 158 159 160 161 162 163 164 ... 255 256

Comments to this Manuals

No comments