Andy David says:
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
;========================================================================== ; SQRT16 ; ; Calculates the square root of a sixteen bit number by successive ; approximation. ; ; ; Input in ACCaHI:ACCaLO ; ; Output in ACCbHI ; ; Also uses ACCbLO and ACCcHI. ; ; SQRT16: movlw 0x80 ; movpf WREG,ACCbLO ; set up walking tester bit. clrf ACCbHI,w ; movlw 0x08 ; movpf WREG,ACCcHI ; tstest: movfp ACCbLO,WREG ; set bit for testing. iorwf ACCbHI,WREG ; movpf WREG,ACCbHI ; mulwf ACCbHI ; square the current estimate. movfp ACCaLO,WREG ; compare PRODH:PRODL with ACCaHI:ACCaLO subwf PRODL,WREG ; movfp ACCaHI,WREG ; subwfb PRODH,WREG ; btfss ALUSTA,C ; If the result is <= input, goto nxtbit ; ... keep this bit set. movfp ACCbLO,WREG ; Result was > input, so reset xorwf ACCbHI,f ; ... bit to zero. nxtbit: rrncf ACCbLO,f ; rotate tester bit right. decfsz ACCcHI,f ; goto tstest ; return
See also:
file: /Techref/microchip/math/sqrt/sqrt16sa.htm, 1KB, , updated: 2000/2/14 13:10, local time: 2017/11/24 18:03,

©2017 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/sqrt16sa.htm"> PIC Microcontoller Math Method </A> 
Did you find what you needed? 
PICList 2017 contributors:
o List host: MIT, Site host massmind.org, Top posters @20171124 RussellMc, Van Horn, David, James Cameron, Sean Breheny, alan.b.pearce, IVP, Neil, David C Brown, Bob Blick, Denny Esterline, * 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! 
.