New Video: External DSECTS – Q-cons, CXDs, and DXDs

Q-cons, CXDs, and DXDs enlist the help of the Binder to make it easy for you to allocate storage dynamically for all your CSECTS. They also widen the possibilities for how you can design multi-CSECT programs. Some companies use these ideas to promote the separation of storage and code. In any case, this is an interesting HLASM path to explore.

I’ve created a video to explain these ideas and a sample program listed below that you can use as skeleton code for further exploration.

        PRINT  ON,NODATA,NOGEN
**********************************************************************
**********************  STORAGE FOR ASECT ****************************
**********************************************************************
ASTOR    DSECT
A1       DS    CL80       SOME VARIABLES FOR ASECT
A2       DS    CL30
A3       DS    CL5
A4       DS    PL10
A5       DS    200CL5
SAVEA    DS    18F        AREA FOR MY CALLEE TO SAVE & RESTORE MY REGS
**********************************************************************
**********************  STORAGE FOR PARMS ****************************
**********************************************************************
PARMSECT DSECT
X        DS    CL80
Y        DS    CL80
Z        DS    CL80
**********************************************************************
**********************  ASECT CONTROL SECTION ***********************
**********************************************************************
ASECT   CSECT
ASECT   AMODE  31
ASECT   RMODE  24
**********************  ENTRY LOGIC  *********************************
         STM   14,12,12(R13)          SAVE CALLER'S REGS
         BASR  R12,0                  ESTABLISH
         USING *,R12                  ADDRESSABILITY
         L     R8,EDSLEN              GRAB LENGTH OF STORAGE NEEDED
         STORAGE OBTAIN,LENGTH=(R8),ADDR=(R11)
         LR    R10,R11                GRAB ADDRESS FOR ALL STORAGE
         A     R10,ASECTO             ADD OFFSET FOR MY DSECT
         USING ASTOR,R10              I HAVE ADDRESSABILITY
         ST    R13,SAVEA+4            BACK-CHAIN CALLER'S FROM MINE
         LA    R13,SAVEA              POINT TO MY LOWER-LEVEL SA
**********************  BEGIN LOGIC  *********************************
         OPEN  (FILEOUT,(OUTPUT))
         PUT   FILEOUT,=CL80'ENTERING PROGASECT'
         LR    R9,R11                  POINT AT DYNAMIC STORAGE
         A     R9,PARMO                ADD THE OFFSET FOR PARMS
         USING PARMSECT,R9             I HAVE ADDRESSABILITY
         MVC   X,=CL80'THIS IS PARM X' INITIALIZE ...
         MVC   Y,=CL80'THIS IS PARM Y' ... PARMS
         MVC   Z,=CL80'THIS IS PARM Z'
         LA    R1,=A(FILEOUT,PARMO)   PASS THE DCB AND PARMO
         L     R15,=A(BSECT)          CALLING BSECT
         BASR  R14,R15                BRANCH THERE
         PUT   FILEOUT,=CL80'RETURNED TO PROGA1'
         LR    R9,R11                 POINT AT ALLOCATED STORAGE
         A     R9,XXXAO               ADD THE OFFSET TO XXX
         PUT   FILEOUT,0(R9)          R9 POINTS AT XXX
         CLOSE FILEOUT
         STORAGE RELEASE,LENGTH=(R8),ADDR=(R11)
*********************** STARDARD EXIT ********************************
RETURN   EQU   *                      BRANCH TO HERE FOR NORMAL RETURN
         L     R13,SAVEA+4            POINT TO CALLER'S SAVE AREA
         LM    R14,R12,12(R13)        RESTORE CALLER'S REGS
         LA    R15,0                  SET RETURN CODE REG 15 = 0
         BR    R14
****************** LOCAL DATA AREAS   ********************************
FILEOUT  DCB   DSORG=PS,                                               X
               MACRF=(PM),                                             X
               DEVD=DA,                                                X
               DDNAME=FILEOUT,                                         X
               RECFM=FB,                                               X
               LRECL=80
ASECTO   DC    Q(ASTOR)               OFFSET TO ASTOR
PARMO    DC    Q(PARMSECT)            OFFSET TO PARMSECT
XXX      DXD   CL80                   DECLARATION OF XXX IN EDS
XXXAO    DC    Q(XXX)                 OFFSET TO XXX
EDSLEN   CXD                          FULLWORD TOTAL SPACE NEEDED
         LTORG
         YREGS

**********************************************************************
**********************  STORAGE FOR BSECT ****************************
**********************************************************************
BSTOR    DSECT
B1       DS     F           THE STORAGE AREAS NEEDED IN BSECT
B2       DS     CL20
B3       DS     PL5
B4       DS     CL100
B5       DS     CL5
SAVEB    DS   18F                     BSECT SAVE AREA
**********************************************************************
**********************  BSECT CONTROL SECTION ***********************
**********************************************************************
BSECT    CSECT
         STM   14,12,12(R13)          SAVE CALLER'S REGS
         BASR  R12,0                  ESTABLISH
         USING *,R12                  ADDRESSABILITY
         LR     R10,R11               SET UP...
         A      R10,BSECTO            ... ADDRESSABILITY FOR BSECT
         USING  BSTOR,R10             I HAVE STORAGE ADDRESSABILITY
         LR     R9,R11                POINT AT ALLOCATED MEMORY
         L      R6,4(R0,R1)           R6 POINTS AT PARMO
         A      R9,0(R0,R6)           ADD THE OFFSET FOR PARMS
         USING  PARMSECT,R9           I HAVE PARM ADDRESSABILITY
         ST     R13,SAVEB+4
         LA     R13,SAVEB
**********************  BEGIN LOGIC  *********************************
         L      R5,0(R0,R1)           R5 POINTS AT MY RECOUT DCB
         PUT    (R5),=CL80'ENTERED BSECT'
         PUT    (R5),X                PRINT THE PARMS
         PUT    (R5),Y
         PUT    (R5),Z
*
*        USE BSTOR FIELDS CAN BE USED HERE
*
         MVC    B4,=CL80'THIS IS B4 DATA'
         PUT    (R5),B4
*
*        PREPARE TO USE XXX
*
         LR     R9,R11                POINT AT XDS WITH R9
         A      R9,XXXBO              ADD THE OFFSET TO XXX
         MVC    0(80,R9),=CL80'XXX IN ASECT WAS CHANGED IN BSECT'
*
         PUT    (R5),=CL80'ABOUT TO LEAVE BSECT'
*********************** STARDARD EXIT ********************************
         L      R13,SAVEB+4           STANDARD EXIT CODE
         LM     R14,R12,12(R13)
         BR     R14
************* INITIALIZED DATA AREAS AND PARMS ***********************
BSECTO   DS     Q(BSTOR)      OFFSET FOR BSECT STORAGE
XXXBO    DC     Q(XXX)        OFFSET TO XXX
         LTORG
         END   ASECT

Leave a comment

Filed under IBM Mainframe Assembler

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.