We know that every instruction is converted base + offset and the offset max size is set to 4K (4096). What if my program size is more than 4k?
Line 1 : Base + 1 ,
Line 2 : Base + 5 ,
.
.
.
.,
Line x : base + 4090
How the Line x onwards is addressed like Base + offset as the instruction is beyond the page size 4096?
How the instruction from Line X onwards is assembled? Do we need to change the base address to the starting of next page where the instruction is held?
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
USINGinstruction 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
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 instructionsLA R5,SUB01andBALR R4,R5do.In your subroutine, you tell the assembler that
R5is pointing to the addressSUB01with theUSING SUB01,R5. The assembler uses this information to build the branch instructionB SUB01A. It calculates the offset fromSUB01toSUB01A.If the code starting at
SUB01is 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:
Explanation: Upon entry to
SUB01you know thatR5point to that label. You need to loadR6withR5 + 4096, andR7withR5 + 8192. There are different ways to achieve this. I'm showing the one using the load addressLAinstruction, which has a maximum offset of 4095 (architecture restriction).The you tell the assembler that registers
R5,R6, andR7can be used to calculate the offsets. It will useR5if the offset is 0-4095,R6if the offset is 4096-8191, andR7of 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