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                          *
*                                                                     *
*       Name: A2CMCASM                                                *
*                                                                     *
*   Language: Assembler                                               *
*                                                                     *
* EntryPoint: ASMAIN                                                  *
*                                                                     *
* Entry Type: Standard OS Entry Linkgage, non-reentrant               *
*                                                                     *
*   Function: Call a C main via SAS/C entry point $MAINC, passing     *
*             a parameter list of integers.                           *
*                                                                     *
*             $MAINC expects to receive a list of addresses with      *
*             the high-order (VL) bit set in the last address.  The   *
*             input parameters are transformed into the standard      *
*             C argc value (number of arguments plust 1) and the      *
*             argv vector.                                            *
*                                                                     *
*             NOTE for $MAINC:                                        *
*                   At execution time there is no way to provide      *
*                   runtime argruments or environment variables.      *
*                   If needed, runtime options can be defined in the  *
*                   source code using the flags defined in            *
*                   <options.h>, see 'Runtime Argument Processing'    *
*                   in the Compiler and Library User's Guide.         *
*                                                                     *
*                   If needed, some runtime arguments may be provided *
*                   in the 'source'.                                  *
*                                                                     *
*                   Another alternative is using entry point $MAINO   *
*                   which does provide for runtime arguments and      *
*                   environment variables.                            *
*                                                                     *
*                   See the Compiler and Library User's Guide for     *
*                   details for both of the above.                    *
*                                                                     *
*    Purpose: Demonstrate how to call a SAS/C main via entry point    *
*             $MAINC from assembler.  OS load was chosen in as the    *
*             method to load the C main.  However, a statically       *
*             linked C main or a C main loaded via attach would have  *
*             the same parameter list requirements when called.       *
*                                                                     *
*             The C main being called will be built as an ALLRES      *
*             application, as such it does not require the SAS/C      *
*             Transient Library.  This is a very simple usage of      *
*             of ALLRES whose intent is to demonstrate that the       *
*             parameter list requirements are exactly the same as     *
*             those required of a normal C main program.  Please      *
*             see the SAS/C Compiler and Library User's Guide for     *
*             details on ALLRES applications.                         *
*                                                                     *
*             Additionally, the following are demonstrated:           *
*              - redirection of standard output (stdout) via source   *
*                using SAS/C facilities                               *
*              - using inline machine code                            *
*              - usage of System Interface Functions                  *
*                  - intractv()                                       *
*                  - cuserid()                                        *
*                                                                     *
* Files Note: 'prefix' is the installation defined high level         *
*             qualifier for the SAS/C product.                        *
*                                                                     *
* MVS -                                                               *
*    Compile/Link/Go: submit prefix.SAMPLE.AUX(A2CMCJ)                *
*                                                                     *
* CMS -                                                               *
*   Complile/Link   : execute CMS exec in SAMPLAUX MACLIB(A2CMCEX)    *
*                                                                     *
*    Execute        : global loadlib a2cmc                            *
*                     a2cmcasm                                        *
*                                                                     *
* Misc Notes:                                                         *
*            - A2CMCASM is not assembler dependent, use either        *
*              Assembler H or High Level Assembler.                   *
*                                                                     *
*---------------------------------------------------------------------*
*                                                                     *
* SAS/C Entry Point '$MAINC' pararmeter list:                         *
*                                                                     *
* At entry to $MAINC R1 must point to a standard OS VL type parameter *
* list, with the VL bit set on the last argument.  Each entry in the  *
* list should be a pointer to data as follows:                        *
*                                                                     *
*    R1 ----->  +---------+                                           *
*               |    *data| ---->   data                              *
*               +---------+                                           *
*               |    *data| ---->   data                              *
*               +---------+                                           *
*               |    *data| ---->   data                              *
*               +---------+                                           *
*               |VL| *data| ---->   data     NOTE: VL bit is set      *
*               +---------+                                           *
*                                                                     *
*---------------------------------------------------------------------*
         EJECT
         PRINT ON,NOGEN
R0       EQU     0
R1       EQU     1
R2       EQU     2
R3       EQU     3
R4       EQU     4
R5       EQU     5
R6       EQU     6
R7       EQU     7
R8       EQU     8
R9       EQU     9
R10      EQU     10
R11      EQU     11
R12      EQU     12
R13      EQU     13
R14      EQU     14
R15      EQU     15
         SPACE
*---------------------------------------------------------------------*
* Standard OS Entry Linkage : Not reentrant                           *
*---------------------------------------------------------------------*
         SPACE
ASMAIN   CSECT
         STM   R14,R12,12(R13)   Save entry regs in callers area
         BALR  R9,R0             Load Base
         USING *,R9              Tell Assembler
         LR    R14,R13           Save callee save area addr
         LA    R13,SAVEAREA      Put mine in R13
         ST    R14,4(R13)        Save callee save area in mine
         ST    R13,8(R14)        Tell callee my save area adr
         SPACE
*---------------------------------------------------------------------*
* Load the C main, if the module is not loaded an abend will          *
* occur.  Otherwise, the load was successful and R0 has entry point   *
* address to the module.                                              *
*---------------------------------------------------------------------*
         SPACE
         LA    R2,LOADNAME          Ptr to module name to load
         LOAD  EPLOC=(R2)           Load the module
         LR    R5,R0                Save the entry point address
*---------------------------------------------------------------------*
* Setup parameter list address and call the C main                    *
*---------------------------------------------------------------------*
         SPACE
         LA    R1,VLPLIST           Ptr to plist for call
         LR    R15,R5               Entry point to R15
         BALR  R14,R15              Call the program
         LTR   R15,R15              Did the called program finish ok?
         BZ    UNLOAD               Yes, Continue
         SPACE
*---------------------------------------------------------------------*
* The C main did not finish up correctly issue a message and exit.    *
*---------------------------------------------------------------------*
         SPACE
         LR    R3,R15               Save return code for exit
         ST    R3,RETCODE           Set return code for msg display
         MVC   MSG,=A(MSG1)         Set msg to display
         MVC   RC,=A(RETCODE)       Move ptr to rc into plist
         LA    R1,MSGPLIST          Point r1 to plist
         L     R15,=V(A2CMEMG)      Ptr to C msg display function
         BALR  R14,R15              Display the msg
         B     EXIT                 Exit with return code
         SPACE
*---------------------------------------------------------------------*
* Delete the module and setup R3 with return code for exit            *
*---------------------------------------------------------------------*
         SPACE
UNLOAD   DS    0H
         LA    R2,LOADNAME          Ptr to module name loaded
         DELETE EPLOC=(R2)          Delete it, no longer needed
         SR    R3,R3                Ensure return code is zero
EXIT     DS    0H
         L     R13,4(R13)           Ptr to entry reg save area          00290015
         LR    R15,R3               Set return code
         LM    R0,R12,20(R13)       Reload registers  0-12..ONLY..      00300006
         L     R14,12(R13)          Restore return address to R14
         BR    R14                  Return to caller                    00320015
         EJECT
*---------------------------------------------------------------------*
* Constant Area Follows                                               *
*---------------------------------------------------------------------*
         SPACE
         LTORG
LOADNAME DC    CL8'A2CMC',X'00'      MAIN filename as a string
         SPACE
*---------------------------------------------------------------------*
* The address of VLPLIST will be loaded into R1 when the C main       *
* is called.  Note that the VL bit is set on in the last argument.    *
*---------------------------------------------------------------------*
         SPACE
VLPLIST  DS    0F
         DC    A(INT1)               argv[1]
         DC    A(INT2)               argv[2]
         DC    A(INT3)               argv[3]
         DC    A(X'80000000'+INT4)   argv[4] VL Bit Set
         SPACE
INT1     DC    F'1'
INT2     DC    F'2'
INT3     DC    F'3'
INT4     DC    F'4'
         SPACE
*---------------------------------------------------------------------*
* The following is the parameter list and parameters that will be     *
* used to call the message display C function, A2CMCEMG.              *
*---------------------------------------------------------------------*
         SPACE
MSG1     DC    X'1515'
         DC    C'ERROR: C Main returned non-zero return code.'
         DC    X'151500'   <== Note: MSG1 is a null terminated string
         SPACE
RETCODE  DS    F
         SPACE
MSGPLIST DS    0F          Parmlist
MSG      DS    A           Argument 1 - the message
RC       DS    A           Argument 2 - the return code
*---------------------------------------------------------------------*
* Working Storage                                                     *
*---------------------------------------------------------------------*
SAVEAREA DC    18F'0'
         SPACE
         END   ASMAIN

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