Page 1 of 1

Unable to initialize packed decimal using ZAP/SP instruction

PostPosted: Tue Jan 17, 2017 8:55 am
by monica1
Hi,

I am trying to use the below instruction to initialize one of the packed decimal field during processing inside an assembler program.

ZAP TEMPNUM,ZEROES

where TEMPNUM and ZEROES are declared as below.

TEMPNUM DC PL2'0'
ZEROES DC PL2'0'


TEMPNUM is being used in few calculations in the program but ZEROES remain the same throughout.

However my TEMPNUM is not getting initialised to zeroes on using the ZAP instruction.

I also tried using the SP instruction like below

SP TEMPNUM,TEMPNUM to move zeroes but I can see that TEMPNUM still has some values inside it.

Could you let me know if there is anything missing?

Thank you.

Re: Unable to initialize packed decimal using ZAP/SP instruc

PostPosted: Tue Jan 17, 2017 10:07 am
by Robert Sample
but I can see that TEMPNUM still has some values inside it.

Could you let me know if there is anything missing?
What values? And how are you looking to see that TEMPNUM "has some values inside it"?

And why do you think that you are the first person, in all the many thousands of people to use the ZAP instruction over the last many years, to have it perform incorrectly? It is vastly more likely that you are either misinterpreting the value, or you are misrepresenting what you are doing.

Re: Unable to initialize packed decimal using ZAP/SP instruc

PostPosted: Tue Jan 17, 2017 10:31 am
by monica1
Hi Robert,

I used the below lines of code to check the value in TEMPNUM.

 ZAP  TEMPNUM,ZEROES
 L    6,TEMPNUM
 WTO  'DISPLAY5'
 DC H'0'   ABEND PROGRAM


So, when my program abends, register 6 should have shown zeroes. Instead it is showing 295C which was the value of TEMPNUM computed in one of the previous steps. That is how I determined that TEMPNUM is not getting initialised to zeroes.

PSW AT TIME OF ERROR  078D0000   00007DCC  ILC 2  INTC 01            
  ACTIVE LOAD MODULE           ADDRESS=00007C40  OFFSET=0000018C    
  NAME=STUDEG                                                        
  DATA AT PSW  00007DC6 - E8F50A23  000047F0  C0204510              
  GR 0: 00000000_00011000   1: 00000000_00A9AC73                    
     2: 00000000_00000040   3: 00000000_007DA9D4                    
     4: 00000000_007DA9B0   5: 00000000_007FF510                    
     6: 00000000_000C295C   7: 00000000_FD000000                    
     8: 00000000_007DCD30   9: 00000000_007FF7D0                    
     A: 00000000_00000000   B: 00000000_007FF510                    
     C: 00000000_40007C46   D: 00000000_00007F64                    
     E: 00000000_50007DAC   F: 00000010_00000000                    
END OF SYMPTOM DUMP

Re: Unable to initialize packed decimal using ZAP/SP instruc

PostPosted: Tue Jan 17, 2017 12:35 pm
by BillyBoyo
The length of your field is two bytes, a half-word happens to be that long. L(oad) operates on Words, four bytes long. You have loaded four bytes starting at the address of TEMPNUM. If you look at the first two bytes of Register six, you'll see your X'000C', then then value which just happens to be two bytes to the right of TEMPNUM.

If you want to only put two bytes in a register, LH (Load Halfword) can do it.

Re: Unable to initialize packed decimal using ZAP/SP instruc

PostPosted: Tue Jan 17, 2017 1:43 pm
by krishnaraj6eee
Load will move the 4 byte data from storage to register. And TEMPNUM PL2'0' will occupy only 2 bytes. That means if you try to move the Tempnum to register 6 first two bytes will have the data of tempnum and next two bytes will have the data at the address tempnum+2 and tempnum+3.
"6: 00000000_000C295C" In this 000c is the data present in the tempnum
Correct me if i'm wrong.

Re: Unable to initialize packed decimal using ZAP/SP instruc

PostPosted: Tue Jan 17, 2017 8:02 pm
by steve-myers
From Principles of Operation - "The second operand is placed at the first-operand location. The operation is equivalent to an addition to zero. The operand and result are in the packed format."

The second sentence effectively says TEMPNUM is set to a packed decimal 0 - 000C, and then the contents of ZEROES, presumably 000C, is added to it.

monica1 - You have got to learn, much better than you seem to understand now -
  • Exactly how packed decimal values are represented in storage.
  • How to use and understand the Assembler listing.
      Loc  Object Code    Addr1 Addr2  Stmt   Source Statement
    00000A                                6 TEMPNUM  DS    PL2  
    00000C 000C                           7 ZEROES   DC    PL2'0'
    This is telling you that ZEROES is 000C.
  • I'd bet you did not bother to read, much less attempt to understand, the reference I gave you a couple of days ago on the other help site. Preparing those links is somewhat involved - they are not put into a response by magic - and such blatant disregard of them makes it much less likely a responder - Billyboyo, krishnaraj6eee or me, for example, will bother to respond to your queries in the future.
  • What happens when an instruction is executed.
  • How to read the contents of a "dump," whether it is a more complete storage dump or the little summary dump you gave us.

Re: Unable to initialize packed decimal using ZAP/SP instruc

PostPosted: Wed Jan 18, 2017 12:33 am
by steve-myers
monica1 wrote:... I also tried using the SP instruction like below

SP TEMPNUM,TEMPNUM to move zeroes but I can see that TEMPNUM still has some values inside it.

Could you let me know if there is anything missing?

Thank you.


The problem with

SP TEMPNUM,TEMPNUM

is what if the contents of TEMPNUM is not a packed decimal number? The definition of the SP instruction is both operands must be a packed decimal number, and it will fail if the contents of both operands are not packed decimal.

ZAP TEMPNUM,ZEROS

TEMPNUM DS PL2
ZEROS DC P'0'

requires that the contents of ZEROS must be packed decimal.

To test your idea, I wrote this program -

SP       CSECT          
         USING *,15    
         SP    NUM1,NUM1
         SP    NUM2,NUM2
         SR    15,15    
         BR    14      
NUM1     DC    P'-999'  
NUM2     DC    P'999'  
         END   SP


I then run it using TSO TEST

This is the session log -

test sp
 TEST
l (num1 num2) x
 NUM1  999D

 NUM2  999C
 TEST
go
 PROGRAM UNDER TEST HAS TERMINATED NORMALLY+
 TEST
l (num1 num2) x
 NUM1  000C

 NUM2  000C


The LIST (L) command is quite flexible. It will normally convert numerics to printable decimal. Here I told it to list the data as hexadecimal.

test sp      
 TEST        
l (num1 num2)
 NUM1  -999  
             
 NUM2  +999  
 TEST

Re: Unable to initialize packed decimal using ZAP/SP instruc

PostPosted: Thu Jan 19, 2017 10:05 am
by monica1
Thank you very much for all your help.

I was able to resolve my issue. This piece of code which I was trying to initialize was inside a loop and towards the end of a loop due to an incorrect instruction, values from another variable were being populated into TEMPNUM.

Once that instruction was corrected, the issue got resolved.

Thanks again everyone.