Sample Program Listing — Part 2
* Take the difference between the given angle and the known lower* angle by logically ANDing the given angle with three. Now take* the product of the two DELTA terms. MUL stores its product MSB* in the index register and LSB in the accumulator. lda THETA and #$03 mul* Because this product is always a small number, it will reside* only in the accumulator; the index register will be zero. Once* again, use the given angle to look up the cosine of the known* lower angle. Negating the accumulator and adding the cosine of* the known lower angle returns the cosine of the given angle. ldx THETA lsrx lsrx nega add COSINE_TABLE ,X sta THETA_COSINE
Notes:
As noted previously, the following relation is always true because the difference between any two adjacent known angles is always four.
0 £ (THETA - first known angle less than THETA) £ 3
Consequently, the difference between THETA and the first known angle less than THETA is simply THETA logically ANDed with three.
With the two terms that comprise DELTA now calculated, DELTA itself can be calculated by taking their product. The unsigned product returned by the MUL instruction is stored with the MSB in the index register and the LSB in the accumulator.
Because the maximum difference between any two cosine terms is nine, and is subsequently divided by four and multiplied by a number no greater than three, the DELTA product will always reside only in the accumulator.
Knowing this, THETA is again read to calculate the offset into the look up table of the first known angle less than THETA. DELTA is negated and added to (effectively subtracting it from) the cosine of the first known angle less than THETA. This is the interpolated cosine of THETA.