Assist Question



High Level Assembler(HLASM) for MVS & VM & VSE

Re: Assist Question

Postby steve-myers » Wed Oct 22, 2014 4:26 pm

D(X,B)

This is the common notation in Principles of Operation for the computation of a storage address for a group of instructions collectively call RX instructions. D is 12-bit displacement, or offset, X and B refer to 32-bit registers. If X or B or 0, the register is not used. In RX instructions, the contents of the two registers are added together, and the 12-bit displacement is then added to the sum to compute a storage address.

The Assembler USING instruction establishes a storage location that is used as a base register to simplify most common addresses. For example -
         USING BASE,10
         L     5,DATA
         ...
BASE     CSECT
         DS    XL12
DATA     DS    F
The USING instruction tells the Assembler that register 10 has the address of BASE, so when it encounters DATA used as an address it can automatically compute the offset - 12 in the example to form D(X,B) as 12(0,10). Now this is important. You - as a programmer - must put the address in the base register before it is used. The Assembler cannot do this.

Most of my programs start off with some combination of instruction similar to this.
PROGRAM  CSECT
         USING *,12
         SAVE  (14,12),,*
         LR    12,15
         LA    15,SAVEAREA
         ST    13,4(,15)
         ST    15,8(,13)
         LR    13,15
The * in the USING instruction is a short hand for "the current value of the location counter." I am telling the Assembler that register 12 contains the current address of the location counter. Now there is something implied here. Register 15 contains the address of the program when it is entered. In fact, the SAVE macro depends on this. Similarly, register 14 contains the address of the instruction to execute when your program is finished, and register 13 contains the address of 72 bytes of storage the new program can use as a register save area. Your program is expected to restore registers 2 through 14 to the contents they had when your program was called before it returns to the program that called your program. If your program calls another program, it must prepare a register save area for use by the new program.

SAVE is a system macro instruction provided by IBM. It provides 2 things. At a minimum, it saves the registers in the save area provided by the calling program, and it provides for an identification. The listing looks like this -
          SAVE  (14,12),,* 
+         B     12(0,15)   
+         DC    AL1(7)     
+         DC    CL7'PROGRAM'
+         STM   14,12,12(13)
The + indicates the line was created by a macro.

The B instruction branches around the identification to the STM instruction to actually save the registers.

The LR 12,15 instruction copies the contents of register 15 to register 12. Now we can actually use the base register. This is not the only way. Some programmers prepare a base register like this -

BASR 12,0
USING *,12

The BASR (or BALR) instruction is normally used to call another program, BASR 14,15, for example. BASR stores the address of the next instruction in the first register. Then, if the second register is not 0, it uses the address in the register to define the next instruction to execute.

The next 4 instructions prepare a new save area for use. What we are actually doing is more complex than setting up register 13 to point to the new save area. Properly speaking, the save area is in two linked lists. The first list, at offset 4 in the save area allows your program to back track the save areas. By using the address at offset 8 a program such as the system dump program can go through the save areas.

There is one more wrinkle.

Starting with z/OS 1.7, the High Level Assembler, Binder, the Binder''s version of the linking loader, and program fetch were altered to allow the use of the BRAS and BRASL instructions to call an external reference or a symbol in a different CSECT. When doing this it is not necessary to load the address of the entry point into register 15, so modules prepared to get control from the BRAS or BRASL instruction might define addressability like this -
PROGRAM  CSECT
         BASR  15,0
         USING *,12
         SAVE  (14,12),,*
         LR    12,15
The BASR (or BALR) 15,0 instruction is required before the SAVE macro so the B instruction has addressability.

These users thanked the author steve-myers for the post:
Susansuth (Thu Oct 30, 2014 10:38 am)
steve-myers
Global moderator
 
Posts: 2105
Joined: Thu Jun 03, 2010 6:21 pm
Has thanked: 4 times
Been thanked: 243 times

Re: Assist Question

Postby Susansuth » Thu Oct 30, 2014 10:38 am

This is very helpful! Thank you very much for the explanation and detail! I really appreciate it!

Susan
Susansuth
 
Posts: 15
Joined: Tue Oct 07, 2014 8:36 am
Has thanked: 9 times
Been thanked: 0 time

Previous

Return to Assembler

 


  • Related topics
    Replies
    Views
    Last post