Andy David says:
Here's my 24bit routine as written for the 17c43 taken from a mail I sent Scott just after I wrote them, hence the comments about the implementations I used.I did a few pencilandpaper runs through the algorithm to be sure I understood the steps involved. This 24bit resembles these 'manual' steps of shifting along the input string 2 bits at a time and subtracting  as the result is 12bit, the final subtraction isn't awkward as in the 32bit sqrt. I can't remember the performance figures for this routine, but I've just counted 348 min, 406 max (inc. call & return). A downside of this method is that the loop counter has to be a seperate variable, so it uses the same amount of ram as the 32bit sqrt. This one is easier to follow and compare to an example on paper than the method I've used for the 32bit sqrt.
I've added a 16bit square root routine (again for the 17c43) that uses successive approximation to find the square root, the binary restoring method I'm fairly sure would be quicker. This is the only 16bit sqrt routine I have specifically for the 17cxx PICs, I've only included it as the original poster requested a 16bit routine. If you really want speed speed speed, I'd rewrite the 32bit routine to be 16bit.
Standard disclaimer applies
;========================================================================== ; brSQRT24 ; ; Calculates the square root of a twentyfour bit number using the ; binary restoring method. ; ; Result in ACCaHI:ACCaLO ; Input in ACCcLO:ACCdHI:ACCdLO ; Test ACCbLO:ACCcHI ; Counter in ACCbHI ; ; 40 words long, uses 8 bytes RAM (inc. 3 holding 24bit input). ; ; brSQRT24: clrf ACCaHI,f ; clrf ACCaLO,f ; clrf ACCcHI,f ; clrf ACCbLO,w ; movlw .12 ; movwf ACCbHI ; (6 cycle intro, 8 incl. call) ShftUp: rlcf ACCdLO,f ; Shift input up 2 places. rlcf ACCdHI,f ; (33 cycles per loop if bit is 0) rlcf ACCcLO,f ; (29 cycles per loop if bit is 1) rlcf ACCcHI,f ; rlcf ACCbLO,f ; rlcf ACCdLO,f ; rlcf ACCdHI,f ; rlcf ACCcLO,f ; rlcf ACCcHI,f ; rlcf ACCbLO,f ; rlcf ACCaLO,f ; Shift rootsofar up by two and append rlcf ACCaHI,f ; ... '01'. rlcf ACCaLO,f ; rlcf ACCaHI,f ; bcf ACCaLO,1 ; bsf ACCaLO,0 ; SubTest:movfp ACCaLO,WREG ; subwf ACCcHI,f ; movfp ACCaHI,WREG ; subwfb ACCbLO,f ; btfsc ALUSTA,C ; goto Set1 movfp ACCaLO,WREG ; Restore the remainder. addwf ACCcHI,f ; ... (the current bit is 0). movfp ACCaHI,WREG ; addwfc ACCbLO,f ; goto Set0 ; Set1: bsf ACCaLO,1 ; Set0: rrcf ACCaHI,f ; rrcf ACCaLO,f ; bcf ACCaHI,7 ; BitLoop:decfsz ACCbHI,f ; goto ShftUp return
See also:
file: /Techref/microchip/math/sqrt/sqrt24.htm, 3KB, , updated: 2000/2/14 14:11, local time: 2018/9/25 08:58,

©2018 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions? <A HREF="http://www.piclist.com/techref/microchip/math/sqrt/sqrt24.htm"> PIC Microcontoller Math Method </A> 
Did you find what you needed? 
PICList 2018 contributors:
o List host: MIT, Site host massmind.org, Top posters @20180925 RussellMc, Van Horn, David, Sean Breheny, David C Brown, Bob Blick, Isaac M. Bavaresco, Neil, Denny Esterline, Harold Hallikainen, John Gardner, * Page Editors: James Newton, David Cary, and YOU! * Roman Black of Black Robotics donates from sales of Linistep stepper controller kits. * Ashley Roll of Digital Nemesis donates from sales of RCL1 RS232 to TTL converters. * Monthly Subscribers: Gregg Rew. ongoing support is MOST appreciated! * Contributors: Richard Seriani, Sr. 
Welcome to www.piclist.com! 
.