360 Assembly/360 Instructions/USING

The USING pseudo-instruction is used to inform the assembler of the contents of various registers which are to be used in base-displacement addressing. It does not generate any executable instructions, it provides information to the assembler.

The format for the USING pseudo-instruction is:


 * USING address,register1[,register2[,...]]

Register1 can be any of the general purpose registers 1 through 15. It tells the assembler that this register has been loaded with the address specified as the first parameter. Because many instructions - including branch instructions - treat register 0 as a non-action or containing the actual value 0, register 0 should not be used for this purpose. A second (or subsequent) register, indicated by the parameter register2 optionally provides a second base register, and is presumed to contain the address of the first parameter plus 4096. Each subsequent register, if specified, is presumed by the assembler tocontaino the address 4096 above the address specified in the preceding register

Example: PROG     START 0          BALR  12,0          USING *,12,11          LA    11,4095(12)          LA    11,1(11) In the above example, the USING pseudo-instruction tells the assembler that register 12 is established as the base register for the first 4096 bytes of this module, and that register 11 is established for the second 4096 bytes. After register 12 has been loaded with the current address through the BALR instruction, register 11 is loaded with the address 4096 bytes later in the program. Note that this uses the older LA instruction, which cannot add more than 4095 to the value contained in a register, so two LA instructions must be used. While this combination of instructions will work on all models of IBM hardware as well as competitor's equipment, later versions of IBM hardware such as the z/Series provide more efficient instructions for this purpose.

If a specific location is addressed by more than one register, the assembler may become confused and issue an MNOTE level 4 (warning) because it is not sure which register to use, in which case it uses the highest numbered register pointing to the address in question. However, if the using addresses of two or more registers overlap, the assembler will choose the register resulting in the lowest displacement address generated. The following example will demonstrate. This example is from an assembler listing.

Here is how the program was assembled.
 * On line 13, the branch is to hexadecimal adderss 8C in the program (label START), and in the instruction, It is assembled as 45F0806C, where 45 is the hexadecimal opcode of the BAL instruction, F being register 15, the first 0 indicating no Index register was used, and 806C is a base-displacement address of hexadeciaml address 08C plus the address in register 8, which was used because of the USING pseudo-instruction on line 10.
 * On line 29, the instruction is assembled as 4150D4C0 where 41 is the LA instruction, the 5 means register 5 is the target register to be loaded, the first 0 again indicating no Index register was used, and {{mono|D4C0|| is used indicating that the address is {{mono|4C0}} hexadecimal bytes plus the address in register 13. This is correct, as {{mono|ITEM}} is located at hexadecimal address {{mono|4dc8}} in the program. The assembler uses register 13 because the using statement on line 21 places the displacement in register 13 as 8 bytes closer to {{mono|ITEM}} than register 8.
 * Similarly, for the instructions on lines 31-33, the address in Register 13 is "closer" to (the (displacement is less) than register 8, so register 13 is used.
 * The instructions on lines 35-37 tell the assembler that registers 2-4 point to these locations.
 * On lines 39-41, since the assembler has been told each of these registers points to the item that they are being told to load the address, in each case, that register has a displacement of 0 from the target address, so that register (with an offset of 0) is used.
 * On line 43, the assembler was told register 3 is the same address as {{mono|ITEM}}, so the assembler uses register 3 with a displacement of 0. Compare this to the identical instruction on line 29, where the address in register 13 produces the smallest displacement, so it was used rather tan register 8.

Here is an example of an inline subroutine which sets up a temporary base register for the subroutine. {{360 Assembly/Example 95}} As the above example stated, the USING pseudo-instruction tells the assembler that a specific register contains the specified address, while the DROP pseudo-instruction tells the assembler that register can no longer be used, until it is specified in another USING pseudo-instruction.

By convention
 * Operating systems often use register 0 and 1 in Supervisor Calls and expect values or address of a list of values to be provided using one or both of these registers; they are also often used (sometimes along with register 15) to return result values from Supervisor Calls. For this reason, register 1 should not be used as a base register in an executable code section, but is acceptable to reference a DSECT mapping labels to the displacement from Register 1.
 * Some operating systems and certain instructions may provide or use Register 2 and/or Register 15, so care should be taken if Register 2 or 15 is used as the base register in an assembly language module that issues supervisor calls or macros that issue supervisor calls.
 * The Linux operating system on the 390/zSystem hardware uses registers 1 through 6 for arguments, so these registers should not be considered to remain the same or be usable after a supervisor call on S/390 Linux.
 * Register 13 is often used as a pointer to an 18-word register save area (for programs running in 24 or 32 bit mode), so it should only be used for this purpose. If the program is not calling any subroutines and saves the value of register 13 on entry, and restores it on exit, register 13 may be used for any purpose. However, if register 13 is being used for some other purpose where it is not pointing to a save area, this should be documented in the program so that anyone doing maintenance on the program in the future is not confused by this practice. Note, register 13 can be used for other purposes such as to point to a rewritable area (such as for reentrant programs that dynamically acquire memory) or for anything else, as long as the first 18 words it points to are available as a register save area.
 * Register 14 is often used as the return address for the program to exit back to the caller (or the operating system if the program is not a subroutine). If the program saves register 14 on entry, and restores it on exit, register 14 may be used for any purpose.
 * Register 15 is typically provided as the entry point of the program, and thus is acceptable as the USING register; only if the program must itself call a subroutine, then it must establish a different register as its base register. However, some operating systems also use register 15 in addition to registers 0 and 1 to return values, so it may be best not to use register 15 as a base register if the routine issues supervisor calls or macros that issue supervisor calls.

Address can be * for the current program counter, or it can be a label in the current module, or a label plus a value. This allows the assembler to know which base register to use for references to addresses in the current module. It may also be used when referencing a DSECT to assign to labels used in the DSECT a base/displacement address.

A main program (i.e. not a subroutine which has a base register loaded by the caller) would use the BALR or BASR instruction to load the contents of a base register, then issue a USING pseudo-instruction to inform the assembler that the particular register was available as a base register.

{{360 pseudo}}

{{BookCat}} {{360 footer}}