On 31-Oct-04 Mark Rogers wrote:
Graham wrote:
Interestingly (to me at least), in the days when we programmed everything in assembler, 8-bit microprocessors had a set of BCD (Binary Coded Decimal) instructions that allowed computations to mirror what we expect in real life. They were put there for use by pocket calculators, which is why these machines give the *right* answers and recur a third rather than a tenth.
Do you have any reference to this use of BCD? I only know of the use of BCD instructions with integer values, where their purpose is somewhat different (in particular the ease with which BCD can be displayed on 7-segment displays with very little processing capability, compared with decimal values).
[Digs out old "Z80-CPU Z80A-CPU Technical Manual", September 1978, Copyright© 1977 by Zilog Inc.]
p. 29 (Sn. 5.3): "The flags and decimal adjust instruction (DAA) in the Z80 ... allow arithmetic operations for: multiprecision packed BCD numbers ... "
p. 31 (ditto): "Two BCD digit rotate instructions (RRD and RLD) allow a digit in the accumulator to be rotated with the two digits in a memory location ... These instructions allow for efficient BCD arithmetic."
p. 39 (Sn. 6.0): "There are also two non-testable bits in the flag register. Both of these are used for BCD arithmetic. They are: 1) Half carry (H) -- this is the BCD carry or borrow result from the least significant four bits of operation. When using the DAA (Decimal Adjust Instruction) this flag is used to accorect the result of a previous packed decimal add or subtract. 2) Subtract Flag (N) -- Since the algorithm for correcting BCD operations is different for addition or subtraction, this flag is used to specify what type of instruction was executed last so that the DAA operation will be correct for either addition or subtraction.
p. 48 (Table 7.0.5): "DAA (Decimal Adjust Accuulator): Converts accumulator content into packed BCD following add or subtract with packed BCD operands."
The basic idea was that an 8-bit byte would store two decimal digits, one in each half-byte ("nibble") of 4 bits, of course in binary form "0" = 0000, "1" = 0001, ... , "8" = 1000, "9" = 1001. The only arithmetic available is add or subtract, which operate on full 8-bit or 16-bit binary numbers. However, the DAA instruction converts the binary result of these binary operations on the binary byte corresponding to the BCD representation back into a BCD result. Anything more complex had to be programmed outside the CPU.
I used to use (and still have) a Texas Instruments TI-59 calculator, which was excellent for its day (about 1977). This used BCD storage (I discovered an undocumented trick which enabled me to see the 1-byte register contents on the display), both for numerical data (in "floating-point" format) and for program code. There were 1000 bytes available which could be partitioned between program code (per-byte) and numbers (8 bytes/number). There were supplementary chips which were hard-wired with special purpose programs which could be slotted in. On of these was a "matrix pack" for addition, subtraction and multiplication, and with these subroutines on call I was able to extract eigenvalues and eigenvectors of matrices up to 15x15 (provided symmetric -- there was just enough number storage to hold the numbers). Those were the days!
Best wishes to all, Ted.
-------------------------------------------------------------------- E-Mail: (Ted Harding) Ted.Harding@nessie.mcc.ac.uk Fax-to-email: +44 (0)870 094 0861 [NB: New number!] Date: 31-Oct-04 Time: 19:30:10 ------------------------------ XFMail ------------------------------