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?
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
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
Joined: 30 Nov 2013 Posts: 917 Location: The Universe
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
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.