First page Back Continue Last page Overview Graphics
Laboratory 4.2 Search in a table
Start a new project.
Write a program to determine the index of a number in a look-up table. In particular, use the following table.
table: dc.b $eb,$77,$7b,$7d,$b7,$bb,$bd,$d7
val: ds.b 1
Your program should end at the same memory location (use a NOP instruction) whether a match is found or not.
The data in the table should be stored as a list of bytes as shown above. Use indexed addressing and start the index at 0. Your program should loop and compare the value stored in val with the values in the table. If a match is found, it should drop out of the loop and put the number of the index in accumulator A. For example if a $dd is in val a 9 should be put into accumulator A. Your program must stop searching when the last entry in the table is checked. If no match is found, put an $ff in the accumulator. Use the debugger and try various values for val to verify that the program works properly.
Save this project. This module will be used later in a program to read a keypad.