MPY P,loc16,#16bit
6-229
MPY P,loc16,#16bit 16 X 16-Bit Multiply
SYNTAX OPTIONS OPCODE OBJMODE RPT CYC
MPY P,loc16,#16bit 1000 1100 LLLL LLLL
CCCC CCCC CCCC CCCC
1 − 1
Operands P Product register
loc16 Addressing mode (see Chapter 5)
#16bit 16-bit immediate constant value
Description Multiply the signed 16-bit contents of the location pointed to by the “loc16”
addressing mode by the 16-bit immediate value and store the 32-bit result in
the P register:
P = signed [loc16] * signed 16bit;
Flags and
Modes
None
Repeat This instruction is not repeatable. If this instruction follows the RPT
instruction, it resets the repeat counter (RPTC) and executes only once.
Example
; ; Calculate using 16-bit multiply:
; Y = (X0*C0) >> 2) + (X1*C1 >> 2) + (X2*C2 >> 2),
; C0, C1 and C2 are constants
SPM −2 ; Set product shift to >> 2
MOVB ACC,#0 ; Zero ACC
MPY P,@X2,#C2 ; P = X2*C2
MPYA P,@X1,#C1 ; ACC = X2*C2>>2, P = X1*C1
MPYA P,@X0,#C0 ; ACC = X1*C1>>2 + X2*C2>>2, P = X0*C0
ADDL ACC,P << PM ; ACC = X0*C0>>2 + X1*C1>>2 + X2*C2>>2
MOVL @Y,ACC ; Store result into Y