[Coco] Divide by 10 on a Motorola MC6809(E)

William Astle lost at l-w.ca
Wed Mar 20 00:21:14 EDT 2024


On 2024-03-19 21:52, John Mark Mobley via Coco wrote:
> Q) So how do you convert to base 10 without the usual divide and modulus
> commands?
> 
> A) Use the BCD add method.

Your method of converting to and from BCD is probably not the best 
method once the numbers get beyond 8 or maybe 16 bits. A better solution 
is the "double dabble" method, which is reversible and can be used for 
conversion in both directions and it only makes a single pass through 
the value to be converted. The reason this is probably faster is that it 
doesn't require any multiplications or multiple precision additions.

However, by the time you finish doing the conversions, I think it will 
generally work out that a traditional binary shift and subtract division 
algorithm will be faster since there are no conversions and it makes a 
single pass through the dividend.

As a side note, if you're taking the 10's complement to do BCD 
subtraction, you can actually just do the 9's complement, make sure C is 
set, and use ADC for the add. It saves a separate ADD 1 operation.

The double dabble method is explained well enough by the wiki article 
and better than I can explain it here. It can also be implemented in 
hardware.


-- 
William Astle



More information about the Coco mailing list