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

Re: A85: 16-bit integer Square Root




I guess you enter you 16 bit number into the HL register, but which register
does the square root go into?

Thanxx

<< 
 I finished the 16-bit version of my sqrt algorithym.  I'm not sure how
 fast Jarno's Sqrt is but I can say that my Sqrt is smaller an instead of
 rounding down it rounds to the nearest integer.
 Speedwise I tested the worst case and my calc on 8 contrast did 256 worst
 case sqrt16s in about .7 seconds.
 The worst case by the way is sqrt of 1.
 
 Anyways here it is:
 Sqrt16:	
   push de
   push bc
   ld de,0
   ld bc,0
   call CP_HL_DE
   jr z,Sqrt16Done  ;0 is a special case.
   ld de,65280
   ld bc,256
   sbc hl,de
   jr nc,Sqrt16done
   dec bc           ;bc=255
   scf
   rr h
   rr l		   ;shift hl
   call Sqrt16loop
 Sqrt16done:
   ld h,b
   ld l,c
   pop bc
   pop de
   ret
 Sqrt16loop:
   add hl,bc
   ret c
   dec c
   jp Sqrt16loop  
 
    >>


Follow-Ups: