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

Question on BALR


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

Active User


Joined: 09 Jun 2014
Posts: 125
Location: US

PostPosted: Tue Mar 10, 2015 2:07 am
Reply with quote

Hi experts,

I just new to the assembler , i saw many program starting with

Code:
BALR R12,R0
USING*, R12


I know it is something about the Base-Displacement.
The first insturction will load R12 with R0 address and then use R0 address as base register address . So do we need assgin the R0 address first ? How it know what the address of R0?

Thanks
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10872
Location: italy

PostPosted: Tue Mar 10, 2015 2:38 am
Reply with quote

follow this link to download the latest version of the IBM z/Architecture Principles of Operation
www-01.ibm.com/support/docview.wss?uid=isg2b9de5f05a9d57819852571c500428f9a
where You will find all You might want to know about the machine instructions .


BALR Rx,Ry will...

branch to the address specified by the content of the second register used ( Ry )
and load the address of the following instruction into the first register used ( Rx )

as a special case when the second register is the register 0 the instruction will act as a no-operation as far as the branch is concerned,
but it will still load the address of the following instruction into the first register
Back to top
View user's profile Send private message
Paul Voyner

New User


Joined: 26 Nov 2012
Posts: 52
Location: UK

PostPosted: Tue Mar 10, 2015 1:05 pm
Reply with quote

Enrico's said what it does, but you probably don't understand why it does it. Why execute an instruction which does nothing except load an address into a register ? The clue is in the USING *,R12 which follows. This is one of the ways of establishing a base register (and you've read about what a base register is, right ?). So R12 is loaded with the virtual storage address of that instruction itself, and the USING sets it as a base register for the following program statements.

It's an alternative to
Code:
START   CSECT
        USING *,R15         R15 contains load address
        STM R14,R12,12(R13) save regs
        LR  R12,R15
        USING START,R12     R12 Base register


See if you can work out what is different about these 2 methods
Back to top
View user's profile Send private message
steve-myers

Active Member


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

PostPosted: Thu Mar 19, 2015 12:55 am
Reply with quote

There is a fundamental problem with Mr. Voyner's example. Look at this listing -
Code:
  Loc  Object Code    Addr1 Addr2  Stmt   Source Statement

000000                00000 00058     1 START    CSECT
                 R:F  00000           2          USING *,15
000000 90EC D00C            0000C     3          STM   14,12,12(13)
000004 18CF                           4          LR    12,15
                 R:C  00000           5          USING START,12
** ASMA300W USING overridden by a prior active USING on statement number 2
** ASMA435I Record 5 in XXXXXX.START.ASM on volume: VVVVVV
000006 41F0 F010            00010     6          LA    15,SAVEAREA
Notice the base register used in the LA instruction.

A frequent problem with Assembler code is when you have two possible base registers for the same address. The ASMA300W diagnostic message was added to HLASM to illustrate the possible problem. The rules to select the base register when more than one base register can be used are discussed in the HLASM Language Reference manual. In this example HLASM followed its rules and selected what amounts to the wrong base register.

Compare
Code:
  Loc  Object Code    Addr1 Addr2  Stmt   Source Statement

000000                00000 00058     1 START    CSECT
000000 90EC D00C            0000C     2          STM   14,12,12(13)
000004 18CF                           3          LR    12,15
                 R:C  00000           4          USING START,12
000006 41F0 C010            00010     5          LA    15,SAVEAREA
and
Code:
  Loc  Object Code    Addr1 Addr2  Stmt   Source Statement

000000                00000 00058     1 START    CSECT
000000 90EC D00C            0000C     2          STM   14,12,12(13)
000004 05C0                           3          BALR  12,0
                 R:C  00006           4          USING *,12
000006 41F0 C00A            00010     5          LA    15,SAVEAREA
The first depends on the usual convention that register 15 contains the entry point address; the second does not depend on this convention. But look at the LA instruction. In the first example, the displacement corresponds to the offset of the address. Many programmers find this to be very convenient. In the second example this is not true.
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 Question for file manager IBM Tools 7
No new posts question for Pedro TSO/ISPF 2
No new posts question on Outrec and sort #Digvijay DFSORT/ICETOOL 20
No new posts panel creation question TSO/ISPF 12
No new posts Sort w/OUTREC Question DFSORT/ICETOOL 2
Search our Forums:

Back to Top