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

Difference in Base register for same variable noticed in prg


IBM Mainframe Forums -> PL/I & Assembler
Post new topic   Reply to topic
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
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: 8696
Location: Dubuque, Iowa, USA

PostPosted: Wed Sep 17, 2008 6:21 pm
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: 262

PostPosted: Wed Sep 17, 2008 7:01 pm
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
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: 8696
Location: Dubuque, Iowa, USA

PostPosted: Thu Sep 18, 2008 5:25 pm
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> PL/I & Assembler

 


Similar Topics
Topic Forum Replies
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts Variable Output file name DFSORT/ICETOOL 8
No new posts Timestamp difference and its average ... DB2 11
No new posts Difference when accessing dataset in ... JCL & VSAM 7
No new posts Moving Or setting POINTER to another ... COBOL Programming 2
Search our Forums:

Back to Top