<< Previous Message Main Index Next Message >>
<< Previous Message in Thread This Month Next Message in Thread >>
Date   : Sat, 04 Jun 2005 12:45:47 +0100 (BST)
From   : "F. Haroon" <haroonnet2002@...>
Subject: Re: Assembly Language Square Root

This program gives me a lot of garble when testing...

Fiaz.

--- Jonathan Graham Harston <jgh@...> wrote:

> > Message-ID: <20050602093605.56070.qmail@...>
>  
> Ooo goody! 6502<->z80 conversion!
>  
> I couldn't get an exact opcode-for-opcode translation working[1], but
> here's one I did earlier ;)
>  
> eg, in=&70:out=&72
>  
> .sqr                            :\ On entry, !in=input value
> LDY #1:STY out+0:DEY:STY out+1  :\ Initialise out to first subtrand
> .sqr_loop                      :\ Repeatedly subtract increasing
> SEC                             :\   odd numbers until in<0
> LDA in+0:TAX:SBC out+0:STA in+0 :\ in=in-subtrand, remainder in X
> LDA in+1:SBC out+1:STA in+1
> BCC sqr_done                    :\ in<0, all done
> INY                             :\ 
> LDA out+0:ADC #1:STA out+0      :\ step +2 to next odd number
> BCC sqr_loop                   :\ no overflow, subtract again
> INC out+1:BNE sqr_loop         :\ INC high byte and subtract again
> .sqr_done
> STY out+0:STX out+1             :\ out?0=root, out?1=remainder
> RTS
> :
> This works by counting how many times increasing odd numbers
> can be subtracted until there's nothing left.
>  
> For example:
>  
> 32-1=31 -> 31-3=28 -> 28-5=23 -> 23-7=16 -> 16-9=7 -> 7-11<0
>         1          2          3          4          5
>  
> -> SRQ(30)=5, remainder 7
>  
> You can test it with:
>  
> FOR A%=1 to 65535:!in=A%:CALL sqr:P.A%,out?0,out?1:NEXT


       
       
               
___________________________________________________________ 
Yahoo! Messenger - NEW crystal clear PC to PC calling worldwide with voicemail
http://uk.messenger.yahoo.com
<< Previous Message Main Index Next Message >>
<< Previous Message in Thread This Month Next Message in Thread >>