HLASM Programmer's Guide
Previous topic | Next topic | Contents | Contact z/OS | Library | PDF


Saving and restoring general register contents

HLASM Programmer's Guide
SC26-4941-06

A program should save the values contained in the general registers when it receives control and, on completion, restore these same values to the general registers. Thus, as control is passed from the operating system to a program and, in turn, to a subprogram, the status of the registers used by each program is preserved. This is done through use of the SAVE and RETURN system macro instructions.

Saving Register Contents: The SAVE macro instruction should be the first statement in the program. It stores the contents of registers 14, 15, and 0 through 12 in an area provided by the program that passes control. When a program is given control, register 13 contains the address of an area in which the general register contents should be saved.

If the program calls any subprograms, or uses any operating system services other than GETMAIN, FREEMAIN, ATTACH, and XCTL, it must first save the contents of register 13 and then load the address of an 18-fullword save area into register 13.

Restoring Register Contents: At completion, the program restores the contents of general registers 14, 15, and 0 through 12 by use of the RETURN system macro instruction (which also indicates program completion). The contents of register 13 must be restored before issuing the RETURN macro instruction.

Example: The coding sequence that follows shows the basic process of saving and restoring the contents of the registers. A complete discussion of the SAVE and RETURN macro instructions and the saving and restoring of registers is contained in the z/OS MVS Programming: Assembler Services Guide.
Name      Operation      Operand

BEGIN     SAVE           (14,12)
          USING          BEGIN,15
          ⋮
          ST             13,SAVEBLK+4
          LA             13,SAVEBLK
          ⋮
program function source statements
          ⋮
          L              13,SAVEBLK+4
          RETURN         (14,12)
SAVEBLK   DC             18F'0'
          ⋮
          END

Go to the previous page Go to the next page




Copyright IBM Corporation 1990, 2014