We haven't had a "how do you think this works" quiz from Andy Warren for a while so I thought I'd toss out this square root routine just for fun. Maybe someone can make it smaller or faster and we could all benefit. A beer to the first one with an explanation but you have to come to Milwaukee to collect. ;Call with four byte number in n_a (ms).. n_d (ls) ;Two byte result in r_a (ms) r_b (ls) ;Also uses n_x, p_a, p_b, t_a, t_b, t_x ;51 program memory locations. ;Worst case execution time: about 717 clock cycles. sq_root: clrf n_x clrf r_a clrf r_b movlw b'10000000' movwf p_a clrf p_b root_loop: clrf t_x bcf STATUS, C rrf p_a, w iorwf r_a, w movwf t_a rrf p_b, w iorwf r_b, w subwf n_b, w movwf t_b bc xx incf t_a, f bnz xx incf t_x, f xx: movf t_a, w subwf n_a, w movwf t_a bc yy incf t_x, f yy: movf t_x, w subwf n_x, w bnc zz movwf n_x movf t_a, w movwf n_a movf t_b, w movwf n_b movf p_a, w iorwf r_a, f movf p_b, w iorwf r_b, f bcf STATUS, C zz: rrf p_a, f rrf p_b, f bc done rlf n_d, f rlf n_c, f rlf n_b, f rlf n_a, f rlf n_x, f goto root_loop done: return -- Bob Fehrenbach Wauwatosa, WI bfehrenb@execpc.com