Home     Projects     Micro     Tools     Delphi     Developer     Site map
HOME  
 
 
       
PIC Divide 24 by 16

DOWNLOAD    MAIN
;Inputs:
;   Dividend - AARGB0:AARGB1:AARGB2 (0 - most significant!)
;   Divisor  - BARGB0:BARGB1
;Temporary:
;   Counter  - LOOPCOUNT
;   Remainder- REMB0:REMB1
;Output:
;   Quotient - AARGB0:AARGB1:AARGB2
;
;       Size: 28
; Max timing: 
;        4+24*(6+6+4+3+6)-1+3+2=608 cycles (with return)
; Min timing: 
;         4+24*(6+6+5+6)-1+3+2=560 cycles (with return)
;          

FXD2416U:
        CLRF REMB0
        CLRF REMB1
        MOVLW 24
        MOVWF LOOPCOUNT
LOOPU2416
        RLF AARGB2, F
        RLF AARGB1, F
        RLF AARGB0, F

        RLF REMB1, F            ;shift carry into remainder
        RLF REMB0, F

        RLF LOOPCOUNT, F        ;save carry in counter
         
        MOVF BARGB1, W
        SUBWF REMB1, F
        MOVF BARGB0, W
        BTFSS _C
        INCFSZ BARGB0, W
        SUBWF REMB0, W
        SKPNC
         BSF LOOPCOUNT, 0 
        BTFSC LOOPCOUNT, 0
         GOTO UOK46LL
        MOVF BARGB1, W
        ADDWF REMB1, F
        MOVF REMB0, W  
UOK46LL
        MOVWF REMB0 
        CLRC                    ;copy bit 0 to carry
        RRF LOOPCOUNT, F        ;and restore counter
        DECFSZ LOOPCOUNT, f     ;decrement counter
         GOTO LOOPU2416         ;and repeat loop if not zero
         
        RLF AARGB2, F           ;shift in last bit of result
        RLF AARGB1, F   
        RLF AARGB0, F
        RETURN
		  

Copyright(c) 2005-2010 sixca.com, All rights reserved.
Best view @ 800X600, IE 6.0 up    Terms of Use  Privacy Policy