www.sas.com > Service and Support > Technical Support
 
Technical Support SAS - The power to know(tm)
  TS Home | Intro to Services | News and Info | Contact TS | Site Map | FAQ | Feedback


/*--------------------------------------------------------------------+
|                                                                     |
|                 Copyright (c) 1995, SAS Institute Inc.              |
|                   Unpublished - All Rights Reserved                 |
|                                                                     |
|                                                                     |
|                     S A S / C  S A M P L E                          |
|                                                                     |
| SampleName: ALOADMM                                                 |
|                                                                     |
|    Purpose: Demonstrate how to maintain a single C execution        |
|             framework in a C and assembler application.  Each       |
|             primary module in the ALOADM sample will display        |
|             the CRAB address it is using.                           |
|                                                                     |
|             If a single C framework has been properly created and   |
|             maintained, the CRAB address displayed by each module   |
|             should be exactly the same.                             |
|                                                                     |
|             There are three primary modules in this sample and      |
|             a single C function used by each primary module to      |
|             display the CRAB address.                               |
|                                                                     |
|             This sample has two independently executable            |
|             parts, some code is common to both parts:               |
|                                                                     |
|              Part 1:                                                |
|                 C main calling a statically linked assembler        |
|                 program using CENTRY(non-INDEP), and CEXIT.         |
|                 The assembler program then dynamically loads a      |
|                 C function compiled without INDEP.  This C function |
|                 is then called in a loop for several interations.   |
|                 When the loop is completed the assembler returns    |
|                 to the C main.                                      |
|                                                                     |
|                 Part #1 Information:  See Below                     |
|                                                                     |
|              Part 2:                                                |
|                 An assembler program using CENTRY(w/INDEP),         |
|                 and CEXIT.  The assembler program dynamically       |
|                 loads a C function compiled without INDEP.  The     |
|                 assembler prgoram calls the dynamically loaded      |
|                 C function in a loop for several iterations.  After |
|                 the loop has completed the assembler program        |
|                 terminates the C execution framework and exits.     |
|                                                                     |
|                 Part #2 Information:                                |
|                         - MVS see prefix.SAMPLE.ASM(ALOADMA)        |
|                         - CMS see SAMPLASM MACLIB(ALOADMA)          |
|                                                                     |
|             The modules in this sample also demonstrate the         |
|             following:                                              |
|               - Calling a statically linked assembler program       |
|                 from a C main.                                      |
|               - Using SAS/C functions loadm/unloadm to manage       |
|                 dynamic loadling/unloading of programs.             |
|               - Use of CENTRY/CEXIT, both INDEP and non-INDEP.      |
|               - Using CREGS and DSA extensions.                     |
|               - Calling SAS/C Library functions from assembler.     |
|               - C runtime options specifed in source.               |
|               - Using INLINE machine code to save the CRAB address. |
|                                                                     |
|                                                                     |
|---------------------------------------------------------------------|
|                                                                     |
| NOTE: The following Section Applies to Part # 1 ONLY!               |
|                                                                     |
|---------------------------------------------------------------------|
|                                                                     |
|       Name: ALOADMM                                                 |
|                                                                     |
|   Language: C                                                       |
|                                                                     |
| EntryPoint: MAIN                                                    |
|                                                                     |
| Entry Type: Standard OS Entry Linkage                               |
|                                                                     |
| Files Note: 'prefix' is the installation defined high level         |
|             qualifier for the SAS/C product.                        |
|                                                                     |
|   Function: The C main program displays the CRAB and then calls     |
|             a statically linked assembler program.  Upon return     |
|             from the assembler, the C main displays the CRAB        |
|             again.                                                  |
|                                                                     |
| Case 1 modules:    ALOADMM - C Main program statically linked with  |
|                              assembler program ALOADMA.             |
|                    ALOADMA - A non-INDEP assembler program using    |
|                              CENTRY/CEXIT which dynamically loads   |
|                              and executes non-INDEP ALOADMD.        |
|                    ALOADMD - A non-INDEP dynamically loadable       |
|                              C function.                            |
|                    ALOADMC - A C function which is statically linked|
|                              and used by the caller to display the  |
|                              CRAB address being used.               |
|                                                                     |
| MVS -                                                               |
|    Compile/Link/Go: submit jcl in prefix.SAMPLE.AUX(ALOADMJ)        |
|                                                                     |
| CMS -                                                               |
|    Compile/Link/Go: execute CMS exec in SAMPLAUX MACLIB(ALOADMEX)   |
|                     as: ALOADMEX                                    |
| Misc Notes:                                                         |
|            - Module ALOADM is  assembler independent, use either    |
|              Assembler H or High Level Assembler.                   |
|                                                                     |
+--------------------------------------------------------------------*/
#include <stdio.h>
#include <options.h>

/* The following demonstrates how to specify runtime options in      */
/* source.  None are required for the proper operation of the        */
/* ALOADM sample.                                                    */
extern  int _options = _VERSION + _BTRACE + _USAGE + _WARNING;

extern  int crbc(void);
extern  int casm(void);

int  main()
{
 printf("CMAIN   : Entry\n");
 printf("CMAIN   : Entry Crab------>");

 crbc();

 printf("CMAIN   : Assembler Call\n");
 printf("\n>--C Main ---> Assembler -------------->\n\n");

 casm();

 printf("\n<-Assembler ---> C Main  --------------<\n\n");
 printf("CMAIN   : Assembler Return \n");
 printf("CMAIN   : Exit Crab ------>");

 crbc();

 printf("CMAIN   : Exit\n");

 exit(0);
}

Copyright (c) 2000 SAS Institute Inc. All Rights Reserved.
Terms of Use & Legal Information | Privacy Statement