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
 

 

Question on BALR

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

Active User


Joined: 09 Jun 2014
Posts: 106
Location: windsor

PostPosted: Tue Mar 10, 2015 2:07 am    Post subject: Question on BALR
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

Global Moderator


Joined: 14 Mar 2007
Posts: 10202
Location: italy

PostPosted: Tue Mar 10, 2015 2:38 am    Post subject: Reply to: Question on BALR
Reply with quote

follow this link to download the latest version of the IBM z/Architecture Principles of Operation
http://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: 51
Location: Switz

PostPosted: Tue Mar 10, 2015 1:05 pm    Post subject: Reply to: Question on BALR
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 User


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

PostPosted: Thu Mar 19, 2015 12:55 am    Post subject:
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    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 Fault Analyzer - listings question. egrove IBM Tools 4 Thu Aug 11, 2016 5:31 pm
No new posts dataset copy question - REPRO or some... atulxp TSO/ISPF 2 Wed Aug 03, 2016 10:56 pm
No new posts SQL Order By related question Joseph K Thomas DB2 8 Fri Mar 18, 2016 12:53 pm
No new posts DFSort Question krrp DFSORT/ICETOOL 9 Mon Mar 07, 2016 7:11 pm
No new posts Need BALR 12,0 for addressbility ? jackzhang75 PL/I & Assembler 11 Wed Feb 24, 2016 12:23 am


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