MAC Instructions
  • All DSP MAC instructions are single cycle
  • All support pre-fetch, some support accumulator write-back
  • Operations can be performed on ACCA (A) or ACCB (B)
Instruction Description Operations Write-Back
CLR Clear Accumulator A = 0 YES
ED Euclidean Distance A = (Wm-Wn)2 NO
EDAC ED and Accumulate A = A + (Wm-Wn)2 NO
MAC Multiply and Accumulate A = A + (Wm*Wn) YES
MAC Square and Accumulate A = A + (Wm)2 NO
MOVSAC Move from X & Y bus no effect on A YES
MPY Multiply to Accumulator A = (Wm*Wn) NO
MPY Square to Accumulator A = (Wm)2 NO
MPY.N Negative Multiply to Acc. A = -(Wm*Wn) NO
MSC Multiply and Subtract A = A - (Wm*Wn) YES

Here is a list of the various instructions of the MAC class:

  • The ED or “Euclidean Distance, no accumulate” instruction subtracts the 2 operands, squares the difference, and places the result in the accumulator.
  • The EDAC or “Euclidean Distance” instruction subtracts the 2 operands, squares the difference, and adds the result to the old contents of the accumulator. This is used in Euclidean Distance calculations, and is very beneficial for Pattern Recognition applications.
  • Besides the usual functionality described in previous pages, the MAC instruction can also be used to square a single data word and add the result to the old contents of the accumulator.
  • The MOVSAC or “Move Special Accumulator” instruction simply pre-fetches a pair of words from memory, without modifying the contents of the accumulator.
  • The MPY or “Multiply” instruction replaces the old contents of the accumulator with the current product.
  • The MPY.N or “Multiply and Negate” instruction is similar to MPY except that the result of the multiplication is negated.
  • The MSC or “Multiply and Subtract” instruction is similar to MAC except that the result of the multiplication is negated before accumulation.
  • Suitable combinations of the above instructions are instrumental in enabling efficient implementation of many DSP algorithms, as well as reducing code size.

MAC Instruction Syntax

ColorSyntax.png

This picture shows the syntax of a MAC instruction. Note that only the source operand registers and the destination accumulator are mandatory arguments, whereas the other arguments are optional. To summarize, the following operations may be performed in a single instruction cycle:

  • 2 data fetches - one each from X and Y data space
  • 2 updates to the X and Y effective addresses used for the data fetch operations
  • 1 operation on Accumulator A or B with the data in two W-registers
  • 1 write back of the “other” accumulator, which is Accumulator B in this example

Instruction Examples

InstructionExample1.png

Typically, the Accumulator A or B is cleared in the beginning using a CLR instruction, while simultaneously fetching 2 data words from memory, one from X space and one from Y space. These 2 data words, which are 0x1111 and 0x2222 in this example, get placed in the specified pair of W registers, W4 and W5 in this case, in preparation for the MAC operation. Then, one or more MAC instructions may be executed in a loop.

InstructionExample2.png

During each MAC, the 2 data words pre-fetched in the previous MAC or CLR instruction are multiplied with each other. The product, 0x2468642, is added to the old contents of the accumulator. Simultaneously, the next pair of words, 0x3333 and 0x4444, are pre-fetched into W4 and W5, to be used as source operands by the next MAC instruction in the code sequence or loop. After the data is fetched, the pointers W8 and W10 are advanced to point to the next word in the array.

© 2016 Microchip Technology, Inc.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.