Saving and restoring general register contents
A program should save the values contained in the general registers when it starts to run 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 GETVIS, FREEVIS, and CDLOAD, it must first save the contents of register 13 and then load the address of an 18-fullword save area into register 13. This save area is in the program and is used by any subprograms or operating system services called by the program.
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.
Name Operation Operand
BEGIN SAVE (14,12)
USING BEGIN,15
⋮
ST 13,SAVEBLK+4
LA 13,SAVEBLK
⋮
L 13,SAVEBLK+4
RETURN (14,12)
SAVEBLK DC 18F'0'
⋮
END