ON 20080901@12:46:41 PM at page: http://www.piclist.com/microchip/math/mul/index.htm#39690.4780092593 James Newton[JMN-EFP-786] published post 39690.4780092593 ;As a thank you for all the code, here is a 32x16 bit Mult.
;Unsigned 32 bit by 16 bit multiplication
;This routine will take a4:a3:a2:a1*b2:b1 -> a6:a5:a4:a3:a2:a1

mult_32_16:
banksel EECON1
; Begin rearrange code
nop
movf a4,w
movwf a6
movf a3,w
movwf a5
movf a2,w
movwf a4
movf a1,w
movwf a3
; End rearrange code
CLRF a2 ; clear partial product
CLRF a1
MOVF a6,W
MOVWF c4
MOVF a5,W
MOVWF c3
MOVF a4,W
MOVWF c2
MOVF a3,W
MOVWF c1

MOVLW 0x08
MOVWF bitcnt

LOOPUM3216A:
RRF b1, F
BTFSC STATUS, C
GOTO ALUM3216NAP
DECFSZ bitcnt, F
GOTO LOOPUM3216A

MOVWF bitcnt

LOOPUM3216B:
RRF b2, F
BTFSC STATUS, C
GOTO BLUM3216NAP
DECFSZ bitcnt, F
GOTO LOOPUM3216B

CLRF a6
CLRF a5
CLRF a4
CLRF a3
RETLW 0x00

BLUM3216NAP:
BCF STATUS, C
GOTO BLUM3216NA

ALUM3216NAP:
BCF STATUS, C
GOTO ALUM3216NA

ALOOPUM3216:
RRF b1, F
BTFSS STATUS, C
GOTO ALUM3216NA
MOVF c1,W
ADDWF a3, F
MOVF c2,W
BTFSC STATUS, C
INCFSZ c2,W
ADDWF a4, F
MOVF c3,W
BTFSC STATUS, C
INCFSZ c3,W
ADDWF a5, F
MOVF c4,W
BTFSC STATUS, C
INCFSZ c4,W
ADDWF a6, F

ALUM3216NA:
RRF a6, F
RRF a5, F
RRF a4, F
RRF a3, F
RRF a2, F
DECFSZ bitcnt, f
GOTO ALOOPUM3216

MOVLW 0x08
MOVWF bitcnt

BLOOPUM3216:
RRF b2, F
BTFSS STATUS, C
GOTO BLUM3216NA
MOVF c1,W
ADDWF a3, F
MOVF c2,W
BTFSC STATUS, C
INCFSZ c2,W
ADDWF a4, F
MOVF c3,W
BTFSC STATUS, C
INCFSZ c3,W
ADDWF a5, F
MOVF c4,W
BTFSC STATUS, C
INCFSZ c4,W
ADDWF a6, F

BLUM3216NA
RRF a6, F
RRF a5, F
RRF a4, F
RRF a3, F
RRF a2, F
RRF a1, F
DECFSZ bitcnt, F
GOTO BLOOPUM3216
nop
return |Delete 'P-' before: '' but after: '