2135 views|2 replies

3836

Posts

19

Resources
The OP
 

MSP430 library hardware multiplier usage [Copy link]

Hardware introduction:
In the MSP430 series of microcontrollers, the hardware multiplier is a peripheral module, not part of the CPU core; so its activity is independent of the CPU activity, and its registers are read and written by CPU instructions like other peripheral registers.

The hardware multiplier module supports the following functions: unsigned multiplication, signed multiplication, unsigned multiplication-add, signed multiplication-add; it can support 16*16 16*8 8*16 8*8 bits multiplication.

The module block diagram of the hardware multiplier is as follows:

The four types of operations of the hardware multiplier module (unsigned multiplication, signed multiplication, unsigned multiply-add, and signed multiply-add) are determined by the position of the first operand written. This module has two operand registers: OP1 and OP2, and three result registers: RESLO, RESHI, and SUMEXT. The RESLO register stores the low word (lower 16 bits) of the result; the RESHI register stores the high word (upper 16 bits) of the result; and the SUMEXT register stores information about the result. The result is ready after 3 clock cycles; the next instruction after writing to OP2 can read the result, with one exception: when the result is accessed using indirect addressing. When the result is accessed using indirect addressing, a NOP instruction is required before reading the result.

Operand OP1 has four addresses (MPY:0130h MPYS:0132h MAC:0134h MACS:0136h). These four registers are used to select the multiplication operation mode. Writing to the first operand register determines which operation to use: unsigned uses signed, etc., but does not start the multiplication operation; writing to the second operand register starts the multiplication operation. After the calculation is completed, the result is stored in registers RESLO, RESHI, and SUMEXT.

The operations corresponding to the four addresses of operand 1 are:

OP1 Address Register Name Operation
0130h MPY Unsigned multiply (unsigned multiplication)
0132h MPYS Signed multiply (signed multiplication)
0134h MAC Unsigned multiply accumulate (unsigned multiplication and accumulation)
0136h MACS Signed multiply accumulate (signed multiplication and accumulation)
The contents of the high-order result register in the four operation modes are as follows:

Mode RESHI Contents
MPY Upper 16-bits of the result
MPYS The MSB is the sign of the result. The remaining bits are the upper
15-bits of the result. Two's complement notation is used for the result.
MAC Upper 16-bits of the result
MACS Upper 16-bits of the result. Two's complement notation is used for the result.
The contents of the four operating modes SUMEXT register:

Mode SUMEXT
MPY SUMEXT is always 0000h
MPYS SUMEXT contains the extended sign of the result
00000h Result was positive or zero
0FFFFh Result was negative
MAC SUMEXT contains the carry of the result
0000h No carry for result
0001h Result has a carry
MACS SUMEXT contains the extended sign of the result
00000h Result was positive or zero
0FFFFh Result was negative
During continuous multiplication operations, if operand 1 does not need to be changed for the operation, there is no need to rewrite the sum to save the same number; but OP2 must be rewritten to start the multiplication operation.

MACS Underflow and Overflow: The hardware multiplier does not detect overflow or underflow of the result of a signed multiplication and addition operation. The positive range of the result is: 0 to 7FFF FFFFh; the negative range is: 0FFFF FFFFh to 8000 0000h. Underflow is when the sum of two negative numbers is a positive number in the result register, and overflow is when the sum of two positive numbers is a negative number in the result register. The SUMEXT register stores the sign of the result, which can be used to determine whether there is an overflow (0000h for a negative sum, overflow; 0FFFFh for a positive sum, underflow). When using MACS, the program must properly detect and handle MACS overflow.

Program example (assembly example given in the user guide):

Examples for all multiplier modes are as follows. All 8x8 modes use absolute addresses for registers because the assembler will not allow B access to word registers when using the standard defined file labels.

; 16x16 Unsigned Multiply
MOV #01234h,&MPY ; Load first operand
MOV #05678h,&OP2 ; Load second operand
; ... ; Process results
; 8x8 Unsigned Multiply. Absolute addressing.
MOV.B #012h,&0130h ; Load first operand
MOV. B #034h,&0138h ; Load 2nd operand
; ... ; Process results
; 16x16 Signed Multiply
MOV #01234h,&MPYS ; Load first operand
MOV #05678h,&OP2 ; Load 2nd operand
; ... ; Process results
; 8x8 Signed Multiply. Absolute addressing.
MOV.B #012h,&0132h ; Load first operand
SXT &MPYS ; Sign extend first operand
MOV.B #034h,&0138h ; Load 2nd operand
SXT &OP2 ; Sign extend 2nd operand
; (triggers 2nd multiplication)
; ... ; Process results
; 16x16 Unsigned Multiply Accumulate
MOV #01234h,&MAC ; Load first operand
MOV #05678h,&OP2 ; Load 2nd operand
; ... ; Process results
; 8x8 Unsigned Multiply Accumulate. Absolute addressing
MOV.B #012h,&0134h ; Load first operand
MOV.B #034h,&0138h ; Load 2nd operand
; ... ; Process results
; 16x16 Signed Multiply Accumulate
MOV #01234h,&MACS ; Load first operand
MOV #05678h,&OP2 ; Load 2nd operand
; ... ; Process results
; 8x8 Signed Multiply Accumulate. Absolute addressing
MOV.B #012h,&0136h ; Load first operand
SXT &MACS ; Sign extend first operand
MOV.B #034h,R5 ; Temp. location for 2nd operand
SXT R5 ; Sign extend 2nd operand
MOV R5,&OP2 ; Load 2nd operand
; ... ; Process results
Although the above program is quite different from the standard assembly language, it is still easy for people with a certain level of assembly language knowledge to understand it. The program gives several ways to write to the operand register.

When addressing the result register indirectly, after writing the OP2 operand to start the multiplication, at least one instruction delay is required before accessing the result register RESLO, etc.; when addressing directly, after writing OP2, the next instruction can read the result. Sample program (assembly):

; Access multiplier results with indirect addressing
MOV #RESLO,R5 ; RESLO address in R5 for indirect
MOV &OPER1,&MPY ; Load 1st operand
MOV &OPER2,&OP2 ; Load 2nd operand
NOP ; Need one cycle A NOP is needed after writing two operands to start the multiplication operation
MOV @R5+,&xxx ; Move RESLO
MOV @R5,&xxx ; Move RESHIIf
an interrupt occurs between writing OP1 and writing OP2, the calculation mode of the source operand is lost after the interrupt response; the operation result is uncertain. To avoid this situation, disable interrupts when writing operands or do not use the hardware multiplier in the interrupt response function. For example:

; Disable interrupts before using the hardware multiplier
DINT ; Disable interrupts
NOP ; Required for DINT
MOV #xxh,&MPY ; Load 1st operand
MOV #xxh,&OP2 ; Load 2nd operand
EINT ; Interrupts may be enabled before
; Process results
That's all I have to say about the hardware part. If you don't understand anything, please refer to the user guide.

This post is from Microcontroller MCU

Latest reply

There should be a directly available library, otherwise you have to write assembly code to use it, which is very troublesome.   Details Published on 2020-9-28 21:20
 

2618

Posts

0

Resources
2
 

Learn more

This post is from Microcontroller MCU
 
 

7422

Posts

2

Resources
3
 

There should be a directly available library, otherwise you have to write assembly code to use it, which is very troublesome.

This post is from Microcontroller MCU
 
Personal signature

默认摸鱼,再摸鱼。2022、9、28

 
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list