IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Assembler Code to check normal return / error


IBM Mainframe Forums -> PL/I & Assembler
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
amitc23

New User


Joined: 05 Nov 2014
Posts: 95
Location: India

PostPosted: Mon Aug 17, 2015 3:52 pm
Reply with quote

Hi

I have following assembler code. could you please help me understand this.


Code:
READD1 EQU   *                                       
         LA    R0,CARD1          ARG LIST           
         L     RF,DATEENTRY           ENTRY POINT         
         BALR  RE,RF               READ THE CARD       
         BR    R2                  RETURN NORMAL       
         B     DATEOVER            RETURN EOF         
         SPACE 1                                       
DATECON
 .............
..........
..............


In this code ,

How does the program know whether it was a normal return / error / end- of-file (in bold lines above)? I thought both BR and B are uncond to check the efficiencyitional Branches.

Regards
Amit

Code'd
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


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

PostPosted: Mon Aug 17, 2015 4:29 pm
Reply with quote

The sub-program should set R15 to a value (zero being normal) when returning to the NSI (Next Sequential Instruction in the Calling program), which can be found in R14.

Examine the sub-program source and look for a return-code setting in R15.

HTH....
Back to top
View user's profile Send private message
amitc23

New User


Joined: 05 Nov 2014
Posts: 95
Location: India

PostPosted: Mon Aug 17, 2015 4:45 pm
Reply with quote

Thanks Bill

I got the most of it. However one doubt still remains.
Code:

BALR  RE,RF               READ THE CARD
BR    R2                  RETURN NORMAL
B     DATEOVRX            RETURN EOF


In this code , I understand that the return code from the subroutine call would be placed in RF (bits 2-3). But How does system know to execute BR or B (I mean how do they link to the return code received). Or let me put it this way , Why is BR not executed if the return code is not zero.

I searched for help and it says both BR and B is unconditional Branches.

Regards

Code'd
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


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

PostPosted: Mon Aug 17, 2015 4:58 pm
Reply with quote

It looks like "READD1" is a sub-routine that issues a BALR to DATEENTRY, which is invoked via a BAL, because R2 will return you back to the NSI in the program where the BAL had been issued. Without seeing any more of the source, the B DATEOVER seems to be non-executable.

Maybe another member can give an assessment?

If you walk it through a debugger, does the B DATEOVER ever occur?

HTH....
Back to top
View user's profile Send private message
amitc23

New User


Joined: 05 Nov 2014
Posts: 95
Location: India

PostPosted: Mon Aug 17, 2015 5:29 pm
Reply with quote

I don't have a debugger at my installation. However following is DATEOVER and DATECON code.

Code:
DATEOVER EQU   *                                     
         B     DATECON            CONTINUE EXECUTION


DATECON EQU   *                                           
         LA    RD,SAVEREGS         SET MY SAVE AREA       
         L     R1,DATEWRK         RESTORE POINTER ADDR   
         B     MAINLINE            GO TO MODULE EXECUTION


Regards

Code'd, again
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Mon Aug 17, 2015 6:54 pm
Reply with quote

Why don't you show the code for DATEENTRY? Using the Code tags, please.
Back to top
View user's profile Send private message
steve-myers

Active Member


Joined: 30 Nov 2013
Posts: 917
Location: The Universe

PostPosted: Mon Aug 17, 2015 8:48 pm
Reply with quote

amitc23 wrote:
... Thanks Bill

I got the most of it. However one doubt still remains.
Code:

BALR  RE,RF               READ THE CARD
BR    R2                  RETURN NORMAL
B     DATEOVRX            RETURN EOF


In this code , I understand that the return code from the subroutine call would be placed in RF (bits 2-3). But How does system know to execute BR or B (I mean how do they link to the return code received). Or let me put it this way , Why is BR not executed if the return code is not zero.

I searched for help and it says both BR and B is unconditional Branches.

Regards

Code'd
BR x is an Assembler provided shortcut for BCR 15,x. Similarly, B x is an Assembler provided shortcut for BC 15,x.

I do something similar -
Code:
         LA    1,UT2   
         BAS   14,READUT
         B     RIGHTEOF


Code:
READUT   BASR  15,0             
         SAVE  (14,2),,READUT   
         LA    15,72(,13)       
         ST    13,4(,15)         
         ST    15,8(,13)         
         LR    13,15             
         LR    2,1               
         GET   (1)               
         LHI   0,1               
         A     0,UT1COUNT-UT1(,2)
         ST    0,UT1COUNT-UT1(,2)
         L     13,4(,13)         
         ST    1,24(,13)         
         RETURN (14,2)           
         ORG   *-2               
         B     4(,14)           
EOF      DC    0H'0'             
         L     13,4(,13)         
         RETURN (14,2)
The intent in the first code fragment is to branch to a specialized EOF routine if the read gets an EOF. The second code fragment is the actual READ routine. It returns to the NSI+4 if there is no EOF, and to the NSI if there is an EOF. It appears the original author of the TS/OP's code has the same general idea.

The ORG *-2 after the first RETURN macro resets the Assembler's location counter so the B 4(,14) replaces the BR 14 within the RETURN macro.

Just a code style point. Many Assembler programmers avoid

XYZ EQU *
instruction

All machine instructions must be aligned on a half word boundary; there is no guarantee the location counter will be on a half word boundary when an address is assigned to XYZ. In my second code fragment, there is a similar issue for the EOF symbol.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> PL/I & Assembler

 


Similar Topics
Topic Forum Replies
No new posts Error to read log with rexx CLIST & REXX 11
No new posts Error when install DB2 DB2 2
No new posts run rexx code with jcl CLIST & REXX 15
No new posts Compile rexx code with jcl CLIST & REXX 6
No new posts CLIST - Virtual storage allocation error CLIST & REXX 5
Search our Forums:

Back to Top