Skip to content
systemcoding.dev
Mainframe

Establish a base register with BALR 12,0 and USING *,12

Make a program addressable with BALR 12,0 and USING *,12 so the assembler can turn labels into base and displacement on z/OS 3.1.

1 min read
Summarize in AI

An assembler program has no address of its own until you give it one. BALR 12,0 loads register 12 with the address of the next instruction, and USING *,12 tells High Level Assembler that this location is in register 12, on z/OS 3.1.

base.asmhlasm
MYPROG   CSECT
         BALR  12,0
         USING *,12
         LA    2,MSG
         BR    14
MSG      DC    C'HELLO'
         END   MYPROG
Text
LOC    OBJECT CODE    ADDR1 ADDR2  STMT
000000 05C0                         BALR  12,0
000002                              USING *,12
000002 4120 C006                    LA    2,MSG

The listing is an example of how the assembler resolves MSG, and the column spacing in a real listing differs a little. BALR 12,0 is at offset 0 and is 2 bytes long, so register 12 holds the address of offset 2. MSG is at offset 8, after the 2-byte BALR, the 4-byte LA and the 2-byte BR, which from base 2 is displacement 6, so the LA is built as base 12, displacement 006, which is the C006 in the object code.

The second operand of 0 means "do not branch", so BALR only saves the address. BASR does the same without setting the high-order status bits in the register, and it is the form for new code. A base register addresses 4,096 bytes from where you point it, so a larger program needs more bases or relative-branch instructions.

Also inAssembly
Share

More snippets

Get new posts by email

We send one email when a new post is published. No spam.

Unsubscribe in one click. No spam, ever.