On 19 August 2016 at 14:47, Ngan, Robert <[email protected]> wrote:
> I'm writing a macro to build length prefixed character strings.  The
length is one byte, and the actual string is referenced by LARL so it needs
to be halfword aligned.

The string needs to be halfword aligned, or the length byte does?

> So I coded (what would be a CNOP 1,2 - if it was valid):

I don't see how CNOP comes into this. CNOP (Conditional No OPeration) is
used to pad an instruction stream with NOPRs (X'0700'); it makes no sense
for data. (Not that it's *wrong* to generate unneeded 0700s, but that's why
there is no sense to CNOP 1,2.)

>          DC    (1-(*-&SYSECT)/2)X'00'   Simulate a CNOP 1,2
>
> However, this generates ASMA067S Illegal duplication factor.

You're on the right track here, I think, but I think your calculation is
not quite right.

How about:

DC    (1-((*-&SYSECT)-(*-&SYSECT)/2*2))X'00'

Or just use DS:

DS    (1-((*-&SYSECT)-(*-&SYSECT)/2*2))X

Or you could use something similar with an ORG.

I'm not clear if you want the length to be generated as a byte before the
data (on the odd boundary), and if so where the label should be.  This
seems to produce reasonable results, assuming you want the label on the
halfword aligned data:

TEST     CSECT
         PRINT DATA

         MACRO
&name    CSTRING &data
&dat     SETC  DEQUOTE('&data')
&len     SETA  DCLEN('&dat')
         DS    (1-((*-&SYSECT)-(*-&SYSECT)/2*2))X
         DC    FL1'&len'
&name    DC    C'&dat'
         MEND

DataA    CSTRING 'Some data'
DataB    CSTRING 'Some more data'
DataC    CSTRING '12345'
DataD    CSTRING '1234'
DataE    CSTRING '1'
DataF    CSTRING NoQuotes
DataG    CSTRING 'O''Connor'
         END


This is somewhat but not completely robust wrt the operand - it can be
quoted or not as you like. Of course if you want the label on the
odd-byte-aligned length byte, just move it. You could also do tricks to
give the label the right length attribute.

&name    EQU   *,&len+1

would give it the length of the string plus the length byte.  etc. etc.

Tony H.

Reply via email to