Hacker News new | ask | show | jobs
by PhantomGremlin 4227 days ago
I forgot to mention another thing he didn't know was useful

d) BCD instructions, which he thinks are "kind of silly", and perhaps they are now that computers run at many GHz. But they were very useful in the old days. E.g. CBASIC [1] implemented BCD floating point math. Here's what Wiki says about it:

   CBASIC proved very popular because it
   incorporated 14-digit binary-coded decimal
   (BCD) math which eliminated MBASIC's rounding
   errors that were sometimes troublesome for
   accounting.
As the reference manual linked [2] from Wiki says:

   Real numbers are stored in eight bytes of
   memory. The first byte is the sign and
   exponent. The exponent is maintained in
   excess 64 code. The seven remaining bytes
   contain a normalized mantissa stored as
   packed decimal digits. The high order four
   bits of the rightmost byte is the most
   significant digit of the mantissa.
That was of course long before IEEE 754 floating point.[3] BTW did anyone know that IEEE defined decimal floating point? I didn't know that until just now. It's probably not that popular.

When a CPU runs at 1 MHz instead of 3 GHz, doing FP in BCD means much simpler and much faster conversion between internal representation and display. A lot of early microcomputers were used by small business. BCD is inferior for complicated scientific calculations, but is ideal for simple small business accounting, which was CBASICs target market.

[1] http://en.wikipedia.org/wiki/CBASIC [2] http://www.cpm.z80.de/manuals/cbasic-m.pdf [3] http://en.wikipedia.org/wiki/IEEE_floating_point

2 comments

An interesting related tidbit was that the BCD implementation was the only part of the 6502 that MOS patented. As you could not copyright an IC mask at the time, Nintendo/Ricoh were able to clone the 6502 without paying license fees simply by cutting the traces to that part of the chip. (Ricoh was a licensed second source for the 6502. I imagine Commodore was not happy with them after that...)
Incidentally BCD is one of the "perks" you get with Intel in mobile/embedded. When Intel says "x86 compatibility" they dont mean reusing pre compiled binaries, what they really mean is 30 year old legacy cruft like BCD, or 64 bit processors booting in real mode.