Displaying an hex Value.



IBM's cross-platform compiler PL/I for MVS, VM & VSE, OS/390 and Enterprise PL/I for z/OS

Displaying an hex Value.

Postby anbullavan » Mon Apr 02, 2012 11:30 am

Hi everybody,

I'am a newbie to PL/1 and I'm now trying to execute some sample programs to understand the concepts of PL/1. I'm trying to do a simple program to understand the pointer concept. My aim is to display the value of a variable and the address location it is stored. Below the code. When i'm executing the below program it abends with SOC4 Protection exception error. I understand this is because of iam trying to display a Hexa variable using PUT list( Var A). Can somebody here guide me on how I can acheive my expected result.

Please excuse me this is a very Noob question. :-)

MAINSUB:PROC OPTIONS(MAIN) REORDER;                                                     
DCL A POINTER;                                       
DCL B CHAR(10) BASED(A);                             
DCL SYSPRINT FILE STREAM OUTPUT PRINT;               
B = '500';                                           
PUT SKIP LIST('A =',A);                             
PUT SKIP LIST('B =',B);       
END MAINSUB;
anbullavan
 
Posts: 8
Joined: Thu Mar 29, 2012 1:37 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Displaying an hex Value.

Postby BillyBoyo » Mon Apr 02, 2012 11:55 am

The value of your pointer (A) will be zero or some random value, so highly likely to be outside storage that you can access. You then assign to B. S0C4.

It is important to learn how to find which instruction in your program has caused an abend. It prevents idle speculation about instructions which have not been reached yet.

If you want to delete/comment-out "B = '500'" and the PUT for B, you may find that your program will run, and you can see the value of A.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times

Re: Displaying an hex Value.

Postby anbullavan » Mon Apr 02, 2012 12:06 pm

Hi Billy , thanks for your time and response. Yes , when i commented out the B= 500 and PUt for B , I was able to see the Value of PTR A and it is as you said Zero.
anbullavan
 
Posts: 8
Joined: Thu Mar 29, 2012 1:37 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Displaying an hex Value.

Postby BillyBoyo » Mon Apr 02, 2012 12:23 pm

For your code to work, you'll need A to be "pointing" to some storage which belongs to you.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times

Re: Displaying an hex Value.

Postby anbullavan » Mon Apr 02, 2012 1:35 pm

Billy,

DCL B CHAR(10) BASED(A); --> Doesn't mean that A pointer is pointing to B ??? My understanding was that.. Please correct me.
anbullavan
 
Posts: 8
Joined: Thu Mar 29, 2012 1:37 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Displaying an hex Value.

Postby BillyBoyo » Mon Apr 02, 2012 1:52 pm

No, that is not the case. Not according to the manual as I read it. Nor according to what you have written so far. Where did you get that idea?
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times

Re: Displaying an hex Value.

Postby anbullavan » Mon Apr 02, 2012 5:08 pm

BillyBoyo wrote:No, that is not the case. Not according to the manual as I read it. Nor according to what you have written so far. Where did you get that idea?


Hi Billy,

Sorry it was my fault that I didnt read the concept well. I made the following changes in the code, and now I'm able to display the variable and the address where it is stored . Thanks for giving your time and making me understand .. Correct me if I missed something here.

MAINSUB:PROC OPTIONS(MAIN) REORDER;                 
INC LBSLATPZ                                       
DCL A POINTER;                                     
DCL 1 BGROUP,                                       
    3 BFUNC CHAR(03) INIT ('KAR');                 
A = ADDR(BGROUP);                                   
DCL SYSPRINT FILE STREAM OUTPUT PRINT;             
PUT SKIP LIST('A =',A);                             
PUT SKIP LIST('B =',BFUNC);   
END MAINSUB; 


Output

A =                     000394E0                                     
B =                     KAR                               
anbullavan
 
Posts: 8
Joined: Thu Mar 29, 2012 1:37 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Displaying an hex Value.

Postby prino » Mon Apr 02, 2012 5:23 pm

You are absolutely clueless about pointers, aren't you?
Robert AH Prins
robert.ah.prins @ the.17+Gb.Google thingy
User avatar
prino
 
Posts: 635
Joined: Wed Mar 11, 2009 12:22 am
Location: Vilnius, Lithuania
Has thanked: 3 times
Been thanked: 28 times

Re: Displaying an hex Value.

Postby anbullavan » Mon Apr 02, 2012 5:42 pm

prino wrote:You are absolutely clueless about pointers, aren't you?


Yes Prino.. I will read and come back to you.. :D
anbullavan
 
Posts: 8
Joined: Thu Mar 29, 2012 1:37 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Displaying an hex Value.

Postby dick scherrer » Mon Apr 02, 2012 9:11 pm

Hello,

You are absolutely clueless about pointers, aren't you?
Yup, as TS mentioned in the initial post. . .
I'am a newbie to PL/1 and I'm now trying to execute some sample programs to understand the concepts of PL/1. I'm trying to do a simple program to understand the pointer concept.
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 93 times

Next

Return to PL/I

 


  • Related topics
    Replies
    Views
    Last post