32-BIT DIVISION - Oct 02 issue I recently asked Peter Hemsley how easy it would be to expand his PIC 16-bit/16-bit division routine (in the PIC Tricks folder on our ftp) to 32-bit/16-bit. He replied: If there is a Carry out from the Shift left then force the subtraction, as in the following. This has not been thoroughly tested but seems to work OK. By the way, a 32/32 divide would involve a 32-bit comparison and a 32-bit subtraction. A tiresome job in PIC language. divide movlw 32 ; 32-bit divide by 16-bit movwf bitcnt clrf remdrH ; Clear remainder clrf remdrL dvloop clrc ; Set quotient bit to 0 ; Shift left dividend and quotient rlf divid0 ; lsb rlf divid1 rlf divid2 rlf divid3 ; lsb into carry rlf remdrL ; and then into partial remainder rlf remdrH skpnc ; Check for overflow goto subd movfw divisH ; Compare partial remainder and divisor subwf remdrH,w skpz goto testgt ; Not equal so test if remdrH is greater movfw divisL ; High bytes are equal, compare low bytes subwf remdrL,w testgt skpc ; Carry set if remdr >= divis goto remrlt subd movfw divisL ; Subtract divisor from partial remainder subwf remdrL skpc ; Test for borrow decf remdrH ; Subtract borrow movfw divisH subwf remdrH bsf divid0,0 ; Set quotient bit to 1 **** ; Quotient replaces dividend which is lost remrlt decfsz bitcnt goto dvloop return Peter Hemsley, via email That's brilliant Peter! - I'll add it to PIC Tricks. Thank you from me and all PIC Trickers! 10Oct'02 **** this line was incorrect in published issue. The code now works excellently - well done Peter.