DOWNLOAD MAIN
;16x16 Multiply routine from Myke Predko
; NOTE: THIS ROUTINE REQUIRES
; THE MULTIPLICAND TO BE POSITIVE!!!
; THE MULTIPLIER, HOWEVER, CAN BE NEGATIVE.
clrf Product + 2 ; "Product" will be the
clrf Product + 3 ; Result of the Operation
movlw D'16' ; Operating on 16 Bits
movwf BitCount
bcf NegMult ;Clear the negative multiplication flag
ifclr Multiplier+1,7 ;Check high bit to see if negative
goto Loop2;Positive - continue w/normal multiplication
bsf NegMult;Set negative multiplication flag
;
; Multiplier is Negative,
; so take two's complement of Multiplier
; before doing operation
;
movlw 0xFF;Take Two's Complement of Multiplier
xorwf Multiplier,f
xorwf Multiplier+1,f
incfsz Multiplier,f
goto Loop2
incf Multiplier+1,f ;Done w/two's complement
Loop2 ; Loop Here for Each Bit
;
rrf Multiplier + 1, f
rrf Multiplier, f
btfss STATUS, C
goto Skip
; "Product"
clrf Product + 4
movf Multiplicand + 1, w
addwf Product + 3, f
btfsc STATUS, C
incf Product + 4, f
movf Multiplicand, w
addwf Product + 2, f
btfsc STATUS, C
incfsz Product + 3, f
goto $ + 2
incf Product + 4, f
Skip
bcf STATUS, C
rrf Product + 4, f
rrf Product + 3, f
rrf Product + 2, f
rrf Product + 1, f
rrf Product, f
decfsz BitCount,f
goto Loop2
;
; Check if Multiplier was Negative.
; If so, take two's complement of Product
;
ifclr NegMult
goto MultDone
movlw 0xFF
xorwf Product,f
xorwf Product+1,f
xorwf Product+2,f
xorwf Product+3,f
incfsz Product,f
goto MultDone
incfsz Product+1,f
goto MultDone
incfsz Product+2,f
goto MultDone
incf Product+3,f
MultDone
return
|