[comp.lang.asm370] Packed-Decimal Validation

CAREY@CLEMSON.BITNET (Jim Blalock) (04/12/90)

I have a question that surely someone else has answered.  I have a need
to validate that data passed to my code is real packed-decimal, in an
attempt to avoid program checks. I've managed to come up with a routine
that should work in all cases, as follows:

          MACRO
 &TAG     PACKCHK &DATA=,&L=             DATA=address,L=integer
 &TAG     XC    WORKAREA,WORKAREA        Clear workarea first
          MVN   WORKAREA(&L),&DATA       Move 'numerics'
          TRT   WORKAREA(&L.-1),PACKTBL  All numerics but last 00-09?
          BNE   F1&SYSNDX                 No, bad input.
          CLI   WORKAREA+&L.-1,X'0A'     Last digit less than x'0a'?
          BL    F1&SYSNDX                 Yes, bad sign.
          CLI   WORKAREA+&L.-1,X'0F'     Last digit more than x'0f'?
          BNH   S1&SYSNDX                 No: ok so far.
 F1&SYSNDX BAS  R14,ERRORMSG             Issue messages, etc. passing
          DC    AL2(reasoncode)           reason code for error routine
 S1&SYSNDX DS   0H                       Numerics ok:
          XC    WORKAREA,WORKAREA        Wipe workarea again
          MVZ   WORKAREA+1(&L),&DATA     Move zones this time to +1
          MVO   WORKAREA(&L.+1),WORKAREA(&L.+1)  Shift left 4 bits
          TRT   WORKAREA(&L),PACKTBL     'Zones' within 00-09?
          BE    S2&SYSNDX                 Looks ok.
          BAS   R14,ERRORMSG             Issue messages, etc. passing
          DC    AL2(reasoncode)           errexit code
 S2&SYSNDX DS   0H                       Valid packed data: proceed.
          MEND
          :
 PACKTBL  DC    XL10'00',XL246'FF'       Table for 00-09.
 WORKAREA DS    CL16

This seems to work OK, but it seems like there's a more "elegant"
solution.  Anyone have a more clever method that can be generalized
a little?