[Coco] Divide by 10 on a Motorola MC6809(E)
Don Barber
don at dgb3.net
Wed Mar 20 18:01:42 EDT 2024
Sorry yes arithmetic shift was incorrect, my bad. Should clear the carry bit with the right ANDCC and then do LSRA instead.
Don
Sent from my iPhone
> On Mar 20, 2024, at 3:48 PM, Sean Conner via Coco <coco at maltedmedia.com> wrote:
>
> It was thus said that the Great Don Barber via Coco once stated:
>> A trick I use to divide 8 bit integers by 10 is to MUL by 205, then shift
>> the A register down by 3 bits (ASRA three times). This works out to
>> 205/2048 which is close enough precision to 1/10 for 8 bit integers.
>
> Nice, although when I tried it, it gave very ... odd ... results for
> higher values of A. Up through 150 it gave the right answers, but starting
> with 160, it started returning (mostly incorrect) negative answers:
>
> 160 -16
> 170 -15
> 180 -14
> 190 -13
> ...
> 240 -8
> 250 -9
>
> change the ASRA to LSRA and the results are what you would expect for
> unsigned division. Also, after the sequence:
>
> ldb #205
> mul
> lsra
> lsra
> lsra
>
> the C flag is 1 for remainders of 5 through 9; clear otherwise. I found
> that interesting.
>
> -spc
>
>
> --
> Coco mailing list
> Coco at maltedmedia.com
> https://pairlist5.pair.net/mailman/listinfo/coco
More information about the Coco
mailing list