
148 Assembly Language Programming for the 68000 Family
We can sign-extend a byte to a word, or a word to a longword, using
the EXT instruction. The general form is:
EXT[.<size>] Dn
<size> = W, L
So, if we want to divide two signed words, we can use the following
instructions:
MOVE.W VAL1,D0
EXT.L DO
DIVS VAL2,D0
MOVE.W DO,RESULT
VAL1: DS.W 1
VAL2: DS.W 1
RESULT: DS.W 1
Before leaving division, there are a few more loose ends to clear up.
In signed division, the sign of the remainder is always the same as that of
the dividend. This means that if a negative number is divided by another
negative number, even though the quotient is positive, any remainder
will be negative. If we divide —23 by —10, the execution of the DIVS
instruction will yield a quotient of +2 and a remainder of —3.
In division, signed or unsigned, it is possible for the quotient to be
larger than the destination register can hold. This overflow condition,
always the case when we try to divide by zero, can occur for divisors
other than zero. The overflow bit, V, is used to detect this situation. The
result of such a division leaves the operands unchanged. A divide by zero
is a special case: a special exception condition is generated by an attempt
to divide by zero. This causes a trap to exception vector number 5. The
discussion of traps in the next chapter will show how this capability can
be utilized.
Decimal Arithmetic
Up to this point, all our numerical values have been represented as
binary data consisting of one or more bytes. Decimal numbers that are
input to a program must be converted to binary. Likewise, a decimal
number that is output must be converted from the internal binary repre
sentation. The INDEC and OUTDEC subroutines introduced in Chapter
4 perform these operations. As it turns out, the 68000 has a number of in
structions that allow the represention of decimal numbers internally in a
special way that makes the input and output conversions much simpler.
This representation is called binary coded decimal or BCD.
Kommentare zu diesen Handbüchern