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.
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
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.
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.
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
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?
Joined: 30 Nov 2013 Posts: 917 Location: The Universe
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.