Datasheet
2010 Microchip Technology Inc. DS39616D-page 95
PIC18F2331/2431/4331/4431
9.0 8 x 8 HARDWARE MULTIPLIER
9.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 applications
previously reserved for digital signal processors.
A comparison of various hardware and software multi-
ply operations, along with the savings in memory and
execution time, is shown in Ta b l e 9- 1 .
9.2 Operation
Example 9-1 shows the sequence to do an 8 x 8
unsigned multiply. Only one instruction is required
when one argument of the multiply is already loaded in
the WREG register.
Example 9-2 shows the sequence to do an 8 x 8 signed
multiply. 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 9-1: 8 x 8 UNSIGNED MULTIPLY
ROUTINE
EXAMPLE 9-2: 8 x 8 SIGNED MULTIPLY
ROUTINE
TABLE 9-1: PERFORMANCE COMPARISON
MOVF ARG1, W ;
MULWF ARG2 ; ARG1 * ARG2 ->
; PRODH:PRODL
MOVF ARG1, W
MULWF ARG2 ; ARG1 * ARG2 ->
; PRODH:PRODL
BTFSC ARG2, SB ; Test Sign Bit
SUBWF PRODH, F ; PRODH = PRODH
; - ARG1
MOVF ARG2, W
BTFSC ARG1, SB ; Test Sign Bit
SUBWF PRODH, F ; 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 13 69 6.9 s 27.6 s 69 s
Hardware Multiply 1 1 100 ns 400 ns 1 s
8 x 8 Signed
Without Hardware Multiply 33 91 9.1 s 36.4 s 91 s
Hardware Multiply 6 6 600 ns 2.4 s6 s
16 x 16 Unsigned
Without Hardware Multiply 21 242 24.2 s 96.8 s242 s
Hardware Multiply 24 24 2.4 s9.6 s 24 s
16 x 16 Signed
Without Hardware Multiply 52 254 25.4 s102.6 s254 s
Hardware Multiply 36 36 3.6 s 14.4 s 36 s