English
Language : 

PIC18LF24K Datasheet, PDF (147/594 Pages) –
PIC18(L)F26/45/46K40
12.0 8x8 HARDWARE MULTIPLIER
12.1 Introduction
All PIC18 devices include an 8x8 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 12-1.
12.2 Operation
Example 12-1 shows the instruction sequence for an
8x8 unsigned multiplication. Only one instruction is
required when one of the arguments is already loaded in
the WREG register.
Example 12-2 shows the sequence to do an 8x8 signed
multiplication. To account for the sign bits of the
arguments, each argument’s Most Significant bit (MSb)
is tested and the appropriate subtractions are done.
EXAMPLE 12-1:
MOVF ARG1, W
MULWF ARG2
8x8 UNSIGNED MULTIPLY
ROUTINE
;
; ARG1 * ARG2 ->
; PRODH:PRODL
EXAMPLE 12-2: 8x8 SIGNED MULTIPLY
ROUTINE
MOVF
MULWF
BTFSC
SUBWF
MOVF
BTFSC
SUBWF
ARG1, W
ARG2
ARG2, SB
PRODH, F
ARG2, W
ARG1, SB
PRODH, F
; ARG1 * ARG2 ->
; PRODH:PRODL
; Test Sign Bit
; PRODH = PRODH
;
- ARG1
; Test Sign Bit
; PRODH = PRODH
;
- ARG2
TABLE 12-1: PERFORMANCE COMPARISON FOR VARIOUS MULTIPLY OPERATIONS
Routine
Multiply Method
Program
Memory
(Words)
Cycles
(Max)
Time
@ 64 MHz @ 40 MHz @ 10 MHz
@ 4 MHz
8x8 unsigned
Without hardware multiply
Hardware multiply
13
1
8x8 signed
Without hardware multiply
33
Hardware multiply
6
16x16 unsigned
Without hardware multiply
Hardware multiply
21
28
16x16 signed
Without hardware multiply
Hardware multiply
52
35
69
4.3 s
6.9 s
27.6 s
69 s
1
62.5 ns 100 ns
400 ns
1 s
91
5.7 s
9.1 s
36.4 s
91 s
6
375 ns 600 ns
2.4 s
6 s
242 15.1 s 24.2 s 96.8 s 242 s
28
1.8 s
2.8 s
11.2 s
28 s
254 15.9 s 25.4 s 102.6 s 254 s
40
2.5 s
4.0 s
16.0 s
40 s
 2016 Microchip Technology Inc.
Preliminary
DS40001816C-page 147