CS-220, Sec. 90, Week 8-C
R. Eckert

TABLE LOOKUP

The 80x86 instruction set includes an instruction that allows us to
perform table lookup. The instruction is XLAT, and it takes no operands.

You must first load the offset part of the start address of the table
into BX register. You then load AL with the position of the byte you want
in the table and invoke the XLAT instruction. The byte stored at the
specified position in the table will be in AL register after the
instruction executes. In other words, the instruction does the equivalent
of the following:

                  AL <--- [AL+BX]

EXAMPLE: A TABLE OF ASCII CODES FOR HEXADECIMAL DIGITS (an alternative to
computing the ASCII codes as we've done in the past);;

DATA       SEGMENT
HA_TABLE   DB       '0123456789ABCDEF'   ;This generates the table
H_DIGIT    DB       7                    ;Assume we want the ASCII
                                         ; code for a 7
ASC_DIGIT  DB       ?                    ;Store ASCII code here
DATA       ENDS

CODE       SEGMENT
           ASSUME   DS:DATA,CS:CODE
MAIN       PROC     FAR
;***bookkeeping instructions go here***
           MOV      BX,OFFSET HA_TABLE   ;Offset of table
           MOV      AL,H_DIGIT           ;Position of table entry
           XLAT                          ;Now AL contains ASCII code
           MOV      ASC_DIGIT,AL         ;Store it
           RET
MAIN       ENDP
CODE       ENDS
           END      MAIN