Make your own free website on

Back Issue

Generating REXX with the Assembler

Two challenges of creating REXX code that accesses system control blocks is An example follows of using the assembler to calculate offsets. The generated REXX code should produce the same results as FINDJSAB which appears on the REXX samples page here. The assembler is being used as a preprocessor for generating REXX code. //S1 EXEC ASMC,PARM='DECK,NOOBJECT' //ASM.SYSLIB DD // DD DISP=SHR,DSN=SYS1.MODGEN //ASM.SYSIN DD * MACRO .* This macro generates a symbol for use in .* the generated REXX code .* Name is the symbol name .* Value is the symbol value SETSYM &NAME,&VALUE &LAB1 SETC '&NAME' .* generate an EQU statement to make value available &LAB1 EQU &VALUE .* generate a SETA statement to make symbol &NAME visible AINSERT '&&&LAB1 SETA &LAB1',FRONT MEND * REXX DSECT *** We do not wish to open a CSECT * 00010000 * DSECTS required to define values PRINT ON,NOGEN IHAPSA IHAASCB IHAASSB IHASTCB IKJTCB IAZJSAB * STORAGE SHORTCUT (PTR) &PTR SETC 'C2D(STORAGE(D2X' * STORAGE SHORTCUT (CHAR) &CHAR SETC 'STORAGE(D2X' PRINT ON,GEN * GENERATE REXX CODE PUNCH '/* REXX */' PUNCH '/* BASED ON EXPANSION OF IAZXJSAB MACRO */' PUNCH '/* THIS EXEC RETURNS CURRENT JOBNAME, JOBID, USERID AND */' PUNCH '/* NAME OF THE COMPONENT WHICH CREATED THE JSAB */' PUNCH '/* FOR THE CURRENT TASK / ADDRESS SPACE */' PUNCH 'NUMERIC DIGITS 10' SETSYM TOLD,PSATOLD-PSA PUNCH 'tcb = &PTR.(&TOLD),4)) /* GET CURRENT TCB */' PUNCH 'jsab = 0 /* NULL POINTER */' PUNCH 'If tcb \= 0 THEN DO' SETSYM STCBP,TCBSTCB-TCB PUNCH ' stcb = &PTR.(tcb+&STCBP),4))' SETSYM JSABP,STCBJSAB-STCB PUNCH ' jsab = &PTR.(stcb+&JSABP),4))' PUNCH ' END' PUNCH 'If jsab = 0 then do' SETSYM AOLD,PSAAOLD-PSA PUNCH ' ascb = &PTR.(&aold),4)) /* GET CURRENT ASCB */' SETSYM ASSBP,ASCBASSB-ASCB PUNCH ' assb = &PTR.(ascb+&ASSBP),4))' PUNCH ' If assb = 0 THEN DO' PUNCH ' Say ''Unable to locate JSAB from ASCB at ''D2X(ascb)' PUNCH ' EXIT 8' PUNCH ' end' SETSYM JSABQ,ASSBJSAB-ASSB PUNCH ' jsab = &PTR.(assb+&JSABQ),4))' PUNCH ' If jsab = 0 then do' PUNCH ' Say ''Unable to locate JSAB from ASCB at ''D2X(ascb)' PUNCH ' exit 8' PUNCH ' end' PUNCH ' end' SETSYM FLG1,JSABFLG1-JSAB PUNCH 'flg1 = &PTR.(jsab+&FLG1),1))' PUNCH 'Do While flg1 > 127' PUNCH ' eye = &CHAR.(jsab),4)' PUNCH ' If eye \= ''JSAB'' THEN DO' PUNCH ' Say ''Invalid JSAB found at ''D2X(jsab)' PUNCH ' exit 8' PUNCH ' end' SETSYM NEXT,JSABNEXT-JSAB PUNCH ' jsab = &PTR.(jsab+&NEXT),4))' PUNCH ' If jsab = 0 then do' PUNCH ' Say ''Unable to locate a valid JSAB''' PUNCH ' exit 8' PUNCH ' end' PUNCH ' flg1 = &PTR.(jsab+&FLG1),1))' PUNCH ' END' SETSYM JBNM,JSABJBNM-JSAB PUNCH 'jbnm = &CHAR.(jsab+&JBNM),8)' SETSYM JBID,JSABJBID-JSAB PUNCH 'jbid = &CHAR.(jsab+&JBID),8)' SETSYM SCID,JSABSCID-JSAB PUNCH 'comp = &CHAR.(jsab+&SCID),4)' SETSYM USID,JSABUSID-JSAB PUNCH 'usid = &CHAR.(jsab+&USID),8)' PUNCH 'Say ''JOBNAME=''jbnm'' JOBID=''jbid'' USERID=''usid' PUNCH 'Say ''COMPONENT=''comp' PUNCH 'EXIT 0' END //SYSPUNCH DD DISP=SHR,DSN= .... The target library would be a partitioned datasets with RECFM=FB and LRECL=80. In the example above, the member name might be FINDJSAB.


Comments or suggestions can be sent to the author.

Last Issue

Big Iron