Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Difference in Base register for same variable noticed in prg

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> PL/I & Assembler
View previous topic :: :: View next topic  
Author Message
anki

New User


Joined: 04 Apr 2008
Posts: 23
Location: Pune

PostPosted: Wed Sep 17, 2008 5:44 pm    Post subject: Difference in Base register for same variable noticed in prg
Reply with quote

Hello,
While assembling one of the program I have noticed difference in the Base register used for same symbol in two instructions. Below is example for the same.

PROGSTAT DS 0H
USING PROGSTAT,R10
.
B LABEL ----> 1st instruction; base reg is R10
.
.
MIDPROG DS 0H
USING MIDPROG,R11
B LABEL ------> 2nd instruction; base reg is R11
.
LABEL DS 0H

As per my knowledge, Assembler works in two passes. In first pass, all symbol gets entered in to the symbol table along with its base and displacement. While in second pass, using the symbol table all used Label's base displacement are entered in Machine Code. So how come same label can have different base at two different instructions? Are there two entries in symbol table?

Please let me know, if more information is required or want me to make myself more clear?

Also advise me any good document/link which is describing Assembler working (i.e. Pass1 and pass 2) in detail.

Thanks,
Ankit
Back to top
View user's profile Send private message

Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8057
Location: East Dubuque, Illinois, USA

PostPosted: Wed Sep 17, 2008 6:21 pm    Post subject:
Reply with quote

Quote:
So how come same label can have different base at two different instructions?
Because you told it to. Review the use of USING which establishes a base register.
Back to top
View user's profile Send private message
nevilh

Active User


Joined: 01 Sep 2006
Posts: 258

PostPosted: Wed Sep 17, 2008 7:01 pm    Post subject:
Reply with quote

Could it be that it is a large program and needs 2 base registers. Is MIDPROG(R11) equal to PROGSTAT(R10) + 4095 ?
Back to top
View user's profile Send private message
anki

New User


Joined: 04 Apr 2008
Posts: 23
Location: Pune

PostPosted: Thu Sep 18, 2008 9:04 am    Post subject: It is not a large program.
Reply with quote

I do understand your question. But I don't think, this is the reason of difference in base register, as the program is smaller than 4095.
-------------------------------------------------------------------------------------
You can try it yourself and notice a difference:
Lets define a subroutine and assign a new base register specificly for that routine [as I did in MIDPROG in example]. Now insert two branch intruction in program such that, one is outside the routine and one is inside the routine to a label which is defined inside routine. [in my example Label is "LABEL" to which we are branching from two places].
Now try to assemble this program, and you would come to know this difference.
-------------------------------------------------------------------------------------

I believe, if we know how assembler works in Pass-1 and Pass-2 then we can easily answer my question. Till I got this question in my mind, I was thinking that I know Pass-1 and Pass-2 very well......
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8057
Location: East Dubuque, Illinois, USA

PostPosted: Thu Sep 18, 2008 5:25 pm    Post subject:
Reply with quote

Ignore pass 1 and 2 -- it has no bearing on the issue. This is tough to explain without a diagram, but here goes:

Assumptions:
PROGSTAT is located at memory address 1000
MIDPROG is located at memory address 1100
LABEL is located at memory address 1200

When you say USING PROGSTAT,R10 you are saying that R10 has been loaded with hex 1000 and establishes an offset of 200 from R10 for the address of LABEL.

When you say USING MIDPROG,R11 you are saying that R11 has been loaded with hex 1100 and establishes an offset of 100 from R11 for the address of LABEL.

The first branch is based on R10 so it loads the address as 200 from R10. The second branch is based on R11 so it loads the address as 100 from R11. That's the whole point of a base register.

Note the address of LABEL in memory is the same in both cases -- what is different is the offset from the base register, because the address of LABEL is fixed in memory but the base register offsets to LABEL depend on what address the base register was loaded with.

The symbol table should contain the absolute address of LABEL from the start of the program, but the branch instructions in your program do not use the symbol table -- they use the relative offsets depending on the base register in use at the time the branch is invoked.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> PL/I & Assembler All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Converting Variable block file to Fix... bhavana yalavarthi DFSORT/ICETOOL 10 Tue May 16, 2017 2:20 pm
No new posts Getting error while opening a variabl... apandey1 COBOL Programming 5 Fri May 05, 2017 12:22 pm
No new posts Writing on to GSAM variable length rohanthengal JCL & VSAM 6 Fri Mar 03, 2017 7:46 pm
No new posts Count Trailing Spaces in variable str... Virendra Shambharkar SYNCSORT 10 Thu Feb 02, 2017 12:23 pm
No new posts Difference between TWALENG and TWASIZE Arunkumar Chandrasekaran CICS 3 Tue Jan 03, 2017 12:57 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us