Examples
List of Examples
- WTO
- VTOC OBTAIN
- Date Routines
- Data Set Name Edit
- Quicksort
- Hash Table
- Print Routine
- Catalog Search Inerface
- Data In Virtual
- VSMLIST - Virtual Storage Information
- Pseudorandom Number Generator (PRNG)
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.
#pragma export(writeMsg)
#include <string.h>
extern void writeMsg(int lenMsg, char *msg)
{
struct WTO_Parm
{
short int len;
short int mcsflags;
unsigned char message[100];
};
unsigned char wrkArea[512];
struct WTO_Parm Msg;
memset(&Msg,0,sizeof(Msg));
Msg.len = lenMsg+4;
Msg.mcsflags = 0;
strcpy(Msg.message,msg);
__asm(" WTO MF=(E,(%0))"
:
: "r"(&Msg) // input definition
: "r0","r1","r14","r15"); // clobber list
}
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.
- The called routine is named "writeMsg", which is aliased.
- The NAB is calculated by pointing to the end of this program's NAB.
- After execution the message "+Test Message WTO" is displayed on the console.
TESTEX01 CSECT
TESTEX01 AMODE 31
TESTEX01 RMODE ANY
WRITEMSG ALIAS C'writeMsg'
Print Gen
J @OFFSET
DC AL2(8)
DC CL8'TESTEX01'
DC CL9'&SYSDATE'
DC CL6'&SYSTIME'
@OFFSET DS 0H
Save (14,12)
LR R12,R15
Using TESTEX01,R12
LGFI R3,65536*2
STORAGE OBTAIN,LENGTH=(R3),LOC=31
St R13,4(,R1)
LR R13,R1 Point to our DSA
Using DSA,R13
St R0,0(,R1) Save DSA Length
LAB0100 DS 0H
LR R2,R13 Calculate NAB
AHI R2,DSALen Move past end of this storage
ST R2,8(,R13) Addr of Next Available Byte (NAB)
MVC message,=CL100'Test Message WTO'
LA R3,message
ST R3,Parm2
LHI R4,L'message
ST R4,Parm1
LA R1,parmList
L R15,=V(WRITEMSG)
BASR R14,R15
L R13,4(,R13) Restore Caller's DSA Pointer
L R14,12(R13) Restore R14
LM R0,R12,20(R13)
BR R14 Return to Caller
DSA DSECT
SaveArea DS 18F
message DS CL100
parmList DS 0FD
Parm1 DS F
Parm2 DS F
DSALen Equ *-DSA
End TESTEX01
References
- z/OS MVS Programming: Assembler Services Reference, Volume 2 (IAR-XCT) Chapter 109. WTO- Write to operator
- z/OS Metal C Programming Guide and Reference
- z/OS XL C/C++ Language Reference
All references copyright© IBM Corporation.