Re: divide by 10 with Z80
- From: "dkelvey@xxxxxxxxxxx" <dkelvey@xxxxxxxxxxx>
- Date: Thu, 24 Jan 2008 14:02:42 -0800 (PST)
On Jan 24, 1:50 pm, "dkel...@xxxxxxxxxxx" <dkel...@xxxxxxxxxxx> wrote:
On Jan 23, 12:43 pm, glen herrmannsfeldt <g...@xxxxxxxxxxxxxxxx>
wrote:
dkel...@xxxxxxxxxxx wrote:
On Jan 22, 2:36 pm, glen herrmannsfeldt <g...@xxxxxxxxxxxxxxxx> wrote:
(snip)
More obvious to me, multiply by 205 and shift right 11 bits.That gives me the quotient but not the remainder. I need both.
205 is X'CD', or binary 11001101. There should be some
optimal combinations of shift, add, and store that can
do that.
The quotient is the track while the remainder is the sector.
Both are required.
Also, the calculation exceeds 16 bits and doesn't fit into
a register pair ( 800 x 205 = 164000 ).
Yes, I tried ones that would fit, but at some point it
rounds the wrong way.
If it didn't over flow, it might look like:
(snip of 16 bit product code)
But, as I said, this is only half the problem. I still need the
remainder that would require me to multiply by 10 and then subtract.
It still might be faster, but maybe not smaller.
A loop subtracting 10 each time while counting up might be
smaller, though slower.
-- glen
Hi Glen
For speed, one might use a smaller number and expect the result
to be off some. One could treat this as a trial quotient.
Calculate the remainder using the multiply by 10 and then check
the size of the remainder. If the error was over small enough range,
one could do maybe 2 or 3 compares of the remainder to determine
how far off it was.
Of course, one could first do a trial of all of the values to
see how big the maximum error was over the range of numbers. This
would
simplify the testing.
This has the advantage that one only needs maybe 2 or 3
conditionals and the rest is all inline, as I described. No need for
time consuming loops.
I'll think about this over the weekend and post what I come up with.
I think the error will always be that the remainder is too large so
testing should be simple.
Dwight
Hi Glen
I just did a quick check. It looks like a multiply by 51d, instead
of 205. It will work if I shift the answer in HL right by 1.
I just checked it for the 800 case and it is only off by 10. That is
only
one compare. I'll have to run some test cases to try all the values
from 0 to 799. If worst case is only off by 1 in the quotient, this
would be a really fast way to do this calculation.
Dwight
.
- Follow-Ups:
- Re: divide by 10 with Z80
- From: dkelvey@xxxxxxxxxxx
- Re: divide by 10 with Z80
- References:
- divide by 10 with Z80
- From: dkelvey@xxxxxxxxxxx
- Re: divide by 10 with Z80
- From: glen herrmannsfeldt
- Re: divide by 10 with Z80
- From: dkelvey@xxxxxxxxxxx
- Re: divide by 10 with Z80
- From: glen herrmannsfeldt
- Re: divide by 10 with Z80
- From: dkelvey@xxxxxxxxxxx
- divide by 10 with Z80
- Prev by Date: Re: divide by 10 with Z80
- Next by Date: Re: ROM error Kayplus83.rom
- Previous by thread: Re: divide by 10 with Z80
- Next by thread: Re: divide by 10 with Z80
- Index(es):
Relevant Pages
|