Re: A86: ASM Programming Test - div 3
[Prev][Next][Index][Thread]
Re: A86: ASM Programming Test - div 3
In a message dated 12/9/98 9:41:20 PM Pacific Standard Time, electrum@tfs.net
writes:
> Hmm, a look-up table. My favorite. Problem is, I don't see an easy way to
> do division with a table. Multiplication is easy, division doesn't seem to
> be. I see two possible ways. One way would be to store all numbers from 0
> to the max. The number at that position would be the quotient. This would
> take up alot of memory but would be fast, and you could also use it to
store
> remainders (that would get a bit tricky, but possible). The other way
(that
> I can see) would be to have all the dividends in the table (assuming they
> would always be multiples of the divisor). You would search for the
divsor,
> and the position in the table woudl be the quotient. This would take less
> space, but would be slower and more limited.
>
> If anyone knows a better way, please let me know.
>
What I was thinking (once again, disregard the fact that I'm talking to you in
an IM right now) is that a program that repeatedly had to divide by 3 for
numbers that were, say, below 30, it would be fast and easy to have a table
that had the values in them. Depending on the purpose of the program, the
table could be pre-rounded as well. Some simple code from a newbie like me
could probably do the trick:
Code:
...
ld a,27
call Div_A_By_Three
...
Div_A_By_Three:
cp 0
ld b,0
cp 1
ld b,0
cp 2
ld b,0
cp 3
ld b,1
cp 4
ld b,1
...
cp 27
ld b,9
...
ret
I'm sure there's a faster/more efficient way, but you get the idea... (perhaps
you can show me something cool by optimizing that? :)