14 Software Examples
14 – 8
quadrant.
The routine that implements this sine approximation, accurate to within
two LSBs, is shown in Listing 14.3. This routine accepts input values in
1.15 format. The coefficients, which are initialized in data memory in 4.12
format, have been adjusted to reflect an input value scaled to the
maximum range allowed by this format. On this scale, 180˚ equals the
maximum positive value, 0x7FFF, and –180˚ equals the maximum
negative value, 0x8000.
The routine shown in Listing 14.3 first adjusts the input angle to its
equivalent in the first quadrant. The sine of the modified angle is
calculated by multiplying increasing powers of the angle by the
appropriate coefficients. The result is adjusted if necessary to compensate
for the modifications made to the original input value.
.MODULE
Sin_Approximation;
{
Sine Approximation
Y = Sin(x)
Calling Parameters
AX0 = x in scaled 1.15 format
M3 = 1
L3 = 0
Return Values
AR = y in 1.15 format
Altered Registers
AY0,AF,AR,MY1,MX1,MF,MR,SR,I3
Computation Time
25 cycles