360 Assembly/360 Instructions/TRT
TRT - SS - Opcode DD - Scan a data string, looking for 1 or more specific characters.
The TRT instruction scans a field, looking for specific bytes. TRT does not change any data. The D1 field contains the address of the data to be scanned. The D2 field contains the address of a 256 byte table where each byte contains either X'00' or a non-zero byte, at the offset in the HEX table of the byte being searched for. TRT sets the condition code, indicating whether the object character(s) was found.
The TRT instruction is available on all models.
TRT changes both registers 1 and 2. TRT is the only instruction that changes reg-2 as part of the operation, so if you use TRT, then don't use reg-2 as your base.
Purpose of Instruction
The TRT instruction searches for specific bytes. For example, if you wanted to find the next occurrence either of C'D' or C'K', you would code:
TRT DATA,SRCHTBL BZ NOTFOUND
SRCHTBL DC XL256'00'
ORG SRCHTBL+C'D' DC X'04' ORG SRCHTBL+C'K' DC X'08' ORG
Condition code, etc.
- If no character is found, the condition code is set to 0.
If a character is found:
- The scanning terminates
- Register 1 indicates the address of the data character found.
- The the byte in the scan table that was non-zero is placed into the low byte of reg-2. The remaining bytes of reg-2 are not changed. This is the only instruction that changes register 2 without reg-2 being specified.
- If the character that is found is the last character of the scanned field, the condition code is set to 2; otherwise, it is set to 1.
Translate and test is implemented in micro code. Checks one byte at a time until either it finds a byte, or the data being scanned is exhausted.
Exceptions and Faults
Protection Exception - the source or the target is outside of the legal address range assigned to this task
Example looking for a non-blank on a print line.
TRT LINE,NONBLANK BZ ALLBLANK
- REG-1 CONTAINS ADDRESS OF NON-BLANK CHAR
NONBLANK DC 256C' '
ORG NONBLANK+C' ' DC X'00' ORG
Example testing a packed field.
SR 2,2 TRT PACKDATA,TRTPACK TEST THE PACKED FIELD WITH 'C', 'D', OR 'F' SIGN BC 2,GOODDATA IF ANY SIGN '0A' - '0F' IS GOOD, USE THIS. B BRTBL(2) TO RESTRICT SIGNS TO '0C' '0D' AND '0F', USE THIS.
BRTBL B NOTFOUND
B GOODDATA B BADSIGN B BADDATA
TRTPACK DC 256X'0C'
ORG TRTPACK DC 10X'00',XL6'080804040804',10X'00',XL6'080804040804' ORG TRTPACK+X'20' DC 10X'20',XL6'080804040804',10X'00',XL6'080804040804' ORG TRTPACK+X'40' DC 10X'40',XL6'080804040804',10X'00',XL6'080804040804' ORG TRTPACK+X'60' DC 10X'60',XL6'080804040804',10X'00',XL6'080804040804' ORG TRTPACK+X'80' DC 10X'80',XL6'080804040804',10X'00',XL6'080804040804' ORG
TR is slightly related, although it's function is very different.