
Conditional and Arithmetic Instructions 59
destination register. For example, the addition of the following unsigned
8-bit binary numbers results in a sum that will not fit in an 8-bit destination
(register or memory byte).
11101001
+ 10110111
110100000
The carry of a bit from the most significant (high-order) bit position has
no place to go. Actually, this event causes the carry bit (C) to be set. If
there was no carry, the carry bit would be reset.
In order to determine if the result of an unsigned addition is valid, the
setting of the carry bit must somehow be tested. Fortunately, the 68000
provides a group of instructions that allow the testing of each of the bits
of the CCR individually and in various combinations. These instructions
all have the form of a
conditional branch. A conditional branch is similar
to a JMP instruction except that for the former the jump is not taken
unless a particular condition is true. This condition corresponds to the
value or values of one or more of the bits of the CCR. If the branch is
not taken then the next sequential instruction is executed. The branch on
carry set instruction, BCS, provides a conditional branch based on the
setting of the carry bit. If the carry bit is set (binary one) then the branch
is taken. The following program illustrates the use of the BCS instruction
to validate the result of an unsigned addition.
HOVB.L NUH1/D0
ADD.L NUM2,D0
BCS INVALID
RESULT IS OK
INVALID: . RESULT EXCEEDS REGISTER SIZE
The label used with the BCS instruction, and with all the conditional
branches, must be to a location that is within approximately plus-or-minus
32,768 bytes of the location of the instruction itself. As mentioned in
Chapter 4, this restriction is also present with the DBRA instruction. It is
usually difficult to tell how many instructions will represent 32,768 bytes.
It is best to let the assembler do the work for you. But let’s suppose
that you really must perform a conditional branch to a location that is
greater than plus or minus 32,768 bytes. What can you do to get around
this problem? One simple solution is to perform the conditional branch
to a JMP instruction that is “close” to the conditional branch and then
Kommentare zu diesen Handbüchern