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

Need BALR 12,0 for addressbility ?


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: Wed Feb 24, 2016 12:23 am
Reply with quote

Hi Experts,

Do we need BALR 12,0 for addressbility or just use USING will be ok?
i saw the code is written as
Code:
BALR   12,0
USING  *,12


As i know USING is tell assambler which base register and address will be used in order to compute the object code and BALR is pass the address to register during the run time. I just confused since program should be loaded anywhere in memory , why need BALR to assgin the address to register ?

I try to write the simple code only few line and get abend 0C4 don't know why?
Sorry for the newbie question.

Code:
        BALR   12,0     
        USING  *,12     
 MOVE   MVC    NUM1,NUM2
 NUM1   DC     CL5'ABCDE'
 NUM2   DC     CL3'FGH' 
 NUM3   DC     CL4'IJKL'
        END             
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Wed Feb 24, 2016 12:28 am
Reply with quote

You're getting the S0C4 because your constants are in the logic flow and the Assembler doesn't know this.

You need to branch around the constants to executable instructions.

But your program needs more work than that.

HTH....
Back to top
View user's profile Send private message
steve-myers

Active Member


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

PostPosted: Wed Feb 24, 2016 5:11 am
Reply with quote

The USING Assembler instruction is you (the programmer) promising the Assembler that you (the programmer) will insert an address into a register. For example -
Code:
MYPGM    CSECT
         SAVE  (14,12),,*
         BALR  12,0
         USING *,12
         AP    NUM1,NUM2
         RETURN (14,12),RC=0
NUM1     DC    PL5'25000'
NUM2     DC    PL3'12512'
         END   ,
In this program, you have already stored an address into a register. The Assembler generates -
Code:
  Loc  Object Code    Addr1 Addr2  Stmt   Source Statement         
000000                00000 00028     1 MYPGM    CSECT             
                                      2          SAVE  (14,12),,*   
000000 47F0 F00A            0000A     4+         B     10(0,15)     
000004 05                             5+         DC    AL1(5)       
000005 D4E8D7C7D4                     6+         DC    CL5'MYPGM'   
00000A 90EC D00C            0000C     7+         STM   14,12,12(13)
00000E 05C0                           8          BALR  12,0         
                 R:C  00010           9          USING *,12         
000010 FA42 C010 C015 00020 00025    10          AP    NUM1,NUM2   
                                     11          RETURN (14,12),RC=0
000016 98EC D00C            0000C    13+         LM    14,12,12(13)
00001A 41F0 0000            00000    14+         LA    15,0(0,0)   
00001E 07FE                          15+         BR    14           
000020 000025000C                    16 NUM1     DC    PL5'25000'   
000025 12512C                        17 NUM2     DC    PL3'12512'   
                                     18          END   ,           
The USING statement is a convenience for you, the programmer. Without the USING statement and other Assembler aids, you would write -
Code:
MYPGM    CSECT
         DC    X'FA42F00AF00F'
         DC    X'1BFF'
         DC    X'07FE'
         DC    X'000025000C'
         DC    X'12512C'
         END   ,
rather than -
Code:
MYPGM    CSECT
         AP    NUM1-MYPGM(5,15),NUM2-MYPGM(3,15)
         SR    15,15
         BR    14
NUM1     DC    PL5'25000'
NUM2     DC    PL3'12512'
         END   ,
or
Code:
MYPGM    CSECT
         USING *,15
         AP    NUM1,NUM2
         SR    15,15
         BR    14
NUM1     DC    PL5'25000'
NUM2     DC    PL3'12512'
         END   ,
Which one would you rather write? I spent 7 years of my life writing the equivalent of the first example as AMASPZAP control statements, but it was no joy - and error prone!
Back to top
View user's profile Send private message
jackzhang75

Active User


Joined: 09 Jun 2014
Posts: 125
Location: US

PostPosted: Wed Feb 24, 2016 7:42 pm
Reply with quote

Hi steve,

Thank you for your answer. For USING instruction i think i can undersatnd what 's it or why need it . But my question is that i don't know do we really need BALR 12,0 together with USING *,12 ?
Back to top
View user's profile Send private message
Willy Jensen

Active Member


Joined: 01 Sep 2015
Posts: 734
Location: Denmark

PostPosted: Wed Feb 24, 2016 8:07 pm
Reply with quote

If r12 contains the address of your program when called then no - but that is normally not the case. It is good practice to set up a base register yourself at the start of the program. R15 should contain the address of your program, but r15 is changed by some macros and program calls, so is not normally considered safe to use. Hence the use of r12.
Back to top
View user's profile Send private message
steve-myers

Active Member


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

PostPosted: Wed Feb 24, 2016 8:35 pm
Reply with quote

For the USING to be useful, the address has to be placed into the register.
Code:
MYPGM    CSECT
         USING WORKAREA,11
         USING *,12
         SAVE  (14,12)
         LR    12,15
         GETMAIN R,LV=WASIZE
         LR    11,1
         ...
         USING RECORD,10
         GET   ADCB
         LR    10,1
         ...
WORKAREA DSECT
         ...
ADCB     DCB   DSORG=PS,MACRF=GL,...
WASIZE   EQU   *-WORKAREA
         ...
RECORD   DSECT
         ...
In this arrangement, which is fairly typical, there are 3 USING statements to cover 3 different storage areas.
  • Register 12 defines addressability for the program area. The address started in register 15, and was copied to register 12. This follows the convention that when a program is called, it's address is stored in register 15 and the transfer to the program is achieved by BALR 14,15. It could just as well be BALR 12,0/USING *,12, where BALR stores the address in the register.
  • Register 11 defines addressability for a work area that is defined by the WORKAREA DSECT. The address is obtained by the GETMAIN macro, and copied to register 11.
  • Register 10 defines addressability to a data record. The GET macro stores the record address in register 1, and the program copies the address to register 10.
Many of my larger programs are constructed like this -
Code:
MYPGM    CSECT
         USING WORKAREA,11
         USING *,12
         SAVE  (14,12)
         LR    12,15
         BAL   11,*+L'*+4
         DC    AL4(WORKAREA)
         L     11,0(,11)
         ...
         USING RECORD,10
         GET   ADCB
         LR    10,1
         ...
WORKAREA CSECT
         ...
ADCB     DCB   DSORG=PS,MACRF=GL,...
         ...
RECORD   DSECT
         ...
This separates the program text from the work area text. In -
Code:
         BAL   11,*+L'*+4
         DC    AL4(WORKAREA)
         L     11,0(,11)
  • The BAL machine instruction stores the address of the work area address in register 11.
  • The DC Assembler instruction specifies the address of the work area.
  • The L machine instruction loads the address of the work area.
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Wed Feb 24, 2016 8:50 pm
Reply with quote

A heads up -

For Assembler sub-programs (not MAIN), which require addressability (or, maybe not) to the HLL/LE compliant Caller's "CEECAA" (Common Anchor Area), don't use R12 because the CAA is always based off the Caller's R12. Just leave R12 free just in case and pick another register (IE: R3).

HTH....
Back to top
View user's profile Send private message
steve-myers

Active Member


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

PostPosted: Wed Feb 24, 2016 9:45 pm
Reply with quote

Mr. O'Boyle's comments are for programs that are expected to run in an LE non XPLINK environment, which doesn't apply to standalone Assembler programs. LE non XPLINK compliant programs are a whole different topic, as is true of LE XPLINK compliant programs.
Back to top
View user's profile Send private message
jackzhang75

Active User


Joined: 09 Jun 2014
Posts: 125
Location: US

PostPosted: Thu Feb 25, 2016 12:43 am
Reply with quote

BLAR 12,0 will copy the insturction address counter into Register 12 which will be the next instruction address that CPU will be exceute . R15 by standard rule is the entry point for the program .
Code:

BLAR    12,0
USING  *,12


will be the same as
Code:
L          R12,R15
USING   *, R12


?? The address in base register R12 will be the same address in above two code ?

Thanks
Back to top
View user's profile Send private message
Willy Jensen

Active Member


Joined: 01 Sep 2015
Posts: 734
Location: Denmark

PostPosted: Thu Feb 25, 2016 1:16 am
Reply with quote

Nope.
L 12,15 will attempt to load r12 with contents of storage address x'15'. in older machines that itself would generate an error as 'x15' if not properly aligned. The correct instruction here is:
LR 12,15 which will copy the contents of r15 to r12.
But then you must have your using specify the start of the program. Your USINGs will make the basereg cover from position 2 and 4 respectively in your samples, and r15 points to position 0. I say position 2 and 4 respectively because 'balr' is 2 bytes and 'l' is 4 bytes in length.
So something like this:
MYPROG CSECT
LR 12,15
USING MYPROG,12

But it seems to me that you really need an assembler course, as we haven't even mentioned other necessary stuff like linkage conventions.
Back to top
View user's profile Send private message
jackzhang75

Active User


Joined: 09 Jun 2014
Posts: 125
Location: US

PostPosted: Thu Feb 25, 2016 1:24 am
Reply with quote

Thank you Willy . i should mean LR 12,15 , it was typo.

The following two code should have same function to provide the addressbility and the address inside R12 should be the same for both code ,right ?

Code:
MYPROG CSECT
LR 12,15
USING MYPROG,12


and

Code:
MYPROG CSECT
BALR   12,0
USING MYPROG,12


Yes, i really learning now.
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 Feb 25, 2016 1:41 am
Reply with quote

No, I don't think you have learned anything.

In
Code:
MYPGM    CSECT
         USING *,12
         SAVE  (14,12)
         LR    12,15
Register 12 has the address of MYPGM because that's what was in register 15.

In
Code:
MYPGM    CSECT
         SAVE  (14,12)
         BALR  12,0
         USING *,12
Register 12 will have an address greater than the address of MYPGM. How much greater depends on the number of instructions in the SAVE macro, plus 2 more bytes for the BALR instruction. In both these examples, the incoming registers have been saved before the LR or BALR instruction altered register 12.
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 on BALR PL/I & Assembler 3
No new posts XCTL,LINK,LOAD,BALR (BASR) and CALL. PL/I & Assembler 15
Search our Forums:

Back to Top