I thought I'd better post a version that does not have the peculiarity mentioned in earlier messages. This implememtation follows closely John Halleck's version in C. Note this an 'unhacked' version, straight forward, no special effort to reduce code size or execution time. ;Four byte square root. ;Call with number in n_a:n_b:n_c:n_d: ;Returns with root in r_c:r:d ;Uses: r_a, r_b, p_a, p_b, p_c, p_d, t_a, t_b, t_c, t_d ;(16 bytes of ram total) ;Uses 92 memory locations. ;Worst case execution time: about 1160 clock cycles sq_root: clrf r_a clrf r_b clrf r_c clrf r_d movlw b'01000000' movwf p_a clrf p_b clrf p_c clrf p_d root_loop: movf r_a, w ;Or position bit with root to form iorwf p_a, w ;next trial number. Save in temp. movwf t_a movf r_b, w iorwf p_b, w movwf t_b movf r_c, w iorwf p_c, w movwf t_c movf r_d, w iorwf p_d, w movwf t_d movf t_d, w ;Subtract root from num subwf n_d, w ;Save result in temp movwf t_d bc xx2 incf t_c, f ;Propagate 'borrow' bnz xx2 incf t_b, f bnz xx2 incf t_a, f xx2: movf t_c, w subwf n_c, w movwf t_c bc xx3 incf t_b, f bnz xx3 incf t_a, f xx3: movf t_b, w subwf n_b, w movwf t_b bc xx4 incf t_a, f xx4: movf t_a, w subwf n_a, w movwf t_a bnc root_too_big movwf n_a ;Else save result movf t_b, w movwf n_b movf t_c, w movwf n_c movf t_d, w movwf n_d bcf STATUS, C ;Shift root to the right rrf r_a, f rrf r_b, f rrf r_c, f rrf r_d, f movf p_a, w ;'Or' root with position bit iorwf r_a, f movf p_b, w iorwf r_b, f movf p_c, w iorwf r_c, f movf p_d, w iorwf r_d, f goto shift_position root_too_big: rrf r_a, f rrf r_b, f rrf r_c, f rrf r_d, f shift_position: ;Shift position bit two places bcf STATUS, C rrf p_a, f rrf p_b, f rrf p_c, f rrf p_d, f bc done rrf p_a, f rrf p_b, f rrf p_c, f rrf p_d, f goto root_loop done: return -- Bob Fehrenbach Wauwatosa, WI bfehrenb@execpc.com