14
Software Examples
14 – 9
}
.VAR/DM
sin_coeff[5];
.INIT
sin_coeff : 0x3240, 0x0053, 0xAACC, 0x08B7, 0x1CCE;
.ENTRY
sin;
sin:
I3=^sin_coeff;
{Pointer to coeff. buffer}
AY0=0x4000;
AR=AX0, AF=AX0 AND AY0;
{Check 2nd or 4th quad.}
IF NE AR=-AX0;
{If yes, negate input}
AY0=0x7FFF;
AR=AR AND AY0;
{Remove sign bit}
MY1=AR;
MF=AR*MY1 (RND), MX1=DM(I3,M3);
{MF = x2}
MR=MX1*MY1 (SS), MX1=DM(I3,M3);
{MR = C1x}
CNTR=3;
DO approx UNTIL CE;
MR=MR+MX1*MF (SS);
approx:
MF=AR*MF (RND), MX1=DM(I3,M3);
MR=MR+MX1*MF (SS);
SR=ASHIFT MR1 BY 3 (HI);
SR=SR OR LSHIFT MR0 BY 3 (LO);
{Convert to 1.15 format}
AR=PASS SR1;
IF LT AR=PASS AY0;
{Saturate if needed}
AF=PASS AX0;
IF LT AR=-AR;
{Negate output if needed}
RTS;
.ENDMOD;
Listing 14.3 Sine Approximation
14.6
SINGLE-PRECISION MATRIX MULTIPLY
The routine presented in this section multiplies two input matrices: X, an
RxS (R rows, S columns) matrix stored in data memory and Y, an SxT
(S rows, T columns) matrix stored in program memory. The output Z, an
RxT (R rows, T columns) matrix, is written to data memory.
The routine is shown in Listing 14.4. It requires a number of registers to be
initialized, as listed in the “Calling Parameters” section of the initial
comment. SE must contain the value necessary to shift the result of each
multiplication into the desired format. For example, SE would be set to
zero to obtain a matrix of 1.31 values from the multiplication of two
matrices of 1.15 values.