Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

ZAP instrution

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> PL/I & Assembler
View previous topic :: :: View next topic  
Author Message
Deepak nigam

New User


Joined: 04 Mar 2008
Posts: 4
Location: mumbai

PostPosted: Tue Apr 20, 2010 3:58 pm    Post subject: ZAP instrution
Reply with quote

Small doubt about ZAP instrution:
A PL2'5'

ZAP A, A

What does A contain?
my concern is : will it make A to zero and then add zero to zero so the result will be 0.
or the result is 5.
Thanks
Deepak
Back to top
View user's profile Send private message

CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2150
Location: At my coffee table

PostPosted: Tue Apr 20, 2010 4:21 pm    Post subject:
Reply with quote

About ZAP, the z/Architecture Principles of Operation wrote:
The two operands may overlap, provided the rightmost byte of the first operand is coincident with or to the right of the rightmost byte of the second operand. In this case, the result is obtained as if the operands were processed right to left.

I read 'coincident' as at the same address, so I'd say the result would be 5.
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2502
Location: Atlanta, Georgia, USA

PostPosted: Tue Apr 20, 2010 5:50 pm    Post subject: Reply to: ZAP instrution
Reply with quote

ZAP translate to -

"ZERO out Operand 2 before adding Operand 1 to it." (Zero and Add Packed/Decimal).

The internal millicode will ensure that the original contents of 'A' (as Operand 2) is preserved.

COBOL does this all the time to ensure a valid sign-nibble, when Operand 2 is defined as signed packed-decimal and is this is known as 'Zapping Itself'.

FWIW (and in this example), an MVC can be substituted as it is a cheaper instruction.

Bill
Back to top
View user's profile Send private message
Ronald Burr

Active User


Joined: 22 Oct 2009
Posts: 293
Location: U.S.A.

PostPosted: Tue Apr 20, 2010 8:02 pm    Post subject:
Reply with quote

Doing an MVC A,A makes no sense. Either the contents of A would remain unchanged ( as would the condition code ) or the instruction would cause a S0Cx abend ( if the computed address of field A was invalid ).

There IS ( or can be ) value in coding a ZAP A,A instruction, however.
Though a ZAP A,A construct wouldn't change the VALUE of A ( though it might change the sign nibble ), it definitely WOULD result in the setting of the condition code:
* 0 if the value of A was zero,
* 1 if the value of A was less than zero, and
* 2 if the value of A was greater than zero
* a CC of 3 if overflow occurrs, but it cannot with this example.

Thus, a ZAP A,A construct could be used to test whether the value of A is less than zero, zero, or greater than zero - without the need to do a compare ( which would require the storing of a packed zero elsewhere ).
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2502
Location: Atlanta, Georgia, USA

PostPosted: Tue Apr 20, 2010 8:20 pm    Post subject: Reply to: ZAP instrution
Reply with quote

Ron,

The MVC was suggested under the criteria -

Quote:

FWIW (and in this example)

If A were not packed-decimal, then sure, a ZAP would cause a S0C7. However, with a non packed-decimal value, MVC will not, until A was addressed further down in the logic using a packed-decimal instruction or a CVB from a doubleword, which had been populated via an MVC.

In this example, either a ZAP or MVC will work as advertised.

If it were a ZAP A,B and B has an unverified value, then a ZAP is preferred.

Bill
Back to top
View user's profile Send private message
UmeySan

Active Member


Joined: 22 Aug 2006
Posts: 755
Location: Germany

PostPosted: Wed Apr 28, 2010 12:59 pm    Post subject:
Reply with quote

Morning Sir's !

As Ron said, in this case ZAP is used to test the field.

Just one more Info to test a packeddecimal field:

TP D1(L1,B1)

Condition code 0 is set if the field contains all valid
packed decimal digits and sign.

Condition code 1 is set if the sign digit in the field
is invalid.

Condition code 2 is set if at least one digit code in
the field is invalid.

Condition code 3 is set if the sign digit is invalid and
at least one digit code is also invalid.
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2502
Location: Atlanta, Georgia, USA

PostPosted: Wed Apr 28, 2010 4:31 pm    Post subject: Reply to: ZAP instrution
Reply with quote

Hi UmeySan,

The following is a sub-program used to validate a 01 to 16 byte packed-decimal field passed by a COBOL caller. It uses an 'EX' over a 'TP'.

Code:

***********************************************************************
*---------------------------------------------------------------------*
*                                                                     *
*        THE EXTENDED-TRANSLATION FACILITY 2 MUST BE INSTALLED IN     *
*        ORDER FOR THE 'TP' (TEST PACK) INSTRUCTION TO WORK.          *
*                                                                     *
*        EXAMPLE 'CALL' FROM COBOL:                                   *
*                                                                     *
*        03  WS-PARM-LGTH          PIC  9(04)      BINARY.            *
*        03  WS-PARM-DATA          PIC  X(16).                        *
*        03  WS-TESTPKD            PIC  X(08)      VALUE 'TESTPKD'.   *
*        03  WS-DECIMAL-X          PIC  X(05).                        *
*                                                                     *
*        MOVE X'123456789C'            TO WS-DECIMAL-X.               *
*        MOVE WS-DECIMAL-X             TO WS-PARM-DATA.               *
*        MOVE LENGTH OF WS-DECIMAL-X   TO WS-PARM-LGTH.               *
*                                                                     *
*        CALL WS-TESTPKD               USING WS-PARM-LGTH,            *
*                                            WS-PARM-DATA.            *
*                                                                     *
*        UPON RETURN, THE 'RETURN-CODE' SPECIAL-REGISTER (R15) WILL   *
*        EQUAL ZERO (VALID PACKED-DECIMAL DATA), 08 (INVALID DATA) OR *
*        16 (INVALID DATA LENGTH).                                    *
*                                                                     *
*        AFTER ISSUING THE OBLIGATORY 'AHI R7,-1', AN 'SLL,4' IS      *
*        ISSUED AGAINST R7. THIS IS NECESSARY FOR THE 'EX' TO 'OR'    *
*        THE ADJUSTED-LGTH INTO BITS 8-15 OF THE 'TP' INSTRUCTION.    *
*                                                                     *
*        SO FOR EXAMPLE, IF THE ADJUSTED R7 = X'00000004', IT WILL    *
*        CONTAIN X'00000040' AFTER THE SHIFT.                         *
*                                                                     *
*---------------------------------------------------------------------*
***********************************************************************
TESTPKD  CSECT
         USING *,R3                    INFORM ASSEMBLER
         SAVE  (14,12)                 SAVE REGISTERS
         LA    R3,0(,R15)              R3 IS BASE-REGISTER
         L     R7,0(,R1)               POINT TO HWORD-LGTH
         LH    R7,0(,R7)               LOAD AS HWORD
         LA    R15,16                  SET RETURN-CODE
         CHI   R7,16                   EXCEEDS MAX-LGTH?
         BH    RTN2CLLR                YES, RETURN TO CALLER
         AHI   R7,-1                   ZERO OR NEGATIVE LGTH?
         BZ    RTN2CLLR                YES, RETURN TO CALLER
         BM    RTN2CLLR                YES, RETURN TO CALLER
         SLL   R7,4                    SHIFT-LEFT 4-BITS FOR 'EX'
         L     R9,2(,R1)               POINT TO PARM-DATA
         XR    R15,R15                 SET RETURN-CODE
         EX    R7,VALIDATE             VALID DECIMAL-DATA?
         BZ    RTN2CLLR                YES, RETURN TO CALLER
         LA    R15,4                   INVALID SIGN
         BC    4,RTN2CLLR              RETURN WITH A H'4'
         LA    R15,2                   INVALID DIGIT
         BC    2,RTN2CLLR              RETURN WITH A H'2'
         LA    R15,1                   INVALID SIGN AND DIGIT
RTN2CLLR EQU   *
*
         RETURN (14,12),RC=(15)        RETURN TO THE CALLER
*
VALIDATE TP    0(,R9)                  EXECUTED 'TP' (LGTH IN R7)
*
         LTORG ,
*
TESTPKD  AMODE 31
TESTPKD  RMODE ANY
*
         YREGS
*
         END

Regards,

Bill
Back to top
View user's profile Send private message
Ronald Burr

Active User


Joined: 22 Oct 2009
Posts: 293
Location: U.S.A.

PostPosted: Wed Apr 28, 2010 6:31 pm    Post subject:
Reply with quote

Bill,
Shouldn't the line
Code:
         L     R9,2(,R1)               POINT TO PARM-DATA

be
Code:
         L     R9,4(,R1)               POINT TO PARM-DATA

namely, loading R9 from R1 with an offset of 4, not 2?
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2502
Location: Atlanta, Georgia, USA

PostPosted: Wed Apr 28, 2010 6:41 pm    Post subject: Reply to: ZAP instrution
Reply with quote

Ron,

Yes, you're right, the second address.

I mapped it in my brain as consecutive data, but they are two different addresses off the R1 parmlist. icon_rolleyes.gif

While I'm mucking things up royally, these lines -

Code:

         AHI   R7,-1                   ZERO OR NEGATIVE LGTH?
         BZ    RTN2CLLR                YES, RETURN TO CALLER
         BM    RTN2CLLR                YES, RETURN TO CALLER

Should be replaced with -

Code:

         AHI   R7,-1                   NEGATIVE LGTH?
         BM    RTN2CLLR                YES, RETURN TO CALLER

The 'BZ' must be removed as the Hword-Lgth (R7) could have been 01 to 16 prior to the AHI of a -1, resulting in 00 through 15, which is what's needed in R7 for the 'EX'.

A 'BM' indicates that R7 was not greater than H'0' prior to the AHI -1, which results in a negative value.

Thanks for pointing these out....

Regards,

Bill
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> PL/I & Assembler All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:



Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us