Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
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.
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 ).
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
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.
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
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
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
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.
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.