Eecs.wsu.edu



EXPERIMENT ELEVEN:

LOOKUP TABLES

INTRODUCTION

Lookup tables are used for data conversion and also to access data that are in tabular form. Tabular data includes both numeric and alphabetic data in the form of character strings as well as in binary form. This experiment uses lookup tables to illustrate conversion from one code to another and also to lookup character string data. It also illustrates how a jump table accesses various software as required by some applications.

OBJECTIVES

1. Use a lookup table to convert from one numeric code to another.

2. Locate and display character string data located in a lookup table.

3. Use a lookup to obtain jump or call addresses for computed jumps or calls.

4. Search a table for information.

PROCEDURE

A lookup table is a group of data organized so it is easily accessed without searching. An example lookup table may contain information such as 7 segment code for numeric displays. Or it may contain EBCDIC (extended binary coded decimal interchange code) that is converted to ASCII through a lookup table. Neither of these codes can be converted by using a numeric technique such as conversion from ASCII to BCD (subtract 30H).

Suppose that alphabetic data must be encrypted as a different code. A lookup table could be used to store the encryption codes. Such a lookup table and a procedure that converts ASCII to the encrypted code appears in Example 11-1. Note that the ASCII-coded character in AL is converted to an entry from the table by using the XLAT (translate) instruction. The XLAT instruction adds the contents of AL to the contents of BX to form an address in the table. It then transfers a copy of the data at that address to the AL register. This software uses two encryption tables: the UTAB table encrypts uppercase letters and the LTAB table encrypts lowercase letters. The letters stored in the tables can be changed for different encryption codes. They could also be randomized occasionally for additional security. Of course this example may only be practical for developing anagrams or word scrambles for the newspaper. The XLAT instruction uses a segment override prefix to override the default segment (DS).

Example 11-1

UTAB DB 'MNBVCXZLKJHGFDSAPOIUYTREWQ'

LTAB DB 'bgtnhymjukilopvfrcdexswzaq'

ENCRP PROC NEAR ;encrypts AL to code in UTAB and LTAB

.IF AL >= 'A' && AL = 'a' && AL '1'

JMP MAIN2

.ENDIF

SUB AL,30H ;convert to binary

MOV BX,OFFSET LTAB

MOV AH,O

ADD AX,AX ;double AX

ADD BX,AX

JMP WORD PTR [BX]

EXIT:

MOV AX,4COOH ;exit to DOS

INT 21H

MAIN ENDP

CODE ENDS

END MAIN

STEP 5: Using a jump type lookup table, write a program that displays your name if a 1 is typed, displays your address if a 2 is typed, and displays your telephone number if a 3 is typed. If a 0 is typed, the program exits to DOS. After displaying your name, etc. the program should redisplay the menu. Make sure that the program accesses four different subprograms to accomplish these four tasks. If any other character is typed, it must be ignored. The prompt and menu displayed by the program must appear as follows:

Main Menu

0 - exit to DOS

1 – name

2 – address

3 - telephone number

Enter choice:

The jump lookup table is accessed by the JMP WORD PTR [BX] instruction in Example 11-4. This same type of program can be modified to call various procedures by changing the JMP instruction to a CALL instruction. If the CALL instruction is used, don't forget that a return will eventually return to the step following the call. This does not happen with the JMP instruction.

All the table lookup techniques discussed thus far have used direct lookup. The next portion of this experiment details tables searches. A table search is accomplished by using either the SCAS instruction to search for a byte, word, or double word entry, or the CMPS instruction to search for a multiple byte entry. The type of search is dictated by the data stored in the table.

Suppose that the data encrypted back in Example 11-1 must be decrypted. This can be accomplished by using the SCASB instruction to search through an uppercase and a lowercase table to locate an entry. When the entry is found, its relative position in the table is found in the DI register. Recall that SCASB searches an area of memory in the extra segment address by the DI register. See Example 11-5 for a procedure that decrypts the information encrypted by Example 11-1.

Example 11-5

UTAB DB 'MNBVCXZLKJHGFDSAPOIUYTREWQ'

LTAB DB 'bgtnhymjukilopvfrcdexswzaq'

DCRP PROC NEAR ;decrypts AL from the code in UTAB

;and LTAB

PUSH ES

PUSH CX

PUSH DI

MOV CX,CS

MOV ES,CX

CLD ;select autoincrement

MOV CX,OFFFFH ;load maximum count

.IF AL >= 'A' && AL '1' statement in Example 11-4?

11-7. Explain how the JMP WORD PTR [BX] instruction functions in Example 11-4.

11-8. Using the SCASB instruction write a procedure that skips over spaces found in the character string addresses by ES : DI . Note that this string is no more than 256 bytes in length.

11-9. Explain how Example 11-5 converts the encrypted uppercase letter B in AL into 43H (C).

11-10. What is the purpose of the REPNE prefix used with the SCASB instruction in Example 11-5?

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download