> From: Scott Dattalo > > A week or so ago Andy W. made the claim: > > > I have in front of me a 16-bit square-root routine that takes only > > 126 cycles to execute on a PIC16C5x. [snip] > Well, I've been prodded. However, I've come up a little short. My solution > requires: > > RAM: 4 registers, including the two that hold the 16-bit input. (same) > ROM: 28 words. (4 words too big) Nice work, Scott! How many cycles is your routine, worst case? > Perhaps someone may see where 4 words can be squeezed out. But, realize that > the slightest change has many ramifications. There are many inconspicuous > dependencies (i.e. tricks). I believe you could save one instruction as follows (std peephole): > BTFSC s1,6 ;If this is the first time through the loop > goto L1 ;then N is < s1+s2 > > ;N may still be greater than s1+s2, so we need to check MS bit of N > BTFSS N_lo,0 ;If MS bit is zero, then N < s1+s2 > goto L1 => BTFSS s1,6 ;If this is the first time through the loop BTFSS N_lo,0 ;If MS bit is zero, then N < s1+s2 goto L1 -- Martin Martin Nilsson http://www.sics.se/~mn/ Swedish Institute of Computer Science E-mail: mn@sics.se Box 1263, S-164 28 Kista Fax: +46-8-751-7230 Sweden Tel: +46-8-752-1574