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: A2CMOASM                                                *
*                                                                     *
*   Language: Assembler                                               *
*                                                                     *
* EntryPoint: ASMAIN                                                  *
*                                                                     *
* Entry Type: Standard OS Entry Linkgage, non-reentrant               *
*                                                                     *
*   Function: Call a C main via SAS/C entry point $MAINO passing a    *
*             tailored parameter list for this entry point.  Entry    *
*             point $MAINO will:                                      *
*              - process the arguments passed at entry and provide    *
*                them to the main program via elements in the         *
*                argv array                                           *
*              - handle runtime options                               *
*              - process environment variables and pass them to the   *
*                main program via elements in the envp array          *
*              - handle standard file redirection                     *
*                                                                     *
*             $MAINO expects an argument list whose first element is  *
*             a pointer to a string contianing runtime options,       *
*             environment variables, and/or file redirections.  All   *
*             elements after the first are passed the the C main via  *
*             the argv array.                                         *
*                                                                     *
*    Purpose: Demonstrate how to call a SAS/C main via entry point    *
*             $MAINO from assembler.  OS load was chosen to load the  *
*             C main, however, a statically linked C main or a        *
*             C main loaded via attach would have exactly the same    *
*             calling requirements.                                   *
*                                                                     *
*             Additionally, the following are demonstrated:           *
*              - passing runtime options via the argument string      *
*                to $MAINO in order to:                               *
*                . redirect stdout to DD name SYSOUTO                 *
*                . set environment variables                          *
*              - 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(A2CMOJ)                *
*                                                                     *
* CMS -                                                               *
*   Complile/Link   : execute CMS exec in SAMPLAUX MACLIB(A2CMOEX)    *
*                                                                     *
*    Execute        : global loadlib a2cmo                            *
*                     a2cmoasm                                        *
*                                                                     *
*                     Note: Output is in fileid SYSOUTO FILE A        *
*                                                                     *
* Misc Notes:                                                         *
*            - A2CMOASM is not assembler dependent, use either        *
*              Assembler H or High Level Assembler.                   *
*                                                                     *
*---------------------------------------------------------------------*
*                                                                     *
* SAS/C $MAINO Parameter List:                                        *
*                                                                     *
* At entry $MAINO expects R1 to point to a standard OS VL type        *
* parameter list, with the VL bit of the last argument set.  The      *
* first argument is a pointer a string prefixed with a halfword       *
* length.  The length should be the length of the string.  The first  *
* argument should point to the string prefix, not the string.         *
*                                                                     *
*     R1-> +---------+       +-----------------------------------+    *
*          |    *char|-----> |Halfword Length of string following|    *
*          +---------+       +-----------------------------------+    *
*          |    *data|       | String with:                      |    *
*          +---------+       | - runtime options                 |    *
*          |    *data|       | - environment variables           |    *
*          +---------+       | - file redirections               |    *
*          |    *data|       +-----------------------------------+    *
*          +---------+                                                *
*          |VL| *data|       NOTE: VL bit is set                      *
*          +---------+                                                *
*                                                                     *
*   NOTE:  Runtime options and environment variables are the ONLY     *
*          entries that will be processed from the string passed      *
*          to entry $MAINO.  Anything else in the string will be      *
*          ignored.                                                   *
*                                                                     *
*---------------------------------------------------------------------*
         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                                           *
*---------------------------------------------------------------------*
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 the argument list 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 failed for some reason, 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)      Addr of msg error msg display
         BALR  R14,R15              Display the msg
         B     EXIT                 Leave with a return code
         SPACE
*---------------------------------------------------------------------*
* Unload the C main, set return code and proceed to exit              *
*---------------------------------------------------------------------*
         SPACE
UNLOAD   DS    0H
         LA    R2,LOADNAME          Ptr to module name loaded
         DELETE EPLOC=(R2)          Delete it, no longer needed
         SPACE
         SR    R3,R3                Ensure return code is zero
*---------------------------------------------------------------------*
* Standard OS Exit Linkage   Note: R3 will have return code           *
*---------------------------------------------------------------------*
         SPACE
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                                                       *
*---------------------------------------------------------------------*
         SPACE
         LTORG
LOADNAME DC    CL8'A2CMO',X'00'      MAIN filename as a string
         SPACE
*---------------------------------------------------------------------*
* The address of VLPLIST will be loaded into R1 when the C main       *
* is called via entry point $MAINO with the VL bit set on the last    *
* argument.                                                           *
*                                                                     *
* Note: - argument 1 address points to the string prefix,             *
*         not the string                                              *
*       - all arguments, after argument one, are passed to the C main *
*         in the argv array                                           *
*---------------------------------------------------------------------*
VLPLIST  DS    0F
         DC    A(OPTPRFX)            Runtime options string
         DC    A(INT1)               argv[1]->
         DC    A(INT2)               argv[2]->
         DC    A(INT3)               argv[3]->
         DC    A(INT4)               argv[4]->
         DC    A(INT5)               argv[5]->
         DC    A(INT5)               argv[5]->
         DC    A(X'80000000'+INT6)   argv[6]-> VL Bit Set
         SPACE
INT1     DC    F'1'
INT2     DC    F'2'
INT3     DC    F'3'
INT4     DC    F'4'
INT5     DC    F'5'
INT6     DC    F'6'
         SPACE
         SPACE
*---------------------------------------------------------------------*
* The following is the parameter list that will be passed to          *
* entry point $MAINO as the frist argument in the parameter list.     *
* It is preceeded by a halfword which is the length of the string     *
* only.                                                               *
*                                                                     *
* Note: To ensure that argument parsing does not concantenate         *
*       arguments, each option string should start with a             *
*       blank and end with a blank.                                   *
*---------------------------------------------------------------------*
         SPACE
OPTPRFX  DS    0F
OPTLEN   DC    AL2(L'OPTDATA)
OPTDATA  DC    C' =BTRACE =VERSION =ENTRY=$MAINO >SYSOUTO '
         SPACE
*---------------------------------------------------------------------*
* The following is the parameter list and parameters that will be     *
* used to call the message display C function, A2CMEMG.               *
*---------------------------------------------------------------------*
         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                                                     *
*---------------------------------------------------------------------*
         SPACE
SAVEAREA DC    18F'0'      AS2CMOASM Savearea
         SPACE
         END   ASMAIN

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