/*--------------------------------------------------------------------------- tblllkup.asm - Table Lookup with Interpolation ----------------------------------------------------------------------------- Description: Performs a Table Lookup with Interpolation to approximate f(x) from a table of values. The interpolation formula used is: x - X0 f'(x) = { ( F[X+1] - F[X] ) * ( ------ - X ) } + F[X] S where: x = input value x f'(x) = the approximation of f(x) Xi = the x value for the ith element in table F[i] = is the ith element of the table = f(Xi) exactly S = x spacing in the table X0 = x corresponding to F[0] X = floor (( x - X0 ) / S ) ----------------------------------------------------------------------------- Program Characteristics: Calling Values: f0 = x f7 = 1/S f15 = X0 i0 = start of table l0 = length of table m0 = 1 l1 = 2 Registers Altered: f1-f4, m1 MODE1 Register Bits: TRUNC = 1 Return Value: f1 = interpolated f(x) Computation Time = 11 cycles = 440ns @ 25MHz Note: 11 cycles includes the DAG hold after load of m1 register. ----------------------------------------------------------------------------- Author: Jim Donahue, Analog Devices DSP Division Revised: 19-AUG-91 ---------------------------------------------------------------------------*/ .GLOBAL tbllkup; #define X f0 /* s, the input value */ #define XF f2 /* (float) floor(X) */ #define X0 f15 /* F(0), first value in table */ #define IS f7 /* 1/S inverse of table stepsize in X */ #define IDX r3 /* (int) floor(X) */ #define INTRP f2 /* interpolation factor (F(i)-->F(i+1) */ #define FI f4 /* F(x) */ #define FI1 f1 /* F(x+1) */ #define RES f1 /* the interpolated result */ .SEGMENT /pm pm_code; tbllkup: X = X - X0, i0 = b0; X = X * IS; IDX = fix X; XF = float IDX, m1 = IDX; INTRP = X - XF, modify(i0,m1); FI = dm(i0,m0); FI1 = dm(i0,m0); rts (db), RES = FI1 - FI; RES = RES * INTRP; RES = RES + FI; .ENDSEG;