OK, here goes. The macro should also check for a specified field length not
greater than 256. In this case, if the initialization byte is X'00' we
should just XC the field on itself. But, if the initialization byte is
anything other than X'00' we should do a cascading move of the
initialization byte. In a all other case, we would perform an MVCL forcing
the field to its new initialization byte value.
V001 TITLE 'TEST INLINE MACRO USED TO INITIALIZE A FIELD'
MACRO
ACLEAR &L=,&A=VSAMWORK,&I=00
LCLC &AA
LCLA &LEN
AIF (T'&L EQ 'O' OR T'&L NE 'N').AROUND
.* NON-VALID LENGTH?
&LEN SETA &L ELSE SET NUMERIC LENGTH VALUE
AIF (&LEN LT 257 AND '&I' EQ '00').XC
.* CAN WE ZAP FIELD?
AIF (&LEN LT 257).MVC CAN WE JUST CASCADE A BYTE?
AIF (&LEN GT 256).DOLIT DO WE NEED TO LOAD A LITERAL?
LA R15,&LEN GET NUMBER OF BYTES TO CLEAR
AGO .CONTINU AND CONTINUE WITH MAINLINE CODE
.DOLIT ANOP . WE'RE DOING A LITERAL MOVE
SR R15,R15 CLEAR LENGTH REGISTER FIRST
ICM R15,B'0011',=AL2(&LEN) AND SET LENGTH
AGO .CONTINU AND CONTINUE WITH MAINLINE CODE
.AROUND ANOP . WE'RE USING THE LENGTH ATTRIB
&AA SETC 'L''' MAKE LENGTH ATTRIBUTE STRING
LA R15,&AA&A GET LENGTH ATTRIBUTE OF FIELD
.CONTINU ANOP . LENGTH IS SET
LA R14,&A TARGET ADDRESS TO CLEAR
LR R0,R14 SOURCE ADDRESS TO CLEAR
SR R1,R1 SET SENDING FIELD LENGTH TO ZERO
IC R1,X'&I' SET PAD CHARACTER
MVCL R14,R0 INITIALIZE WORK AREA
MNOTE 0,'R0, R1, R14, AND R15 ARE NOW FUBAR'
MEXIT . AND EXIT THE MACRO NOW
.XC ANOP , WE WILL ZAP THE FIELD ON ITSELF
&AA SETC '(&LEN)' SET STRING OF LENGTH WITH PARENS
XC &A&AA,&A ZAP THE FIELD
MEXIT . AND EXIT THE MACRO NOW
.MVC ANOP , WE WILL DO A CASCADE MVC ZAP
MVI &A,X'&I' ZAP FIRST BYTE OF STRING
&LEN SETA &LEN-1 DECREMENT LENGTH
&AA SETC '(&LEN)' SET STRING OF LENGTH WITH PARENS
MVC &A+1&AA,&A DO THE CASCADING MOVE
MEND , WE ARE DONE
EJECT
TESTMAC CSECT , SET &SYSECT
USING TESTMAC,R15 ASSIGN TEMP BASE
STM R14,R12,12(R13) SAVE ALL REGS
LR R5,R15 GET EP ADDRESS
USING TESTMAC,R5 SET NEW PGM BASE
DROP R15 KILL TEMP BASE
LR R3,R13 SAVE OLD SA
LA R13,SAVE POINT TO NEW SA
ST R13,8(R3) CHAIN
ST R3,4(R13) SAVE AREAS
SPACE 1
ACLEAR
ACLEAR L=0000010
ACLEAR L=257
ACLEAR L=48,I=FF
ACLEAR L=48
ACLEAR L=500
SPACE 1
L R13,4(R13) POINT TO OLD SA
LM R14,R12,12(R13) RESTORE ALL REGS
SR R15,R15 SET ZERO RC
BR R14 RETURN TO CALLER
DROP R5 KILL PGM BASE
SAVE DC 18F'-1' OUR SAVE AREA
VSAMWORK DS CL500 OUR WORK AREA
YREGS , REGISTER EQUATES
LTORG , <= JUST TO BE KOSHER
*
END TESTMAC END ASSEMBLY, SUPPLY EP
The little test program will actually run and test our generated code.
-----Original Message-----
From: IBM Mainframe Assembler List [mailto:[email protected]]
On Behalf Of Paul Gilmartin
Sent: Saturday, August 04, 2012 1:45 PM
To: [email protected]
Subject: Re: Attributes Test In Macros
On Aug 4, 2012, at 11:12, John Gilmore wrote:
> Dan Skomsky suggests the statement
>
> | AIF ('&L' GT '256').DOLIT WE NEED TO LOAD A LITERAL
>
> which is booby trapped. The HLASM and its predecessors compare
> strings lexicographically iff their lengths|character counts are
> equal. When they are not, the longer compares greater than the
> shorter. Thus 'aaa' < 'aab' but 'aa' > 'x' and, for example, '0000' >
> '256'.
>
I'm aghast that no one noticed this early, deemed it a bug,
and fixed it. Nowadays, it's to sanctified by use to fix.
CLC over a 2-byte length field followed by the string body?
How could they?
-- gil