|
PIC18FXX39 Datasheet, PDF (68/322 Pages) Microchip Technology – Enhanced FLASH Microcontrollers with Single Phase Induction Motor Control Kernel | |||
|
◁ |
PIC18FXX39
Example 7-3 shows the sequence to do a 16 x 16
unsigned multiply. Equation 7-1 shows the algorithm
that is used. The 32-bit result is stored in four registers,
RES3:RES0.
EQUATION 7-1:
16 x 16 UNSIGNED
MULTIPLICATION
ALGORITHM
RES3:RES0 =
=
ARG1H:ARG1L ï· ARG2H:ARG2L
(ARG1H ï· ARG2H ï· 216) +
(ARG1H ï· ARG2L ï· 28) +
(ARG1L ï· ARG2H ï· 28) +
(ARG1L ï· ARG2L)
EXAMPLE 7-3:
16 x 16 UNSIGNED
MULTIPLY ROUTINE
MOVF ARG1L, W
MULWF ARG2L
; ARG1L * ARG2L ->
; PRODH:PRODL
MOVFF PRODH, RES1 ;
MOVFF PRODL, RES0 ;
;
MOVF ARG1H, W
MULWF ARG2H
; ARG1H * ARG2H ->
; PRODH:PRODL
MOVFF PRODH, RES3 ;
MOVFF PRODL, RES2 ;
;
MOVF ARG1L, W
MULWF ARG2H
; ARG1L * ARG2H ->
; PRODH:PRODL
MOVF PRODL, W
;
ADDWF RES1, F
; Add cross
MOVF PRODH, W
; products
ADDWFC RES2, F
;
CLRF WREG
;
ADDWFC RES3, F
;
;
MOVF ARG1H, W
;
MULWF ARG2L
; ARG1H * ARG2L ->
; PRODH:PRODL
MOVF PRODL, W
;
ADDWF RES1, F
; Add cross
MOVF PRODH, W
; products
ADDWFC RES2, F
;
CLRF WREG
;
ADDWFC RES3, F
;
Example 7-4 shows the sequence to do a 16 x 16
signed multiply. Equation 7-2 shows the algorithm
used. The 32-bit result is stored in four registers,
RES3:RES0. To account for the sign bits of the argu-
ments, each argument pairs Most Significant bit (MSb)
is tested and the appropriate subtractions are done.
EQUATION 7-2: 16 x 16 SIGNED
MULTIPLICATION
ALGORITHM
RES3:RES0
= ARG1H:ARG1L ï· ARG2H:ARG2L
= (ARG1H ï· ARG2H ï· 216) +
(ARG1H ï· ARG2L ï· 28) +
(ARG1L ï· ARG2H ï· 28) +
(ARG1L ï· ARG2L) +
(-1 ï· ARG2H<7> ï· ARG1H:ARG1L ï· 216) +
(-1 ï· ARG1H<7> ï· ARG2H:ARG2L ï· 216)
EXAMPLE 7-4:
16 x 16 SIGNED
MULTIPLY ROUTINE
MOVF
MULWF
MOVFF
MOVFF
;
MOVF
MULWF
MOVFF
MOVFF
;
MOVF
MULWF
MOVF
ADDWF
MOVF
ADDWFC
CLRF
ADDWFC
;
MOVF
MULWF
MOVF
ADDWF
MOVF
ADDWFC
CLRF
ADDWFC
;
BTFSS
BRA
MOVF
SUBWF
MOVF
SUBWFB
;
SIGN_ARG1
BTFSS
BRA
MOVF
SUBWF
MOVF
SUBWFB
;
CONT_CODE
:
ARG1L, W
ARG2L
PRODH, RES1
PRODL, RES0
ARG1H, W
ARG2H
PRODH, RES3
PRODL, RES2
ARG1L, W
ARG2H
PRODL, W
RES1, F
PRODH, W
RES2, F
WREG
RES3, F
ARG1H, W
ARG2L
PRODL, W
RES1, F
PRODH, W
RES2, F
WREG
RES3, F
ARG2H, 7
SIGN_ARG1
ARG1L, W
RES2
ARG1H, W
RES3
ARG1H, 7
CONT_CODE
ARG2L, W
RES2
ARG2H, W
RES3
; ARG1L * ARG2L ->
; PRODH:PRODL
;
;
; ARG1H * ARG2H ->
; PRODH:PRODL
;
;
; ARG1L * ARG2H ->
; PRODH:PRODL
;
; Add cross
; products
;
;
;
;
; ARG1H * ARG2L ->
; PRODH:PRODL
;
; Add cross
; products
;
;
;
; ARG2H:ARG2L neg?
; no, check ARG1
;
;
;
; ARG1H:ARG1L neg?
; no, done
;
;
;
DS30485B-page 68
Preliminary
ï£ 2002-2013 Microchip Technology Inc.
|
▷ |