• Aucun résultat trouvé

THE TRANSLATE AND TEST INSTRUCTION AND THE EXECUTE INSTRUCTION

Dans le document A Programmer's Introduction to IBM System /360 (Page 105-108)

The Translate and Test instruction (TRT) adds great power to the processing capability of System/360. It is related to the Translate instruction and has the same format, but is very different in operation. It is used to scan a data field for characters with a special meaning. Since it merits our close attention, we shall study it in the three remaining programs in this chapter.

As with Translate, we work with a table as the second operand that is accessed exactly the same way. That is, a frrst operand argument byte addresses a particular entry in the table by an address computation. Once again the table must be in order by the binary sequence of the code of the source material, which in this and the following sections will be standard EBCDIC input. This time, however, we must put zeros in the table to indicate characters without any special meaning and some nonzero value for each character with a special meaning.

In further contrast to the Translate instruction, there is no change in the argument bytes as a result of the TRT operation, despite the "translate" in its name. Instead, the argument bytes are merely inspected, byte by byte, from left to right. If the first argument byte references a function byte that is zero, the next argument byte is inspected, and so forth. If all the function bytes that are referenced are zero, the condition code is set to zero and the operation is complete. However, if a nonzero function byte is refer-enced, the contents of that byte are placed by the machine in register 2 and the address of the argument byte is placed in register 1. The condition code is set to 1 or 2, and the operation is terminated. A condition code of 1 indicates that there are more function bytes t~ inspect, a condition code of 2 that the nonzero function byte is at the end of the field. The programmer may then make use of the information in the registers and in the condition code.

This means that we can inspect a complete stream of argument bytes, looking for whatever interests us: error characters, end-of-message codes, blanks and commas that separate parts of a line, or whatever. The following problem shows one way to use the instruction.

We are given the starting address of a string of characters of unknown length. The string contains an unknown num-ber of names and addresses. Each name is of unknown length; each address component is of unknown length;

there may be from one to four lines of address; we do not know how many names and addresses there are. All we do know is that after each "line" of information there is a dollar sign ($), after the last line of an address there are two dollar signs ($$), and at the end of the entire string there is a dollar sign followed by an asterisk ($*). We are required to set up each name and address in four lines named LINEl, LINE2, LINE3, and LINE4. Any unused lines must

manner, it is to be printed, after which we return to set up and print the next address.

The table required for this application must be 256 bytes in length in order to reference the complete range of EBCDIC binary values. It will consist of 254 zeros, with entries only in positions 5B (91) and 5C (92), corresponding to dollar sign and asterisk respectively. For the dollar sign we have chosen to enter 01 and for asterisk 02. These choices are highly arbitrary; as we shall see, any other two numbers would be just as good. All we need to know about the input stream is where the doll-ar signs and asterisks appear; we care nothing about any other characters.

The program in Figure 7-16 begins by placing in register 3 the address of the frrst character of the input stream that we shall break into names and addresses. On the assumption that there is only one such stream to process, this instruc-tion is never repeated in this program. The next instrucinstruc-tion is returned to each time another name and address is to be processed. It places a 4 in register 9 to be used as a guard against incorrect input streams; if ever a name and address would seem to require more than the four lines we have allotted, the program will stop. The next Load Address places in register 10 the address of th~ frrst line of the output. The next two instructions are

~ver1apping

Move Characters that clear to blanks the o.Btput areas. With assumed line lengths of 120 characters, this makes 480 bytes to clear. Since the maximum length in a Move Characters is 256 bytes, two instructions are needed, each clearing two lines. The first MVC instruction clears to blanks the first two lines and the first position of the third line. The second MVC instruction uses the blank now in the frrst position of the third line to blank the remaining positions of the third line and all of the fourth line.

Now we come to the Translate and Test. The fust operand starts at the address in register 3, which we set up with the starting address of the input stream; it is stated to be a maximum of 120 characters in length. The second operand address names the table. If the input stream is correct, a dollar sign will be found within 120 characters.

If, because of an error, there is no end-of-line dollar sign, we will have a condition code of zero at the completion of the execution of the instruction. A Branch on Zero, accordingly, takes us to an error exit (this could also be written asBC 8,ERROR).

In the normal case of finding a dollar sign to indicate the end of the first line, what do we have in the registers?

Register 1 contains the address of the dollar sign that stopped the Translate and Test. We wish to do a little arithmetic on this address without destroying it, so we move it to register 4. Now we subtract from the address of the dollar sign the address of the first character of the line. The

LOC OBJECT CODE AoDRl ADDR2 STMT SOURCE STATEMENT

~ CC03F9 OOOOOOOOOOOCOOOO 000401 0000000000000000

C. JACKSONS1234 MAIN STREETSCHICAGO,X ANoERSONSS53 MAPLE PLACE APARTMENT '

C'5CSWHITE PLAINS. NEW YORKSSD. D. ADAMS AND FAMILYS505 X GRATHSONSAPT. 3lSREADING, PENN.S*'

F'l'

Figure 7-16. A program to print names and addresses. The input stream contains an unknown number of names and addresses, each name and address contains a variable number of lines, and each line is of variable length.

ready to execute a Move Characters instruction in which we will use this computed address; but in the instruction itself the length code is always one less than the actual length. So we now subtract 1 from the difference residing in register 1.

What would it mean if this difference were now negative? We shall see, in further analysis of the program, that it would indicate the double dollar sign that denotes the end of a name and address. We therefore Branch on Minus (or BC 4) to OUT, where we would normally process the completed name and address.

Let us review the status of things. We have in register 3 the starting address of a group of characters that should be moved; in register 10 we have the address to which they should be moved; in register 1 we have the correct length code for a Move Characters instruction. We need either to place that length code in an instruction - or do something equivalent. "Something equivalent" is precisely what the Execute (EX) instruction provides. We say

EX 1,MVCINS

This means to execute the instruction at the second operand address named (MVCINS), after Or-ing together the last eight bits of register 1 and the length code portion of MVCINS. Looking down at MVCINS we see that a Move Characters instruction has been set up to do all the things just outlined as necessary, with the exception of the length.

The instruction set up at MVCINS says to move a group:Of bytes starting at the address given in register 3 to another location given by the address in register 10. Both displace-ments are zero, because the base addresses are exactly what are wanted. The length code is zero in the instruction; the actual length is supplied by the last eight bits of register 1.

One line of the complete name and address is thus moved to a printing position.

The Execute instruction is a very serviceable tool in the hands of a resourceful programmer, especially when it is used in a loop that deals with varying conditions. It is an unusual branching instruction that causes one instruction anywhere in a program to be executed out of sequence. Then, unless the remote instruction itself happens to be a successful branch, the program continues with the next instruction after the Execute. As we have seen, Execute can actually modify the remote instruction before execution. It can specify length codes, immediate data, register operands, or whatever information goes into the second byte in the format of the remote instruction. It does this by Or-ing with the last eight bits of a register, which the programmer may use to store information, do arithmetic, or whatever.

We will see further examples of the Execute instruction in the next two programs.

We are now about ready to go back for another look at the input stream. To do that, register 3 must contain the address of the next valid data character in the stream.

Register 4 contains almost what we need; it has the address

accordingly use a Load Address instruction to get the desired address into register 3. The instruction operates as follows. The displacement of one is added to the contents of the base register to get an effective address. (If an index register had been specified, its contents would also have been added in.) This address is then placed in register 3, with no actual reference to storage. It would have been legitimate to place the sum back in register 4, if that had been desired. Load Address provides a fast and simple way to add a small positive amount to a register.

In the next Load Address instruction we see register 10 being incremented by 120 by use of the method just described. The purpose is to set up the next line as the destination the next time around the loop. Finally we Branch on Count back to inspect the input stream again. If this . would mean trying for a fifth line, the branch is not taken and we reach the error exit.

At OUT, which we reach on discovering either two dollar signs in sequence or a dollar sign followed by an asterisk, we would normally include a series of instructions to print the output. Since input/output operations are outside the scope of this book, we simply indicate by a No-Operation instruction that this action would occur here in the program. NOPR is an extended mnemonic for Branch on Condition with a mask of zero, which never causes a branch to occur.

Following the output operations we are ready to go back for another name and address, unless this was the last one in the stream. Whether that was the case can be determined by looking at the function byte in register 2 to see whether it is that produced by a dollar sign or by an asterisk, that is, a lora 2 respectively. A comparison with ENDCON, which contains a 2 in proper form for a comparison with a fullword register, makes the determination. If the function byte is not that produced from an asterisk, we Branch on Not Equal back to AGAIN to repeat the whole process.

Otherwise we reach the normal exit from the program.

Figure 7-17 shows successive groups of output, based on the input stream assembled with the program.

SMITH DETROIT J. c. JACKSON 1234 MAIN STREET CHICAGO, ILLINOIS F.

c.

R. ANDERSON

553 MAPLE PLACE APARTMENT 5C WHITE PLAINS, NEW YORK D. D. ADAMS AND FAMILY 505 GRATHSON

APT. 31 READING, PENN.

Figure 7-17. Four names and addresses produced by the program in

AN ASSEMBLER APPLICATION OF TRANSLATE AND

Dans le document A Programmer's Introduction to IBM System /360 (Page 105-108)