The TRT instruction is used to search a block of bytes for one or more values. The format looks like this:
TRT D1(L,B1),D2(B2)
Here D1(B1) is the address of the variable we want to search, at least L bytes long, and D1(B2) is the address of a search table.
A search table is a table of 256 bytes, initialized as follows:
TRT examines the area to be searched, one byte at a time, and looks up the corresponding byte in the table. For instance, if a byte has the value X'48' (decimal 72), TRT looks at the byte in the table at an offset of 72. If that byte is not X'00', the search ends.
Example
Suppose we want to search for a question mark character (X'6F'). The search table we need would look like this:
QMTAB DC 256X'00' ORG QMTAB+X'6F' DC X'FF' ORG
We could use it like this:
XREAD BUFFER,80 TRT BUFFER(80),QMTAB
where BUFFER is 80 bytes long.
After the TRT: if we found a question mark, register 1 will contain the address of the first question mark character found in BUFFER, the rightmost byte of register 2 will contain the corresponding value from the table (X'FF' in this case), and the condition code will be set to 1 (or 2 if the blank was found at the very end of BUFFER).
If the TRT did not find a question mark character in BUFFER, the condition code will be set to 0.
Notes
The hardest part of using TRT is setting up the search table.
The second hardest part of using TRT is remembering that it can and will change the values in registers 1 and 2.
Suggested Exercises
What would the search table look like if we wanted to find: