Example: Simple floating point number lookup using NVEM0

This example is for a lookup table with single floating point entries. Given a number in X, we want to read out the X'th byte from the table (which just happens to be a table of sines, where X is in degrees). Because all addressing starts at 0, X=0 will access the first value in the table, i.e. the number 1, X=1, will access the 2nd entry (3) etc.

The table uses NV0fNum directives, one per line, with floating point arguments. Each entry takes 4 bytes, the amount of memory used by SPLat for floating point numbers.

The code is very similar to the previous example, that extracts single-byte table entries. Note though that the record length is set to 4. The required record is otherwise targeted in the same way, by setting the pointer and the record length and popping the record number.

A floating point number cannot be held in X so we use the NVfReadW instruction to fetch the data from the table and place it in the floating point register W. NVfReadW has an argument, in this case 0, that specifies an offset in bytes into a record.

Code:
    NVSetPtr       Table   ;Get to start of table
    NVSetRecLen    4       ;Needed so offset is calculated correctly
    NVPopRecNum            ;Set the record number
    NVfReadW       0       ;Get the result

     .... continue ...

    NVEM0   ;===== End of code, Start of NVEM0 data

table:
    NV0fNum         0.0
    NV0fNum         1.74524E-2
    NV0fNum         3.48995E-2
    NV0fNum         5.23360E-2
    NV0fNum         6.97565E-2
    NV0fNum         8.71557E-2