Addressing with IBM mainframe processors
The ancestor of today z/Architecture (IBM mainframe) processors indeed were only offering the base-offset addressing. You had to load a base address into a register, and then specified this base register plus a 12-bit offset, i.e. 0 to 4095 bytes to address some storage.
Addressing with S390/Architecture processors
The assembler offers the USING
instruction to help you with this. You specify a label in your program and a register, that will hold the address of that labeled instruction at runtime. The assembler will then calculate the offset for you.
Example
...
LA R5,SUB01
BALR R4,R5
...
SUB01 DS 0H
USING SUB01,R5
...
B SUB01A
...
SUB01A DS 0H
Explanation:
Some way down your program you need to call subroutine SUB01
. You load its address into register 5 (R5
), then branch while saving the return address into register 4 (R4
). This is what the instructions LA R5,SUB01
and BALR R4,R5
do.
In your subroutine, you tell the assembler that R5
is pointing to the address SUB01
with the USING SUB01,R5
. The assembler uses this information to build the branch instruction B SUB01A
. It calculates the offset from SUB01
to SUB01A
.
If the code starting at SUB01
is longer than 4096 bytes, the maximum offset, you need a second, third, fourth, etc register, which point to the next 4k segment, each.
Assuming the code is 10k long, you need three registers. The code might look like this:
...
LA R5,SUB01
BALR R4,R5
...
SUB01 DS 0H
LA R6,4095(,R5)
LA R6,1(,R6)
LA R7,4095(,R6)
LA R7,1(,R7)
USING SUB01,R5,R6,R7
...
B SUB01A
...
SUB01A DS 0H
Explanation:
Upon entry to SUB01
you know that R5
point to that label. You need to load R6
with R5 + 4096
, and R7
with R5 + 8192
. There are different ways to achieve this. I'm showing the one using the load address LA
instruction, which has a maximum offset of 4095 (architecture restriction).
The you tell the assembler that registers R5
, R6
, and R7
can be used to calculate the offsets. It will use R5
if the offset is 0-4095, R6
if the offset is 4096-8191, and R7
of the offset is 8192-12287.
Addressing with z/Architecture processors
With z/Architecture, IBM introduced a set of new instructions that use a 20-bit signed displacement. Those instructions use a signed offset, i.e they can address storage after the address in the base register, but also storage before that address. A 20-bit signed offset provides for relative addressing of up to 524,287 bytes beyond the base address location or of up to 524,288 bytes before it.
You can address much larger areas with those instruction using a single base register.
IBM z/Architecture Description
IBM documents its z/Architecture in a manual called z/Architecture Principles of Operation