div and mul of BCD or Hex?
Hello coder,
I am currently working on the display and calculation of scores. I have already read the thread "BCD Arithmetic - howto^". The simple adding and subtracting is no problem. But I have to divide the score by 50. Also the points can be increased by graduation 3*90 or 5*240 etc. Now to my problem. For dividing and multiplying with BCD there are no 1:1 commands. Multiplying can be avoided by using LookUp tables and adding. But for x:50 there is no alternative. Of course I can calculate everything in hex and convert the hex values to decimal for the display. But this eats a lot of cycles. :( How can I solve the problem without overloading the computer. Thanks in advance JoeJoe @Admins: please move to right section, sorry |
You can convert the divide into a multiply.
First, add the number to itself to do *2. Then, remove the two last digits to do /100. You will have achieved /50. |
/50 can be achieved by /100 (dropping last byte) and add the number to itself (so /100*2)
|
thanks for your replies :)
|
Quote:
|
Quote:
|
That's right, but we don't want to be like that ;)
I do this with the reciprocal method. x/50 = x*(1/50) |
Quote:
:50 is simple enough (already answered by others), but general multiplication or division in BCD is slow, in general. To multply, use the pen-and-paper algorithm of multiplying digit by digit, then add the partial products by a BCD add. Similarly, a BCD division follows the pen-and-paper algorithm of continuous subtraction until an overflow, and keeping the number of times a number was subtracted, then carry over the remainder, and continue with the next digit. All these algorithms are slow... |
Quote:
If you have no division instruction, the same way as in BCD, except that each digit can be either 0 or 1, which simplifies continuous subtraction to a single compare. If you do, well, use the division instruction. |
All times are GMT +2. The time now is 17:21. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.