IBM Metal C

Compiler

Linkage. Calling a Metal C Program

Calling a Metal C program from an assembler program depends on the amode of the called Metal C program. For more details about linkage conventions consult: z/OS Metal C Programming Guide and Reference©, Chapter 1. About IBM z/OS Metal C.

For AMODE 31

For AMODE 64

To pass a parameter by reference, specify a pointer of the type to be passed in the function prototype. For any addressing mode, integer type values are returned in GPR 15. For AMODE 31 a 64-bit integer value is returned in GPR 15 + GPR 0.

NAB linkage extension

Metal C code uses the dynamic storage area (DSA) as stack space. Each time a function is called, its prolog code acquires this space and upon return releases it. To avoid excessive overhead from acquisition and release operations, Metal C uses an upward growing stack or next available byte (NAB) for the DSA. All Metal C runtime library functions expect the NAB address to be set by the calling function.

If a routine is a main routine, then the prolog code for the routine will perform a STORAGE OBTAIN for its DSA, and a STORAGE RELEASE upon termination.

Example of NAB

Below is an example of the usage of the NAB. Before calling the Metal C routine, in this case getDate, the calling program needs to calculate the NAB. This program uses the first byte after its own DSA, whose size is overallocated at 65K. The calling program stores the NAB at offset 8 in its own save area.

In the prolog code for the called route, getDate, the Metal C code loads the NAB from offset 8 from R13, the caller's DSA. The caller's DSA (R13) is saved at offset 4 in the called routine's DSA, and restored upon return from the routine. If a called routine, in turn, calls another Metal C routine, then the same convention of NAB calculation and retrieval is performed by the calling and called routine.

References

  1. z/OS Metal C Programming Guide and Reference
  2. z/OS XL C/C++ Language Reference

All references copyright© IBM Corporation.