• Aucun résultat trouvé

THE USING INSTRUCTION

Automatic computation of the addresses of all operands in main storage requires the programmer to supply two items of information to the assembler and one to the object program.

With the USING instruction, the programmer tells the assembler:

1. Which general registers may be used as base registers 2. What each one will contain at the time the object program is executed

With this information the assembler can do its work of designating base registers and computing displacements.

I t still remains to place in the base registers the values we have promised the assembler will be there. This can in principle be done in many ways, but the most common is to use the Branch and Link Register instruction (BALR).

The general format of this instruction is:

BALRR1,R2

Rl receives the address of the next byte after the BALR;

R2 supplies a branch address unless it is zero, in which case

possible to delegate to the assembler almost all the clerical work of keeping track of base registers and computing displacements. With a full understanding of these tech-niques, the programmer is able to leave the housekeeping to the assembler where appropriate, and to employ more sophisticated methods where needed.

In this chapter we shall see how the automatic tech-niques are called into operation and how the assembler implements them, and we will explore a few sHghtly more advanced techniques. As in so many other aspects of programming, particular emphasis mu st be placed on the question of when various actions occur: during assembly, linkage editing, or program execution.

the next instruction in sequence is taken as usual. For OUI

purposes here, the second operand (R2) is always zero. For instance, in the illustrative program we shall be considering shortly, we have an instruction:

BALR 11,0

This places in register 11 the address of the next byte after the BALR, and there is no branch. Register 11 was arbitrarily chosen as the base register for this program. It is used as a base register for most of the programs in this text.

In actual practice, the choice of a base register cannot be a completely arbitrary one. As mentioned earlier, most instal-lations find it necessary to establish rather rigid conventions for register usage. In addition, the various operating systems for System/360 make use of certain general registers for supervisor routines, linkages between separate programs, and other purposes. Under most operating systems, registers 2 through 11 are freely available to the programmer and should be used to avoid any complication.

AN EXAMPLE

These ideas may be made more concrete by considering an example. Figure 4-1 is an assembly listing of a program the processing details of which do not concern us.

The START instruction specifies that the assembled first byte of the program is location 25610= 10016 • We see that the BALR instruction has in fact been placed at 100. (All numbers in the object program area of the assembly listing - on the left-hand side - are hexadecimal.) The BALR instruction specifies that general purpose register 11 is to be loaded with the address of the next machine instruction.

This, of course, is done at execution time by the machine.

The USING instruction, which is an assembler instruction and takes no space in the object program, informs the assembler that general purpose register 11 is available for use as a base register and will contain the address of the next machine instruction, as signified by the asterisk. The BALR is a two-byte instruction so the next instruction, the Load, is placed at 102. This number, shown in the location counter column in the USING statement, indicates what the assembler assumed would be the contents of base register 11.

Let us look at the Load instruction to see how the assembler handled it. Reading from left to right the opera-tion code is 58, the register loaded with a word from 12C, which is the address of the symbol TEN.

The Shift Left Algebraic instruction is a little different. not the case and we need a base register designation of zero.

We see that this was done. The effective address is therefore just the displacement of 1. The remainder of the program presents no new base register concepts.

As always, it is most important to distinguish between what is done at assembly time and what is done at execution time. The assembler, in the example at hand, has filled in base register numbers where needed and has com-puted displacements. These base register numbers and displacements become part of the actual instructions, as listed down the left side of the assembly listing. In carrying out the assembly operations, the assembler had to know what base register we wished to use and what we planned to put in it; this information we provided with the USING.

The assembler cannot load the base register for the execution of our program, since that can be done only when the program is executed. We therefore provided the BALR instruction, which, at execution time, places the address of the next instruction into the specified register.

The remainder of the program can now be carried out, with effective addresses being developed as intended.

The assembler program is actually processed in several separate phases. One of its functions is to determine the length· and location of each instruction, area, and constant.

STATEMENT

While doing this, the assembler constructs a symbol table.

As shown in Figure 4-2, this lists for each symbol used in the program: its length in bytes, either its value or location (VALUE), the number of the statement in which it is defined (DEFN), and all statements in which it is referenced. With the length and location of each instruction and the base register information provided by the program-mer in the USING instruction, the assembler is able, in a later phase, to calculate the base register and displacement and to list these and the actual assembled addresses of all operands as they appear in Figure 4-1.

In our program, we said with the START instruction that the first byte of the program should be assembled at location 25610

=

10016 . Everything said so far has assumed that the program will actually be loaded at 10016 . This is not so. In the first place, this location is within the low area of main storage that is occupied by the supervisor and other parts of the control program, and could not be used for program execution. Parenthetically, it should be explained that START 256 is not a standard programming practice.

We have chosen it for the examples in the first few chapters of this book to cause our assemblies to begin at some positive value, simply for illustrative purposes. The usual practice is to specify a zero START, which greatly simpli-fies the programmer's chore of calculating addresses, a necessity when debugging a program.

The second reason that our program will not be loaded at location 10016 is that, regardless of the location we give in the START statement, our assembled object program is in relocatable form and it is not executable until processed by the linkage editor. The linkage editor is an IBM service program that is part of the operating or programming support system.

The linkage editor assigns the actual starting address in main storage for each object program in a job input stream, and edits these into executable programs. It uses infor-mation supplied by the assembler regarding the length of

the program, its name (given in the START statement, PROGE in this case), the assembled locations of any relocatable address constants, and other details necessary to perform the relocation.

When the program is in executable form, all statements, constants, reserved storage spaces, etc., remain in the same relative positions as in the assembly listing. Nothing needs to be changed to make the object program operate correctly from the new location or, at a later time, from still another location. All that is involved is the relocation factor.

Suppose the linkage editor assigns location 320016 as the starting address. When the program has been loaded, it begins with execution of the BALR instruction. Now, what is the address of the next instruction after the BALR? The answer is 3202. This value goes into register 11 and becomes the base address. The displacements in the assembled instruc-tions have not changed, of course. The effective address in the Load instruction is now 3202 + 22 = 3224. With the new starting location, 3224 is exactly where DATA appears. All other addresses are correctly computed as well, including the "address" in the Shift, which is completely unchanged since no base register is used.

I t is also possible for the programmer by use of a control card to i~ll the linkage editor which starting location to assign. A ·complete relocation of the program after assembly is thus a simple matter. In more complex program struc-tures, the linkage editor has more work to do than this example'might suggest, but it is nevertheless feasible to execute programs from whatever storage locations may be convenient and available under any particular set of circumstances.

As we have noted, this simplicity of program relocation was one of the reasons for providing base registers in System/360.

The techniques of program relocation and the functions of the linkage editor will be discussed in more detail in the chapter on· subroutines and program relocation.

CROSS-REFERENCE

SYMBOL LEN VALUE DEFN

BEGIN 00002 000100 00003 0023 BINl 00004 000134 00020 0010 BIN2 00004 000138 00021 0011 DAT A 00004 000124 00016 0005 0008 DEC 00008 000140 00022 0012 PROGE 00001 000100 00002

RESULT 00004 000130 00019 0009 TEN 00004 00012C 00018 0006

NO STATEMENTS FLAGGED IN THIS ASSEMBLY

Figure 4-2. Symbol cross-reference table constructed and listed by the assembler for the assembly in Figure 4-1