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

Sean Conner sean at conman.org
Wed Mar 20 15:47:46 EDT 2024


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



More information about the Coco mailing list