IBM Metal C

Examples

List of Examples

  1. WTO
  2. VTOC OBTAIN
  3. Date Routines
  4. Data Set Name Edit
  5. Quicksort
  6. Hash Table
  7. Print Routine
  8. Catalog Search Inerface
  9. Data In Virtual
  10. VSMLIST - Virtual Storage Information
  11. Pseudorandom Number Generator (PRNG)

All Examples in Zip File

Example 1. WTO

This first example is a trivial program in C to take a message and message length, passed by the caller, and invoke a WTO with the message. The code of special interest in this example is the "__asm" statement, which injects assembler statements into the generated assembler code. The "%0" in the WTO statement is a placeholder similar to a C format specifier in a printf statement. The text following the assembler statements are the contraints. The first ":" in the statement defines the beginning of the output constraints. In this example there are no output constraints, but the ":" must still be specified as a placeholder. The text after the second ":" is the input constraint, in this case, instructing the compiler to load into a register the address of the memory operand "Msg". The text after the third ":" is called the "clobber list". It tells the compiler what registers not to use.

Compiling the example yields HLASM code, which is shown below. The compiler generated a WTO and substituted R2 for the input specifier "%0".

 
         TITLE '5694A01 V1.13 z/OS XL C                           "DEVEX
               L.ATLJP.C(WRITEMSG)"'
.* The HLASM GOFF option is needed to assemble this program
         ACONTROL AFPR
WRITEM#C CSECT
WRITEM#C AMODE 31
WRITEM#C RMODE ANY
         SYSSTATE ARCHLVL=2
         IEABRCX DEFINE
@@CCN@1  ALIAS C'writeMsg'
* #include 
* #pragma export(writeMsg)
* extern void writeMsg(int lenMsg, char *msg)
         J     @@CCN@1
@@PFD@@  DC    XL8'00C300C300D50000'   Prefix Data Marker
         DC    CL8'20141121'           Compiled Date YYYYMMDD
         DC    CL6'093942'             Compiled Time HHMMSS
         DC    XL4'410D0000'           Compiler Version
         DC    XL2'0000'               Reserved
         DC    BL1'01000000'           Flag Set 1
         DC    BL1'00000000'           Flag Set 2
         DC    BL1'00000000'           Flag Set 3
         DC    BL1'00000000'           Flag Set 4
         DC    XL4'00000000'           Reserved
         ENTRY @@CCN@1
@@CCN@1  AMODE 31
         DC    XL8'00C300C300D50100'   Function Entry Point Marker
         DC    A(@@FPB@1-*+8)          Signed offset to FPB
         DC    XL4'00000000'           Reserved
@@CCN@1  DS    0F
         STM   14,3,12(13)
         LR    15,13
         L     13,8(,13)
         ST    15,4(,13)
@@BGN@1  DS    0H
         USING @@AUTO@1,13
         LARL  3,@@LIT@1
         USING @@LIT@1,3
         ST    1,80(,13)               #SR_PARM_1
         USING @@PARMD@1,1
         L     14,@2lenMsg
* {
*
*    struct WTO_Parm
*    {
*       short    int len;
*       short    int mcsflags;
*       unsigned char message[100];
*    };
*
*    struct WTO_Parm Msg;
*
*    memset(&Msg,0,sizeof(Msg));
         XC    @5Msg,@5Msg
         L     15,@3msg
         LA    1,@5Msg+4
         LA    0,0
*
*    Msg.len           = lenMsg+4;
         AHI   14,4
*    Msg.mcsflags      = 0;
         MVHHI 86(13),0
         STH   14,84(,13)              _a1_d84_l2_
*    strcpy(Msg.message,msg);
@@LAB@1  MVST  1,15
         BRO   @@LAB@1
         LA    2,@5Msg
*
*         __asm(" WTO  MF=(E,(%0))"
         WTO   MF=(E,(2))
*         :
*         : "r"(&Msg)                      // input  definition
*         : "r0","r1","r14","r15");        //  clobber list
*  }
@1L1     DS    0H
         DROP
         L     13,4(,13)
         L     14,12(,13)
         LM    1,3,24(13)
         BR    14
         DS    0F
@@LIT@1  LTORG
@@FPB@   LOCTR
@@FPB@1  DS    0F                      Function Property Block
         DC    XL2'CCD5'               Eyecatcher
         DC    BL2'1111000000000011'   Saved GPR Mask
         DC    A(@@PFD@@-@@FPB@1)      Signed Offset to Prefix Data
         DC    BL1'00000000'           Flag Set 1
         DC    BL1'10000000'           Flag Set 2
         DC    BL1'00000000'           Flag Set 3
         DC    BL1'00000000'           Flag Set 4
         DC    XL4'00000000'           Reserved
         DC    XL4'00000000'           Reserved
         EJECT
@@AUTO@1 DSECT
         DS    48F
         ORG   @@AUTO@1
#GPR_SA_1 DS   18F
         DS    F
         ORG   @@AUTO@1+84
@5Msg    DS    XL104
         ORG   @@AUTO@1+80
#SR_PARM_1 DS  XL4
@@PARMD@1 DSECT
         DS    XL8
         ORG   @@PARMD@1+0
@2lenMsg DS    F
         ORG   @@PARMD@1+4
@3msg    DS    F
         END   ,(5694A01   ,1D00,14325)

The code to execute this example is shown below.

References

  1. z/OS MVS Programming: Assembler Services Reference, Volume 2 (IAR-XCT) Chapter 109. WTO- Write to operator
  2. z/OS Metal C Programming Guide and Reference
  3. z/OS XL C/C++ Language Reference

All references copyright© IBM Corporation.