Table Example 4: Maintaining Precision - Motorola CPU32 Reference Manual

Hide thumbs Also See for CPU32:
Table of Contents

Advertisement

The first column is the value passed to the subroutine, the second column is the value
expected by the table instruction, and the third column is the result returned by the
subroutine.
The following value has been calculated for independent variable X:
31
NOT USED
Since X is an 8-bit value, the upper four bits are used as a table offset and the lower
four bits are used as an interpolation fraction. The following results are obtained from
the subroutine:
Table Entry Offset → Dx [4:7] = $B = 11
Interpolation Fraction → Dx [0:3] = $D = 13
Thus, Y is calculated as follows:
If the 8-bit value for X were used directly by the table instruction, interpolation would
be incorrectly performed between entries 0 and 1. Data must be shifted to the left four
places before use:
The new range for X is 0 ≤ X ≤ 4096; however, since a left shift fills the least significant
digits of the word with zeroes, the interpolation fraction can only have one of 16 values.
After the shift operation, Dx contains the following value:
31
NOT USED
Execution of the table instruction using the new value in Dx yields:
Table Entry Offset → Dx [8:15] = $0B = 11
Interpolation Fraction → Dx [0:7] = $D0 = 208
Thus, Y is calculated as follows:

4.6.4 Table Example 4: Maintaining Precision

In this example, three table lookup and interpolation (TLI) operations are performed
and the results are summed. The calculation is done once with the result of each TLI
rounded before addition and once with only the final result rounded. Assume that the
result of the three interpolations are as follows (a "." indicates the binary radix point).
MOTOROLA
4-192
16
15
Y = 80 + (13 (64 – 80)) / 16 = 67
LSL.W #4, Dx
16
15
Y = 80 + (208 (64 – 80)) / 256 = 67
INSTRUCTION SET
0 0 0 0 0 0 0 0 1 0 1 1 1 1 0 1
0 0 0 0 1 0 1 1 1 1 0 1 0 0 0 0
REFERENCE MANUAL
0
0
CPU32

Advertisement

Table of Contents
loading

Table of Contents