
2004 Microchip Technology Inc.
Preliminary
DS39637A-page 111
PIC18F2480/2580/4480/4580
8.0
8 x 8 HARDWARE MULTIPLIER
8.1
Introduction
All PIC18 devices include an 8 x 8 hardware multiplier
as part of the ALU. The multiplier performs an unsigned
operation and yields a 16-bit result that is stored in the
product register pair, PRODH:PRODL. The multiplier’s
operation does not affect any flags in the Status
register.
Making multiplication a hardware operation allows it to
be completed in a single instruction cycle. This has the
advantages of higher computational throughput and
reduced code size for multiplication algorithms and
allows the PIC18 devices to be used in many applica-
tions previously reserved for digital signal processors.
A comparison of various hardware and software
multiply operations, along with the savings in memory
and execution time, is shown in Table 8-1.
8.2
Operation
Example 8-1 shows the instruction sequence for an
8 x 8 unsigned multiplication. Only one instruction is
required when one of the arguments is already loaded
in the WREG register.
Example 8-2 shows the sequence to do an 8 x 8 signed
multiplication. To account for the signed bits of the
arguments, each argument’s Most Significant bit (MSb)
is tested and the appropriate subtractions are done.
EXAMPLE 8-1:
8 x 8 UNSIGNED
MULTIPLY ROUTINE
EXAMPLE 8-2:
8 x 8 SIGNED
MULTIPLY ROUTINE
TABLE 8-1:
PERFORMANCE COMPARISON FOR VARIOUS MULTIPLY OPERATIONS
MOVF
MULWF
ARG1, W
ARG2
;
; ARG1 * ARG2 ->
; PRODH:PRODL
MOVF
MULWF
ARG1, W
ARG2
; ARG1 * ARG2 ->
; PRODH:PRODL
; Test Sign Bit
; PRODH = PRODH
; - ARG1
BTFSC
SUBWF
ARG2, SB
PRODH, F
MOVF
BTFSC
SUBWF
ARG2, W
ARG1, SB
PRODH, F
; Test Sign Bit
; PRODH = PRODH
; - ARG2
Routine
Multiply Method
Program
Memory
(Words)
Cycles
(Max)
Time
@ 40 MHz
@ 10 MHz
@ 4 MHz
8 x 8 unsigned
Without hardware multiply
Hardware multiply
Without hardware multiply
Hardware multiply
Without hardware multiply
Hardware multiply
Without hardware multiply
Hardware multiply
13
1
33
6
21
28
52
35
69
1
91
6
242
28
254
40
6.9
μ
s
100 ns
9.1
μ
s
600 ns
24.2
μ
s
2.8
μ
s
25.4
μ
s
4.0
μ
s
27.6
μ
s
400 ns
36.4
μ
s
2.4
μ
s
96.8
μ
s
11.2
μ
s
102.6
μ
s
16.0
μ
s
69
μ
s
1
μ
s
91
μ
s
6
μ
s
242
μ
s
28
μ
s
254
μ
s
40
μ
s
8 x 8 signed
16 x 16 unsigned
16 x 16 signed