[Prev][Next][Index][Thread]

Re: A85: 16-bit integer Square Root (few changes)




On Mon, 16 Mar 1998, Erik L Gillespie wrote:
> I keep trying to take the square root of 54564 and each time I try to
> display the answer the number254 is displayed.  Here's what the program
> looks like, can anyone tell me what's wrong: (I made all of the changes
> except pushing and popping hl)

The way I posted the routine the 1st time was correct.
The corrections made dealing with the shifting of hl was wrong.
Read my reply to see why.

The reason why the routine is a little confusing is because I optimized
it so that Sqrt16loop would be as fast as possible.
This meant starting with hl negative and adding so that I could use add
instead of sbc.
Also testing for the case when the answer is 256 1st so that I would only
dec b rather than dec bc.
And finally it meant dividing hl by 2

Lately I've been trying to use a smarter algorithym rather than starting
from 255 and working my way down but that would require some
multiplication and I think that it would just end up slower.

If anyone wants to know the concept behind the routine just say so.

-Humberto Yeverino Jr.

"Small potatos make the steak look bigger."

http://www.engr.csufresno.edu/~humberto/Home.html
humberto@engr.csufresno.edu

<font size=3>For browsers:<br>
<a href="http://www.engr.csufresno.edu/~humberto/Home.html">
Have a look.</a></font><br>


References: