Jim Giel

Coding for the MAC (Multiply-Accumulate Unit)

Discussion created by Jim Giel on Mar 5, 2008
Latest reply on Mar 5, 2008 by Jim Giel
Hi, I'm using CodeWarrior V7.0, IDE version 5.9.0, targetting the MCF52211 on the M52211EVB.  I'm looking at doing 32-bit multiplication for a project I'm working in, so I've been looking at using the MAC assembly instructions.  Specifically, the "mac.l" instruction.
 
Here is part of the code I put together to try this out:
 
  long data = 0x2000000;
  long mult = 0x2000000;   
  long product = 0;
  
  asm {
    move.l  #0,acc
    move.l  data,d0
    move.l  mult,d1
    mac.l    d0,d1
    move.l  acc, d1
    move.l  d1,product
  }   
  
  
When I execute this, I get a zero as the result.  MACSR is 0x06, indicating both zero and overflow.  (When I use numbers that produce a result that is less than 32 bits, I get the correct result.) 
 
In section 4.3.1.1 of the MCF52211 ColdFire Integrated Microcontroller Reference Manual, Rev.2, it says that rounding can occur when "Execution of a MAC (or MSAC) instruction with 32-bit operands. If MACSR[R/T] is zero,multiplying two 32-bit numbers creates a 64-bit product truncated to the upper 32 bits; otherwise, it is rounded using round-to-nearest (even) method."
 
Why doesn't my result get truncated to a 32-bit value?
 
I also noted that in Chapter 5 of the ColdFire Family Programmer's Reference Manual, Rev.3, it says that the product, shifted as defined by the scale factor, to the the accumulator.  Do I need to do this in order to truncate the 64-bit result?
How do I specify the scale factor to make the 32-bit shift?  
 
I tried changing the mac instruction to the following:
 
mac.l d0,d1,11
mac.l d0,d1 11
mac.l d0,d111
mac.l d0,d1 L
mac.l d0,d1L
 
but all produced assembly errors.
 
 

Outcomes