Re: A85: Mathematical routines
[Prev][Next][Index][Thread]
Re: A85: Mathematical routines
On Mon, 17 Nov 1997 22:33:17 GMT richardlewis@cedarcity.net
(Richardlewis) writes:
...
>Does anybody know what a BCD number is? I know
>the processor can handle them, but what are they?
BCD stands for Binary Coded Decimal. It is easily converted to and from
ASCII, and can store very large numbers containing up to 20 digits.
There are two main variations of BCD numbers: Packed BCD numbers store 2
digits per byte, usually with individual digits in high-to-low order, but
with the bytes in low-to-high order. Unpacked BCD numbers store 1 digit
per byte, ordering the bytes in either low-to-high or high-to-low
sequence.
Packed BCD numbers are probably the most common, storing 2 digits in each
byte, 1 digit in the upper 4 bits and the other in the lower 4 bits.
Unpacked BCD numbers are mostly used as an intermediate form for
converting packed BCD numbers to and from ASCII characters. In the
unpacked form, you just have to add 30h to each byte to display the
number (ie: numbers 0 to 9 ASCII values are 30h to 39h), and you just
subtract 30h from each ASCII character byte to get the BCD numbers.
Whenever a BCD operation is carried out, there is a slight error(since
the entire byte isn't being used) that is corrected by using the command
DAA. This instruction conditionally adjusts the Accumulator for BCD
addition and subtraction operations. For addition (ADD, ADC, INC) or
subtraction (SUB, SBC, DEC, NEG), the following table indicates the
operation performed:
(use a monospaced typeface to see this properly)
Operation|C |Hex value |H |Hex value|number |C
|before|upr. digit|before|low digit|added |after
|DAA |(bit 7-4) |DAA |(bit 3-0)|to byte|DAA
----------------------------------------------------------
0 9-0 0 0-9 00 0
0 0-8 0 A-F 06 0
0 0-9 1 0-3 06 0
ADD 0 A-F 0 0-9 60 1
ADC 0 9-F 0 A-F 66 1
INC 0 A-F 1 0-3 66 1
1 0-2 0 0-9 60 1
1 0-2 0 A-F 66 1
1 0-3 1 0-3 66 1
---------------------------------------------------------
SUB 0 0-9 0 0-9 00 0
SBC 0 0-8 1 6-F FA 0
DEC 1 7-F 0 0-9 A0 1
NEG 1 6-7 1 6-F 9A 1
---------------------------------------------------------
Sincerely,
The Unibomer
Jared Ivey
Unibomer@Juno.com
http://www.geocities.com/SiliconValley/Vista/7342
"I don't know why I did it, I don't know why I enjoyed it, and I don't
know why I'll do it again." -- Bart Simpson
References: