PIC Microcontroller Math Method

Divide 24 bit int by 15 bit int to 24 bit int

by Nikolai Golovchenko

FXD2415U:
        CLRF REMB0
        CLRF REMB1
        MOVLW 24
        MOVWF LOOPCOUNT
LOOPU2415
        RLF ACCB0, W    ;left shift of accb0's msb to reminder
        RLF REMB1, F
        RLF REMB0, F
        MOVF BARGB1, W  ;REMB -= BARGB
        SUBWF REMB1, F
        MOVF BARGB0, W
        BTFSS _C
        INCFSZ BARGB0,W
        SUBWF REMB0, F

        BTFSC _C
        GOTO UOK45LL    ;if no borrow

        MOVF BARGB1, W  ;REMB += BARGB
        ADDWF REMB1, F
        MOVF BARGB0, W
        BTFSC _C
        INCFSZ BARGB0,W
        ADDWF REMB0, F

        BCF _C
UOK45LL
        RLF AARGB2, F
        RLF AARGB1, F
        RLF AARGB0, F
        DECFSZ LOOPCOUNT, F
        GOTO LOOPU2415

        RETURN