Texas Instruments MSP430x1xx User Manual
Page 96
Hardware Multiplier Operation
6-8
6.2.4
Multiply Signed and Accumulate, 16x16bit, 16x8bit, 8x16bit, 8x8bit
********************************************************************
* TRANSFER BOTH OPERANDS TO THE REGISTERS IN THE HARDWARE *
* MULTIPLIER MODULE *
* USE CONSTANT OPERAND1 AND OPERAND 2 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
MAXMACS
.EQU
32H
;NUMBER OF MACS FUNCTIONS WHICH COULD
;BE EXECUTED TILL AN OVERFLOW OR UNDERFLOW
;COULD OCCUR THE FIRST TIME
.BSS
OPER1,2,200H
.BSS
OPER2,2
.BSS
RAM,8
.BSS
MCOUNT,2
.IF OPERAND1=8
MOV.B
&OPER1,&MACS
; LOAD 1ST OPERAND,
; DEFINES ADD. UNSIGNED MULTIPLY
SXT
&MACS
; EXPAND BYTE TO SIGNED WORD DATA
.ELSE
MOV
&OPER1,&MACS
; LOAD 1ST OPERAND,
; DEFINES ADD. UNSIGNED MULTIPLY
.ENDIF
.IF OPERAND1=8
SXT
&OPER2
; OPER2 MEMORY LOCATION NEEDS
; 2 BYTES
MOV.B
&OPER2,&OP2
; LOAD 2ND OPERAND AND START
; MULTIPLICATION
.ELSE
MOV
&OPER2,&OP2
; LOAD 2ND OPERAND AND START
; MULTIPLICATION
.ENDIF
********************************************************************
* EXAMPLE TO ADD THE RESULT OF THE HARDWARE MULTIPLICATION *
* TO THE RAM DATA IF NECESSARY *
* THE RESULT OF THE MULTIPLICATION IS HELD IN RESLO AND *
* RESHI REGISTERS. THE UPPER TWO WORDS IN THE EXAMPLE ARE *
* FURTHER LOCATED IN THEIR RAM LOCATION *
********************************************************************
INC
MCOUNT
; INC MACS COUNTER
CMP
#MAXMACS,MCOUNT
; ONLY ADD TO RAM IF NECESSARY
JNE
NEXTMACS
;
ADDC
&RESLO,&RAM+0
; ADD SUMEXTENSION TO RAM+0
ADDC
&RESHI,&RAM+2
; ADD SUMEXTENSION TO RAM+2
ADDC
&SUMEXT,&RAM+4
; ADD SUMEXTENSION TO RAM+4
ADDC
&SUMEXT,&RAM+6
; IF 64 BIT LENGTH IS USED
CLR
MCOUNT
NEXTMACS
. . .