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 1995 (c), SAS Institute Inc.                  |
|                Unpublished - All Rights Reserved                    |
|                                                                     |
|                     S A S / C  S A M P L E                          |
|                                                                     |
|       Name: C2ASMC                                                  |
|                                                                     |
|   Language: C                                                       |
|                                                                     |
| EntryPoint: MAIN                                                    |
|                                                                     |
| EntryType : OS Entry Linkage                                        |
|                                                                     |
| Files Note: 'prefix' is the installation defined high level         |
|             qualifier for the SAS/C product.                        |
|                                                                     |
|   Function: Call a statically linked assembler routine which        |
|             sums a list of integers passed as pointers to int       |
|             in the call.  Two calls are made by C2ASMC, one with    |
|             two arguments and the second with four arguments.       |
|                                                                     |
|             The sum is checked after each call to SUMINT to         |
|             ensure the result is as expected.                       |
|                                                                     |
|    Purpose: Demonstrate a C function calling a statically linked    |
|             assembler routine expecting a C framework.  C2ASMC      |
|             uses the & operator to generate the pointers to         |
|             int for the parameter list.  The facilities of          |
|             __asm are used to produce the VL-type parameter         |
|             list which is required by SUMINT.                       |
|                                                                     |
| MVS - Compile/Link/Go: submit prefix.SAMPLE.AUX(C2ASMJ)             |
|                                                                     |
| CMS -                                                               |
|     Source: SAMPLASM MACLIB (C2ASMC/C2ASMA)                         |
|                                                                     |
|   Assemble: global maclib lcuser                                    |
|             hlasm c2asma                                            |
|                                                                     |
|    Compile: global maclib lc370                                     |
|             lc370 c2asmc                                            |
|                                                                     |
|       Load: global txtlib lc370bas lc370std                         |
|             load c2asmc c2asma (nomap reset main rmode 24 amode 24  |
|                                                                     |
|     Genmod: genmod c2asmc( from @main                               |
|                                                                     |
|    Execute: c2asmc                                                  |
|                                                                     |
|      Notes:                                                         |
|                                                                     |
+--------------------------------------------------------------------*/
#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-type 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 paramenter 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 C2ASM 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);
   }

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