Now.going back to the structure of an Assembler program, remember these points.
- The initial contents of the registers.
- Before your program exits, it must restore the contents of any registers it altered, except as noted in the next bullet.
- Many times, register 15 is used as a return code.
These bullets lead us to this famous utility, though it is more commonly known by another name.
YF CSECT
SR 15,15
BR 14
END YF
Except for register 15, it does not alter any registers, so it does not have to restore any registers.
Now, in the real world, a program has to use registers to do anything, so real world programs save registers in the register save area supplied by the caller, and restore the registers before the program returns.
YF CSECT
SAVE (14,12),,YF-&SYSDATE-&SYSTIME
RETURN (14,12),RC=0
END YF
SAVE and RETURN are macros provided by IBM. The (14,12) are just the registers to save or restore. The YF-&SYSDATE-&SYSTIME in the SAVE macro is just a character string the macro inserts into the program that serves as a program identifier. &SYSDATE and &SYSTIME represent the date and time the Assembler processed the program, and are a convenient method to locate the program in storage and verifying the correct version of the program is in storage. RC=0 in the RETURN macro directs the macro load 0 into register 15.
Now, if your program is going to use other programs, or use any of the common I/O macros, it must prepare a register save area for the other programs to use -
YF CSECT
SAVE (14,12),,YF-&SYSDATE-&SYSTIME
BALR 12,0
USING *,12
LA 15,SAVEAREA
ST 13,4(,15)
ST 15,8(,13)
LR 13,15
L 13,4(,13)
RETURN (14,12),RC=0
SAVEAREA DC 9D'0'
DCBD DSORG=QS,DEVD=DA
END YF
Huh!? Doesn't register 13 already point to a register save area?
Yes, but the SAVE macro stored registers in that save area. If some other program then stores your registers in the save area the ability of your program to properly return to the calling program is impaired.