Passing control

Figure 1 shows an example of loading registers and passing control. In this example, no new save area is used, so register 13 still contains the address of the old save area. It is also assumed for this example that the control section will pass the same parameters it received to the next entry point. First, register 14 is reloaded with the return address. Next, register 15 is loaded with the address of the external entry point NEXT, using the V-type address constant at the location NEXTADDR. Registers 0-12 are reloaded, and control is passed by a branch instruction using register 15. The control section to which control is passed contains an ENTRY instruction identifying the entry point NEXT.
Figure 1. Passing Control in a Simple Structure
          .
          .
          L   14,12(13)      LOAD CALLER'S RETURN ADDRESS
          L   15,NEXTADDR    ENTRY NEXT
          LM  0,12,20(13)    RETURN CALLER's REGISTERS
          BR  15             NEXT SAVE (14,12)
          .
          .
NEXTADDR  DC  V(NEXT)
Figure 2 shows an example of passing a parameter list to an entry point with the same addressing mode. Early in the routine the contents of register 1 (that is, the address of the fullword containing the PARM field address) were stored at the fullword PARMADDR. Register 13 is loaded with the address of the old save area, which had been saved in word 2 of the new save area. The contents of register 14 are restored, and register 15 is loaded with the entry address.
Figure 2. Passing Control With a Parameter List
         .
         .
         USING *,12           Establish addressability
EARLY    ST    1,PARMADDR     Save parameter address
         .
         .
         L     13,4(13)       Reload address of old save area
         L     0,20(13)
         L     14,12(13)      Load return address
         L     15,NEXTADDR    Load address of next entry point
         LA    1,PARMLIST     Load address of parameter list
         OI    PARMADDR,X'80' Turn on last parameter indicator
         LM    2,12,28(13)    Reload remaining registers
         BR    15             Pass control
         .
         .
PARMLIST DS    0A
DCBADDRS DC    A(INDCB)
         DC    A(OUTDCB)
PARMADDR DC    A(0)
NEXTADDR DC    V(NEXT)

The address of the list of parameters is loaded into register 1. These parameters include the addresses of two data control blocks (DCBs) and the original register 1 contents. The high-order bit in the last address parameter (PARMADDR) is set to 1 using an OR-immediate instruction. The contents of registers 2-12 are restored. (Since one of these registers was the base register, restoring the registers earlier would have made the parameter list unaddressable.) A branch register instruction using register 15 passes control to entry point NEXT.