Chapter Contents |
Previous |
Next |
Communication with Assembler Programs |
This is a
simple example of a C
main
program that calls an assembler routine named
SUMINT
. This example is
used as the main driver function for Sample Assembler Routine Using CENTRY and CEXIT and Calling a C Library Function from Assembler.
Sample C main Program
#include <stdio.h> #include <stdlib.h> #include <options.h> /* Function Declaration for the assembler routine */ extern _ _asm int sumint(int *, ...);/* Note: */ /* 1) _ _asm keyword will build */ /* a VL-format parameter list.*/ /* If the last argument is */ /* a pointer, the high order*/ /* bit of byte 0 will be set*/ /* on. SUMINT expects all */ /* arguments to be pointers */ /* to int. */ /* */ /* 2) Usage of the ellipsis */ /* to indicate a variable */ /* length parameter list */ /* should be expected. */ /* The following demonstrates how to specify runtime options in */ /* in source code. They are not required for the proper execution */ /* of the C#ASM sample. */ extern int _options = _VERSION + _BTRACE + _USAGE + _WARNING; int main () { int h = 1; int i = 2; int j = 3; int k = 4; int sum = 0; /* Returned value */ int check_sum; /* Check variable */ int retcode = 0; /*---------------------------------------------------------------*/ /* First Time with 2 argument pointers to int */ /*---------------------------------------------------------------*/ sum = sumint(&h, &i); /* Note: Args passed by reference. */ printf("\n\nVariable Length with 2 arguments, " "the sum of %d and %d is %d\n", h, i, sum); check_sum = h+i; if (sum == check_sum) /* Verify Sum is corrrect.*/ { printf("\nSum of %d was correct.\n", sum); retcode = 0; } else { printf("\nSum of %d was NOT CORRECT!.\n", sum); printf("It should have been %d!\n",check_sum); retcode = 12; }; /*---------------------------------------------------------------*/ /* Second Time with 4 argument pointers to int */ /*---------------------------------------------------------------*/ sum = sumint(&h, &i, &j, &k); /* Note: Args passed by reference. */ printf("\n\nVariable Length with 4 arguments, " "the sum of %d, %d, %d and %d is %d\n", h, i, j, k, sum); check_sum = h+i+j+k; if (sum == check_sum) /* Verify Sum is correct.*/ {printf("\nSum of %d was correct.\n", sum);} else { printf("\nSum of %d was NOT CORRECT!\n.", sum); printf("It should have been %d!\n",check_sum); retcode = 12; }; exit(retcode); }
Sample Assembler Routine Using CENTRY and CEXIT is a simple example of an assembler routine that returns the sum of integers to its caller. Since no functions are called from the assembler routine and no automatic storage is needed, the CENTRY and CEXIT macro parameter DSA=0 defines a function with small automatic storage requirements.
Sample Assembler Routine Using CENTRY and CEXIT
EJECT PRINT ON,GEN SUMINT@ CSECT CREGS USING SPACE SUMINT CENTRY INDEP=NO,DSA=0 *---------------------------------------------------------------------* * Make sure we actually got a plist address on the call. * *---------------------------------------------------------------------* SR R3,R3 Clear R3 for sum'ing LTR R1,R1 Is there a plist? BZ DONE Nope, just leave w/R3=0! SPACE *---------------------------------------------------------------------* * Sum integers passed via VL-format parameter list. * *---------------------------------------------------------------------* SR R3,R3 Clear R3 for summing NEXTADD DS 0H L R4,0(R1) Load pointer A R3,0(R4) Add integer to sum TM 0(R1),X'80' End of VL-Plist? <---Note This Check BNZ DONE Yes, finish up and exit LA R1,4(R1) No, bump to next argument B NEXTADD Start again DONE DS 0H Yes, prepare to return SPACE *---------------------------------------------------------------------* * Exit with the sum of the integers provided to CEXIT in R3. * *---------------------------------------------------------------------* CEXIT RC=(R3),INDEP=NO,DSA=0 EJECT *---------------------------------------------------------------------* * Constants * *---------------------------------------------------------------------* LTORG Area for Literal Pool *---------------------------------------------------------------------* * Working Storage * *---------------------------------------------------------------------* COPY DSA Required for CENTRY/CEXIT *---------------------------------------------------------------------* * Dsects * *---------------------------------------------------------------------* COPY CRAB Required for CENTRY/CEXIT END SUMINT
Sample C main Program Calling a CICS Assembler Application and CICS Assembler Application Routine are examples of a C
main
program calling an assembler
routine that issues an EXEC CICS READ command. The assembler routine is
passed a file key as a parameter; it then returns a pointer to the record
that was read. The EXEC CICS command is translated into an invocation of
the DFHECALL macro. This macro uses a work area to build a parameter list
to pass to CICS. Storage for the parameter list is allocated in the DSA.
Sample C main Program Calling a CICS Assembler Application
#pragma options copts(dollars) #include <stdio.h> void main() { void *readrec(); struct DFH$AFIL { char filea [0] ; char filerec [0] ; char stat; char numb [6] ; char name [20] ; char addrx [20] ; char phone [8] ; char datex [8] ; char amount [8] ; char comment [9] ; } *dfh$afil; dfh$afil = readrec("111111"); if (!dfh$afil) printf(" read failed\ n"); else printf(" %.20s\ ", dfh$afil->name); }
CICS Assembler Application Routine
*ASM XOPTS(NOPROLOG NOEPILOG) READREC@ CSECT CREGS USING Register equates. READREC CENTRY DSA=DSALEN Generate C prolog. SPACE L R3,0(,R1) Point to passed parameter. SPACE EXEC CICS ADDRESS EIB(R4) SPACE USING DFHEIBLK,R4 Establish EIB addressability. SPACE EXEC CICS READ FILE('FILEA') SET(R15) RIDFLD(0(,R3)) RESP(RC) SPACE CLC RC,DFHRESP(NORMAL) Check command response code. BE RETURN Branch if OK. L R15,CRABZERO Else return null. SPACE RETURN CEXIT RC=(15) Return pointer to record or null. SPACE DROP R4 end of EIB addressability EJECT COPY DSA DFHEIPL DS 20F used by DFHECALL macro for parm list DFHEITP1 DS F used by DFHECALL for return info RC DS F EXEC CICS command response code DSALEN EQU *-DSA EJECT COPY CRAB CRAB control block map EJECT DFHEIBR EQU 0 COPY DFHEIBLK EIB map SPACE 2 END
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.