In the discussion of the return under Analyzing the return, it was indicated that the control section returning control must restore the contents of registers 2-14. Because these are the same registers reloaded when control is passed without a return, refer to the discussion under “Passing Control without Return” for detailed information and examples. The contents of registers 0 and 1 do not have to be restored.
Register 15 can contain a return code when control is returned. As indicated previously, a return code should be a multiple of four with a return code of zero indicating a normal return. The return codes other than zero that you use can have any meaning, as long as the control section receiving the return codes is aware of that meaning.
The return address is the address originally passed in register 14; you should always return control to that address. If an addressing mode switch is not involved, you can either use a branch instruction such as BR 14, or you can use the RETURN macro. An example of each of these methods of returning control is discussed in the following paragraphs. If an addressing mode switch is involved, you can use a BSM 0,14 instruction to return control. See Figure 1 for an example that uses the BSM instruction to return control.
.
.
L 13,4(13) Load address of previous save area
L 14,12(13) Load return address
SR 15,15 Set register 15 to zero
IC 15,STATUSBY Load number of errors
SLA 15,2 Set return code to multiple of 4
LM 2,12,28(13) Reload registers 2-12
BR 14 Return
.
.
STATUSBY DC X'00'
The RETURN macro saves coding time. The expansion of the RETURN macro provides instructions that restore a designated range of registers, load a return code in register 15, and branch to the address in register 14. If T is specified, the RETURN macro flags the save area used by the returning control section (that is, the save area supplied by the calling routine). It does this by setting the low-order bit of word four of the save area to one after the registers have been restored. The flag indicates that the control section that used the save area has returned to the calling control section. The flag is useful when tracing the flow of your program in a dump. For a complete record of program flow, a separate save area must be provided by each control section each time control is passed.
You must restore the contents of register 13 before issuing the RETURN macro. Code the registers to be reloaded in the same order as they would have been designated for a load-multiple (LM) instruction. You can load register 15 with the return code before you write the RETURN macro, you can specify the return code in the RETURN macro, or you can reload register 15 from the save area.
.
.
L 13,4(13) Restore save area address
L 14,12(13) Return address in register 14
SR 15,15 Zero register 15
IC 15,STATUSBY Load number of errors
SLA 15,2 Set return code to multiple of 4
RETURN (2,12),RC=(15) Reload registers and return
.
.
STATUSBY DC X'00'
.
.
L 13,4(13)
RETURN (14,12),T,RC=8