Parm Fields

To pass multiple parm fields to a subprogram, the caller must load their addresses into a series of consecutive fullwords known as the address list.  The caller must also load register 1 with the address of the first fullword in the series; and indicate the last parm to be passed by setting bit 0 of its address to B'1'.  The following code illustrates how a caller containing three potential parm fields passes the first two to a subprogram.

         LA    R1,P1ADDR               R1  = ADDR OF 1ST ADDR IN LIST
         OI    P2ADDR,X'80'            MARK 2ND PARM AS LAST
         L     R15,=V(GETPARMS)        R15 = ADDR OF CALLED PGM
         BASR  R14,R15                 CALL THE PROGRAM
          .
          .
          .
PARM1    DC    CL5'PARM1'              PARM 1
PARM2    DC    F'255'                  PARM 2
         DS    CL2
PARM3    DC    CL10'PARM 3 FLD'        PARM 3
*
P1ADDR   DC    A(PARM1)                PARM 1 ADDR
P2ADDR   DC    A(PARM2)                PARM 2 ADDR
P3ADDR   DC    A(PARM3)                PARM 3 ADDR

The subprogram must scan the address list to load each parm field into a storage location of a type determined by the order of the parm’s address within the list. The following code illustrates a subprogram that can process up to 3 parm fields of the types passed by the above caller.

         LTR   R1,R1                   TEST FOR PARM DATA
         BZ    PARMEND                 NO DATA WHEN R1 = 0
         LA    R4,P1ADDR               R4 = PTR TO PARM 1 SAVE ADDR
         LA    R6,P1LEN                R6 = PTR TO PARM 1 SAVE LEN
         LA    R8,3                    MAX LOOP COUNT IS 3
GETPARM  L     R2,0(,R1)               R2 = PARM ADDR
         L     R5,0(,R4)               R5 = PARM SAVE ADDR
         LH    R7,0(,R6)               R7 = PARM SAVE LEN
         BCTR  R7,0                    DECREMENT LEN FOR EX
         EX    R7,MVPARM               EXECUTE MVC FOR PARM
         TM    0(R1),X'80'             TEST FOR LAST PARM
         BO    PARMEND                 END LOOP, IF FOUND
         LA    R1,4(,R1)               BUMP PTR TO PARM
         LA    R4,4(,R4)               BUMP PTR TO PARM SAVE ADDR
         LA    R6,2(,R6)               BUMP PTR TO PARM SAVE LEN
         BCT   R8,GETPARM              CONTINUE LOOP
PARMEND  DS    0H
          .
          .
          .
MVPARM   MVC   0(0,R5),0(R2)           EXECUTED MOVE
*
PARM1    DC    CL5'NULL '              PARM 1
PARM2    DC    F'0'                    PARM 2
         DS    CL2
PARM3    DC    CL10'NULL      '        PARM 3
*
P1ADDR   DC    A(PARM1)                PARM 1 ADDR
P2ADDR   DC    A(PARM2)                PARM 2 ADDR
P3ADDR   DC    A(PARM3)                PARM 3 ADDR
*
P1LEN    DC    AL2(L'PARM1)            PARM 1 LEN
P2LEN    DC    AL2(L'PARM2)            PARM 2 LEN
P3LEN    DC    AL2(L'PARM3)            PARM 3 LEN

Copyright © 2011 The Stevens Computing Services Company, Inc.  All rights reserved.