100 likes | 234 Views
ECT 357. Ch 14 Multiplication/Division/Floating-Point/Math Subroutines. Today’s Quote: The cure of crime is not in the electric chair, but in the high chair. Train up a child in the way he should go: and when he is old, he will not depart from it. Proverbs 22:6.
E N D
ECT 357 Ch 14 Multiplication/Division/Floating-Point/Math Subroutines
Today’s Quote: The cure of crime is not in the electric chair, but in the high chair. Train up a child in the way he should go: and when he is old, he will not depart from it. Proverbs 22:6
Multiplication Overview An 8 x 8 hardware multiplier is included in the ALU of the PIC18FXX2 devices. By making the multiply a hardware operation, it completes in a single instruction cycle. This is an unsigned multiply that gives a 16-bit result. The result is stored into the 16-bit product register pair (PRODH:PRODL). The multiplier does not affect any flags in the STATUS register.
Multiplication Overview Making the 8 x 8 multiplier execute in a single cycle gives the following advantages: • Higher computational throughput • Reduces code size requirements for multiply algorithms The performance increase allows the device to be used in applications previously reserved for Digital Signal Processors.
Unsigned Multiply • 2 multiplication instructions MOVF ARG1, W ;memory with wreg MULWF ARG2 MOVF ARG1, W ;literal with wreg MULLW 5 Result placed in PRODH:PRODL
Signed vs. Unsigned Numbers • Invert all bits and add 1 to convert between signed and unsigned.
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. • 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
Division Overview • No division instruction • Look up tables (Div/Log) • Multiplication/Division pairs
Math Subroutines • Multiplication subroutines from 8x8 to 32x32 signed and unsigned. • Division subroutines from 8x8 to 32x32 signed and unsigned • Floating point subroutines for: • Conversion • Multiplication • Division • Subtraction • Addition
Subroutine Implementation • #include <C:\MATH18\MATHVARS.inc> • #include <C:\MATH18\FXM1616U.inc> • #include <C:\MATH18\FXD3208U.inc> • #include <C:\MATH18\FPSUBS.inc>