lørdag den 12. december 2015

Language Environment in Assembler (1)

A simple LE-program explained

Language Environment (LE) has been around for more than 20 years. However, I have just recently started working with it and I wish to share some of my experiences with you.


Before you start you might want an introduction to LE in "Language Environment Concepts Guide". Find it here.


Every module and message in Language Environment start with “CEE”. I start by using an example in "Language Environment Concepts Guide", "Chapter 5. Sample Routines". I have added a few lines in order to show how to get some “Working Storage”. Added lines are in Italic and CEE-lines are in Bold


*==========================================================
*           
* Shows a simple main assembler routine
* that brings up the environment,
* returns with a return code of 0, modifier of 0, and
* prints a message in the main routine.
*                                      
*===========================================================  
MAIN     CEEENTRY PPA=MAINPPA,AUTO=DSA_LENGTH             
**
        LA    1,PARMLIST
        L     15,=V(CEEMOUT) ;
        BALR  14,15
        MVI   Working_Area,C' '
        MVC   Working_Area+1(L'Working_Area),Working_Area
        MVC   Working_Area(PARMLIST_LEN),PARMLIST        
        MVC   Working_Area+PARMLIST_LEN(HWLEN+2),HW      
        LA    1,Working_Area+PARMLIST_LEN
        ST    1,Working_Area
        LA    1,Working_Area
        L     15,=V(CEEMOUT)
        BALR  14,15
*==========================================================
* Terminate the Language Environment environment
* and return to the caller
*==========================================================;
        CEETERM RC=0,MODIFIER=0
* =========================================================
* CONSTANTS AND WORKAREAS
* =========================================================
PARMLIST DC    AL4(STRING)
        DC    AL4(DEST)
        DC    X'80000000' Omitted feedback code           
PARMLIST_LEN EQU *-PARMLIST
*
STRING   DC    AL2(STRLEN)
STRBEGIN DC    CL19'In the main routine'                   
STRLEN   EQU   *-STRBEGIN
DEST     DC    F'2' ;
HW       DC    AL2(HWLEN)     
HWTEXT   DC    C'Hello World'
HWLEN    EQU   *-HWTEXT
MAINPPA  CEEPPA         Constants describing the code block
        CEEDSA         Mapping of the dynamic save area   
Working_Area DS CL128
DSA_LENGTH EQU *-CEEDSA     
        CEECAA         Mapping of the common anchor area             
        END   MAIN     Nominate MAIN as the entry point              
Example program (MAIN) from manual


I have highlighted the CEE-macroes and fields that are LE.

The result from the program on SYSOUT:
In the main routine
Hello World         

CEEENTRY- Sets Language Environment and starts program
MAIN     CEEENTRY PPA=MAINPPA,AUTO=DSA_LENGTH
CEEENTRY initializes the LE-environment. It saves registers in the normal way and provides storage for the program variables. In COBOL known as Working Storage.
The parameter AUTO takes that length. It is calculated near the end in the sample program in the statement DSA_LENGTH EQU *-CEEDSA.
PPA is the name of the label on the CEEPPA macro. CEEENTRY calculates the offset to PPA in order to be able to locate it.

CEEMOUT - Write to SYSOUT

L     15,=V(CEEMOUT)
There are several services that you can use in LE and write to SYSOUT is one of them. It is called CEEMOUT. You just call the service as any other statically linked CSECT. Read here

CEETERM - Terminate the Language Environment

CEETERM RC=0,MODIFIER=0
CEETERM terminates LE and returns to the caller. CEEENTRY and CEETERM are mutually dependant.

CEEPPA - Constants describing the code block

MAINPPA  CEEPPA
This is the Program Prolog Area (PPA) macro that is referred in CEEENTRY. It defines a lot of constants that describes this programs LE. That includes assembly time.

CEEDSA - Mapping of the dynamic save area

CEEDSA
Starts the Dynamic Storage Area (DSA). The first 128 bytes are reserved for LE but after that it is all yours, as long you calculate the size properly. Always remember include the 128 bytes in the DSA length.
DSA_LENGTH EQU *-CEEDSA

CEECAA - Mapping of the common anchor area

CEECAA
It is the LE common area. Read more here.
You must include the LE MACLIB in the Assembler SYSLIB.
//SYSLIB   DD DISP=SHR,DSN=SYS1.MACLIB
//         DD DISP=SHR,DSN=CEE.SCEEMAC


and the load modules for LE in the Linkage Editor (Binder):
//SYSLIB   DD DISP=SHR,DSN=CEE.SCEELKED


The Linkage Editor must include CALL in the options as opposed to NCALL in order to dynamically include the LE-modules in your program during Bind.
SETOPT PARM(LET,LIST,XREF,CALL)




Previous article about making a program reentable

Ingen kommentarer:

Send en kommentar