movlw d'32' ; 32-bit divide by 16-bit movwf temp clrf remH clrf remL divide clrc rlf Word0, f ; LSB rlf Word1, f rlf Word2, f rlf Word3, f ; MSB rlf remL, f rlf remH, f ; 16-bit Remainder btfsc STATUS, C ; Check if there is a remainder goto rem ; Deal with remainder movf denomH, w ; Compare partial remainder and divisor subwf remH, w btfss STATUS, Z goto testrem ; Not equal so test if remdrH is greater movf denomL, w ; High bytes are equal, compare low bytes subwf remL, w testrem btfss STATUS, C ; Carry set if remainder more than or equal to goto decloop ; denominator. rem movf denomL, w ; Subtract denominator from remainder. subwf remL, f btfss STATUS, C ; Do we need a borrow? decf remH, f ; If so take the borrow. movf denomH, w subwf remH, f bsf Word0, 0 decloop decfsz temp, f ; Skip when looped 32 times goto divide return