With
VS COBOL II,
assembler programs could invoke COBOL programs regardless of the AMODE specification.
For example:
Figure 1. Effect of AMODE for invoking programs
In the figure above, the following occurs:
- Program COBOLA dynamically calls AssemblerA.
(Assembler is AMODE 31.)
- AssemblerA loads COBOLB which is RENT,
DATA(24), and AMODE(24).
- AssemblerA BALRs to COBOLB. (Now, COBOLB
is entered in AMODE 31.)
- COBOLB returns to AssemblerA.
- AssemblerA calls AssemblerB.
- AssemblerB does a BASSM to COBOLB.
(COBOLB is entered in AMODE 24.)
- COBOLB abends because it expects to be entered in AMODE 31.
Under Language Environment,
COBOL programs compiled with VS COBOL II,
IBM COBOL, or Enterprise COBOL that
are invoked by assembler programs must be entered in the same AMODE each time
that they are called.
To avoid the abend in the example above:
- In Step 2, AssemblerA must save the AMODE.
- In Step 3, AssemblerA needs to BASSM to COBOLB instead
of BALR.
- In Step 4, AssemblerA needs to restore the AMODE saved
in Step 2.
If an assembler program that is AMODE 31 calls a COBOL program that is
AMODE 24, the assembler program must also be RMODE 24 in order for COBOL to
return to the assembler program. If the assembler program is AMODE ANY in
this case, an abend might result upon return from the COBOL program as a result
of branching to an address that is not valid. This is because R14 will contain
a 31-bit address from the assembler program's save area, but COBOL will return
to the assembler program in AMODE 24.