Motorola M68000 Betriebsanweisung Seite 165

  • Herunterladen
  • Zu meinen Handbüchern hinzufügen
  • Drucken
  • Seite
    / 256
  • Inhaltsverzeichnis
  • LESEZEICHEN
  • Bewertet. / 5. Basierend auf Kundenbewertungen
Seitenansicht 164
Advanced Arithmetic 151
JSR GETC
GET A CHARCTER
SOB.B # ' 0'/DO
MAKE INTO DECIMAL
LSL.B #4,DO
SHIFT INTO HIGH NIBBLE
MOVE.L DO/-(SP) SAVE DO
JSR
GETC
GET A CHARACTER
SUB.B #'0',D0 MAKE INTO DECIMAL
ADD.L
(SP)+/DO
ADD HIGH NIBBLE
This routine does not have any error checking, so if a character other
than 0 through 9 is entered, an error will result. It is straightforward to
add instructions to test the range of each digit as it enters to ensure that
it is valid.
BCD numbers are unsigned. The high-order bit of the high-order byte
is not interpreted as a sign bit. How then can we represent signed BCD
numbers? One method is to reserve a single byte as the sign byte. We can
store the ASCII character + or in this sign byte and the absolute value
of the BCD number in the remaining bytes. Unfortunately we can’t just
add or subtract these numbers. The sign byte can’t enter into the actual
arithmetic. Before using a signed BCD number, the sign byte must first
be checked. If the BCD number is negative, tens complement must first
be taken prior to its use in a calculation. The tens complement is used
in a manner very similar to the twos complement of binary numbers.
The ten’s complement is the nines complement plus one. To compute
the nines complement, simply subtract each BCD digit from the number
nine, then add in the one. For example: the nines complement of the
four-digit BCD number 1234 is 8765. The ten’s complement is then 8766.
This adjusted number used in a calculation will now give a correct result.
From the above example, the number 8766 can be thought of as a negative
1234. If we add a positive 1234, we should get a result of zero. This is
true if we ignore the carry.
8766 -1234
1234 +1234
10000 0000
The same rules apply as for two’s complement binary numbers. Unfor
tunately, we must keep track of the signs separately, or use more com
plicated schemes. One such scheme would be to use the high-order digit
for the sign, with a positive number being represented by a 0 and a neg
ative number by a 9. This is equivalent to the use of the high-order bit
as a sign bit with twos complement binary numbers.
The NBCD instruction is used to compute the ten’s complement. The
action of this instruction is to perform the ten’s complement of a pair
of BCD bytes and then subtract the extend bit. If the extend bit is 0,
then the result is truly the tens complement. If the extend bit is a 1, then
Seitenansicht 164
1 2 ... 160 161 162 163 164 165 166 167 168 169 170 ... 255 256

Kommentare zu diesen Handbüchern

Keine Kommentare