Texas Instruments MSP430x1xx User Manual
Page 94
Hardware Multiplier Operation
6-6
6.2.2
Multiply Signed, 16
×
16 bit, 16
×
8 bit, 8
×
16 bit, 8
×
8 bit
The following multiplication operation shows 36 bytes of program code and 36
execution cycles (16
×
16 bit multiplication).
**********************************************************
*
TRANSFER BOTH OPERANDS TO THE REGISTERS IN THE
*
*
HARDWARE MULTIPLIER MODULE
*
*
IF ONE OF THE OPERANDS IS 8 BIT, SIGN EXTENSION
*
*
is NEEDED. USE CONSTANT OPERAND1 AND OPERAND2 TO *
*
IDENTIFY BYTE DATA
*
**********************************************************
OPERAND1 .EQU
0
; 0: OPERAND1 IS WORD (16BIT)
; 8: OPERAND1 IS BYTE ( 8BIT)
OPERAND2 .EQU
0
; 0: OPERAND2 IS WORD (16BIT)
; 8: OPERAND2 IS BYTE ( 8BIT)
MPY
.EQU
0130H
MPYS
.EQU
0132H
MAC
.EQU
0134H
MACS
.EQU
0136H
OP2
.EQU
0138H
RESLO .EQU
013AH
RESHI .EQU
013CH
SUMEXT .EQU
013EH
.BSS
OPER1,2,200H
.BSS
OPER2,2
.BSS
RAM,8
.IF OPERAND1=0
MOV
&OPER1,&MPYS ; LOAD 1ST (WORD) OPERAND,
; DEFINES ADD. SIGNED MULTIPLY
.ELSE
MOV.B &OPER1,&MPYS ; LOAD 1ST (BYTE) OPERAND,
; DEFINES ADD. SIGNED MULTIPLY
SXT
&MPYS
; EXPAND BYTE TO SIGNED WORD DATA
.ENDIF
.IF OPERAND2=0
MOV
&OPER2,&OP2
; LOAD 2ND (WORD) OPERAND AND
; START SIGNED MULTIPLICATION
.ELSE
MOV.B &OPER2,&OP2
; LOAD 2ND (BYTE) OPERAND,
SXT
&OP2
; RE–LOAD 2ND OPERAND AND START
; SIGNED ‘FINAL’ MULTIPLICATION
.ENDIF
**********************************************************
*
EXAMPLE TO ADD THE RESULT OF THE HARDWARE
*
*
MULTIPLICATION TO THE RAM DATA, 64 BITS
*
**********************************************************
ADD
&RESLO,&RAM
; ADD LOW RESULT TO RAM
ADDC &RESHI,&RAM+2 ; ADD HIGH RESULT TO RAM+2
ADDC &SUMEXT,&RAM+4 ; ADD SIGN WORD TO EXTENSION WORD
ADDC &SUMEXT,&RAM+6 ; IF 64 BIT LENGTH IS USED