System information
Instead of reading a number, the QUERY program reads an alphanumeric string that is a
particular key to find in the N A M E S . D A T data base. Because the L A S T N A M E . K E
Y list is sorted, one can find a particular entry rapidly by performing a binary search, similar to
looking up a name in the telephone book. Starting at both ends of the list, one examines the
entry halfway in between and, if not matched, splits either the upper half or the lower half for the
next search. You will quickly reach the item you are looking for and find the corresponding
record number. You should fetch and display this record at the console, 'ust as was done in the
program shown above.
With some more work, you can allow a fixed grouping size that differs from the 128-byte
record shown above. This is accomplished by keeping track of the record number and the byte
offset within the record. Knowing the group size, you randomly access the record containing the
proper group, offset to the beginning of the group within the record read sequentially until the
group size has been exhausted.
Finally, you can improve QUERY considerably by allowing boolean expressions, which
compute the set of records that satisfy several relationships, such as a L A S T NAME between
HARDY and LAUREL and an AGE lower than 45. Display all the records that fit this
description. Finally, if your lists are getting too big to fit into memory, randomly access key files
from the disk as well.
5.6 System Function Summary
Function Function Input Output
Number Name
Decimal Hex
0 0 System Reset C = 00H none
I 1 Console Input C = 01H A = ASCII char
2 2 Console Output E = char none
3 3 Reader Input A = ASCII char
4 4 Punch Output E = char none
5 5 List Output E = char none
6 6 Direct Console I/O C = 06H A = char or status
E = 0FFH (input) or (no value)
0FEH (status) or
char (output)
7 7 Get I/O Byte none A = I/O byte value
5.5 A Sample Random Access Program CP/M Operating System Manual
5-54