Rev. 1.50, 10/04, page 257 of 448
10.1.29 MAC.W (Multiply and Accumulate Word): Arithmetic Instruction
Format Operation Instruction Code Cycle T Bit
MAC.W @Rm+,@Rn+
MAC @Rm+,@Rn+
Signed,
(Rn) × (Rm) + MAC →MAC
Rn + 2 → Rn, Rm + 2 → Rm
0100nnnnmmmm1111 4 —
Description: This instruction performs signed multiplication of the 16-bit operands whose
addresses are the contents of general registers Rm and Rn, adds the 32-bit result to the MAC
register contents, and stores the result in the MAC register. Operands Rm and Rn are each
incremented by 2 each time they are read.
If the S bit is 0, a 16 × 16 + 64 → 64-bit multiply-and-accumulate operation is performed, and the
64-bit result is stored in the linked MACH and MACL registers.
If the S bit is 1, a 16 × 16 + 32 → 32-bit multiply-and-accumulate operation is performed, and the
addition to the MAC register contents is a saturation operation. In a saturation operation, only the
MACL register is valid, and the result range is limited to H'80000000 (minimum value) to
H'7FFFFFFF (maximum value). If overflow occurs, the LSB of the MACH register is set to 1.
H'80000000 (minimum value) is stored in the MACL register if the result overflows in the
negative direction, and H'7FFFFFFF (maximum value) is stored if the result overflows in the
positive direction
Notes: If the S bit is 0, a 16 × 16 + 64 → 64-bit multiply-and-accumulate operation is performed.
Operation:
MACW(long m, long n) /* MAC.W @Rm+,@Rn+ */
{
long tempm,tempn,dest,src,ans;
unsigned long templ;
tempn = (long)Read_Word(R[n]);
R[n] += 2;
tempm = (long)Read_Word(R[m]);
R[m] += 2;
templ = MACL;
tempm = ((long)(short)tempn*(long)(short)tempm);
if ((long)MACL>=0) dest = 0;
else dest = 1;