Assembler programming without using using – it is all relative

Before Jump

For many years a program on z architecture looked like

MYPROG  CSECT
LR 12,15
USING MYPROG,12
B OVER
DC C'*MYPROG *'
OVER DS 0H
...

LA 3,MYAUTOSTORAGE

USING MYDATA,3
L 4,FIELD2
MYDATA DSECT
FIELD1 DS F
FIELD2 DS F

To reference a field you have to do it off a register. For example

  • B OVER is converted to BR 0x10 off register 12
  • L 4,FIELD2 is converted to Load offset 4 from register 3

Each base register could cover 4KB, so for large programs, or large data you needed multiple registers.

Post Jump

A significant leap in the instructions was the introduction of the “… relative” instruction. For example the Jump (or as it is properly know the BRANCH RELATIVE ON CONDITION) is jump the number of half words from the start of the instruction

OFFSET  
0000 MYPROG CSECT
0000 LR 12,15
0000 USING MYPROG,12
0002 J OVER (A7F4 0007)
0006 DC C'*MYPROG *'
0010 OVER DS 0H F

The Jump instruction A7M4 xxxx) has condition M (F is always branch) and xxxx in this case if 0007. The address of the instruction is 0002, so jump to h2 + 2 * 7 = 0010 — which is the label for OVER.

This is a faster instruction than the B OVER, because it has to do less work. It can jump to +- 65534 bytes, and does not use any base registers. Not using a base register means that more registers can be used to access data.

But ..

I was writing some assembler code within a C program, and hit a few snags. The C code does not make a base register available to access fields.

With code like

MYLABEL  DC C'HELLO'
LA R2,MYLABEL

With base registers, this code will work and create the LA instruction with the offset of MYLABEL from the base register.

However, because there is no base register and USING, the LA instruction fails.

I found two ways of doing it when using relative instructions

Branch and save

          BRAS 2,OVERWTOL
SWTO WTO TEXT=label,MF=L
OVERWTOL DS 0H

This jumps to the label OVERWTOL, and saves the “return address” in register 2. Register 2 points to label SWTO.

Load address relative

OFFSET
0004 SWTO WTO TEXT=label,MF=L
0074 LARL 2,SWTO

Which becomes load address with value -38 half words from the start of the instruction, so “offset” FFFFFFC8

This is half the solution

I was using the WTO macro to write message on the console.

   WTO   text=(Mydata),MF=(E,(4)) 
...
MYDATA DC H'5',CL8'HELLO'

This failed because there was no base register.

I had to use

         LARL   2,MYDATA   
WTO text=((2),MF=(E,(4))
...
MYDATA DC H'5',CL8'HELLO'

and this worked successfully.

Leave a comment