News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Binary Coded Decimal

Started by rags, February 18, 2005, 04:00:45 PM

Previous topic - Next topic

rags

Hi,
   While looking at the OpCodes Help file I saw several instructions related to BCD. What is their purpose? Or more correctly, why would one use BCD in a program?
Regards,
  Mike
God made Man, but the monkey applied the glue -DEVO

Randall Hyde

Quote from: rags on February 18, 2005, 04:00:45 PM
Hi,
   While looking at the OpCodes Help file I saw several instructions related to BCD. What is their purpose? Or more correctly, why would one use BCD in a program?
Regards,
  Mike

You might check out the discussion of BCD arithmetic in "The Art of Assembly Language" on Webster at http://webster.cs.ucr.edu. Also, the chapter on arithmetic in my new book "Write Great Code, Volume I: Understanding the Machine" goes into some detail about the uses (and abuses) of BCD arithmetic.

BTW, the BCD instructions on the x86 (integer versions) are rarely used for BCD arithmetic. They are useful for various conversions here and there, but they are mostly useless for doing actual BCD operations of any kind. BTW, Knuths "The Art of Computer Programming, Volume II" also goes into detail about BCD operations.
Cheers,
Randy Hyde

rags

Thanks for the help Randall.I'll check those out.


Regards,
           Mike
God made Man, but the monkey applied the glue -DEVO

raymond

AFAIK, the BCD set of instructions was developed in the early days of PCs to provide the accuracy required for financial purposes, i.e. accuracy to the last penny. 16-bit registers were not very useful in those days to deal with sums exceeding $327.67 having to keep one bit for the sign.

Using BCD instructions can still be useful today if you have to deal with large numbers. For example, I have used BCDs to write a "useless" program to extract the square root of any number (with or without decimals) with an accuracy of up to 10000 decimals.

There are other options to deal with large numbers but this is one of them.

Raymond
When you assume something, you risk being wrong half the time
http://www.ray.masmcode.com