I think that almost every program starts with CLD! Why use binary coded decimal representation? Possibly for applications where numbers are typed in in decimal form with a key board , some arithmetics is carried out and the result then sent in decimal form to a display. In this case the operations to go to BCD representation might be a bit shorter then to a "packed binary" representation. Anybody knows a "reasonable" application?
Well I once had a little application for BCD! Someone sent the fax home:
send
+ more
_________
money
asking his parents to send some money. Replacing the letters with the right decimal digest the arithmetic fits! This can certainly be solved by hand with a little analysis but also with "brute force" using a 6502 checking all possibilities. I once wrote a small rather elegant program using arithmetics in BCD mode of 16 bits and 32 bit words to solve this problem.
The idea was (I think) to see 0sndmore as a 4 byte number, to increase this number with 1 each time and to check the arithmetics.
Maybe somebody would be amused (like me) to write such a program. At least once to operate in BCD mode!
4 bit binary coded decimal
- GARTHWILSON
- Forum Moderator
- Posts: 8773
- Joined: 30 Aug 2002
- Location: Southern California
- Contact:
The CMOS 65c02 has the decimal flag already clear when it comes out of reset or responds to an interrupt, so the CLD is not necessary there.
As for what the decimal mode is good for, I'll quote a little out of WDC's excellent programming manual:
"In certain applications such as numeric I/O programming, where conversion between ASCII and binary representation of decimal strings is inconvenient, and business applications, in which conversion of binary fractions to decimal fractions results in approximation errors, it is convenient to represent numbers in decimal form and, if possible, perform arithmetic operations on them directly in this form."
As for what the decimal mode is good for, I'll quote a little out of WDC's excellent programming manual:
"In certain applications such as numeric I/O programming, where conversion between ASCII and binary representation of decimal strings is inconvenient, and business applications, in which conversion of binary fractions to decimal fractions results in approximation errors, it is convenient to represent numbers in decimal form and, if possible, perform arithmetic operations on them directly in this form."
Re: 4 bit binary coded decimal
> I think that almost every program starts with CLD! Why use binary
> coded decimal representation?
The two most recent applications of BCD I have had were
a) a clock chip whose registers were BCD anyway
b) decoding the modified Julian data passed in the Television Service Data Packet as part of UK teletext broadcasts as a means of keeping an accurate clock which automatically corrected for BST/GMT
Sprow.
> coded decimal representation?
The two most recent applications of BCD I have had were
a) a clock chip whose registers were BCD anyway
b) decoding the modified Julian data passed in the Television Service Data Packet as part of UK teletext broadcasts as a means of keeping an accurate clock which automatically corrected for BST/GMT
Sprow.
Re: 4 bit binary coded decimal
Mats wrote:
Anybody knows a "reasonable" application?
The problem is, of course, that doing this in binary is nonsensical. How does one accurately represent 0.3, or 0.1 for that matter, in binary? It can't be done. You can approximate, and many computer floating point implementations take care of this for you, but (1.1 + 0.1) - 1.2 will, in a fair number of naive floating point implementations, NOT give zero as the answer (it'll be zero to a large number of bits, but over the whole floating point value, it won't be precisely zero). For small numbers of bits, say 32 or 64, this isn't so much a big deal. But when you're dealing with astronomically large or small numbers, say in the field of astronomy, weather, and medicine especially, these accumulated round-off errors can mean life or death to people.
BCD eliminates any chance of this happening.
--
Samuel A. Falvo II