An alternative to linkage assist routines is a technique called capping. You can add a “cap” (prologue and epilogue) to a module to handle entry and exit addressing mode switching. The cap accepts control in either 24-bit or 31-bit addressing mode, saves the caller's registers, and switches to the addressing mode in which the module is designed to run. After the module has completed its function, the epilogue portion of the cap restores the caller's registers and addressing mode before returning control.
For example, when capping is used, a module in 24-bit addressing mode can be invoked by modules whose addressing mode is either 24-bit or 31-bit; it can perform its function in 24-bit addressing mode and can return to its caller in the caller's addressing mode. Capped modules must be able to accept callers in either addressing mode. Modules that reside above 16 megabytes cannot be invoked in 24-bit addressing mode. Capping, therefore, can be done only for programs that reside below 16 megabytes.
MYPROG CSECT
MYPROG AMODE ANY
MYPROG RMODE 24
USING *,15
STM 14,12,12(13) SAVE CALLER'S REGISTERS BEFORE SETTING AMODE
LA 10,SAVE SET FORWARD ADDRESS POINTER IN CALLER'S
ST 10,8(13) SAVE AREA
LA 12,MYMODE SET AMODE BIT TO 0 AND ESTABLISH BASE
LA 11,RESETM GET ADDRESS OF EXIT CODE
BSM 11,12 SAVE CALLER'S AMODE AND SET IT TO AMODE 24
USING *,12
MYMODE DS 0H
DROP 15
ST 13,SAVE+4 SAVE CALLER'S SAVE AREA
LR 13,10 ESTABLISH OWN SAVE AREA
_______________________________________________________________________
This is the functional part of the original module.
This example assumes that register 11 retains its
original contents throughout this portion of the program.
_______________________________________________________________________
L 13,4(13) GET ADDRESS OF CALLER'S SAVE AREA
BSM 0,11 RESET CALLER'S AMODE
RESETM DS 0H
LM 14,12,12(13) RESTORE CALLER'S REGISTERS IN CALLER'S AMODE
BR 14 RETURN
SAVE DS 0F
DC 18F'0'