## d(x,b) explanation?

High Level Assembler(HLASM) for MVS & VM & VSE

### d(x,b) explanation?

So lets say we have A r,D(X,B)

I know the contents of the fullword starting at address given by D(X,B) will be added to register "r"

I get the operation, I'm just confused on the D(X,B) part. I know D is the displacement written in decimal and then converted to hex. B is the base register loaded from the using statement, but I don't understand X.. I get it's for an index register but what does it actually do?

and if the displacement can be up to 4095, what is actually taking place if a register can only hold up to 32 bytes (I believe, that's what I read somewhere).. I thought the displacement is moving the "pointer" up and down the memory address stored in the base register.

The resources I have are just technical information so I still don't understand what is happening and I guess I just need a simple, less book jargon explanation. I get most of the coding but visualizing how everything works with storage from the registers, how much memory each register actually holds and how the addressing is assigned to the base register and where it goes from there, and how everything syncs up with the other registers is all confusing to me currently.

I'm studying Assembly Language in Assist on the z/os system in grad school and I want to have a firm grasp on all this stuff because when I graduate, I'd like to work with embedded systems; and especially have a good chance with jobs like this with Lockheed Martin, Boeing, or/and ultimately NASA. So I'd like to master the subject.

Thank you!
eaglei22

Posts: 8
Joined: Sat Jan 28, 2012 2:30 am
Has thanked: 0 time
Been thanked: 0 time

### Re: d(x,b) explanation?

The address is formed by adding the contents of the index register to the contents of the base register and then adding the displacement. You can think of the addressing adder as a three input adder; the two registers and the displacement.
steve-myers
Global moderator

Posts: 1773
Joined: Thu Jun 03, 2010 6:21 pm
Has thanked: 4 times
Been thanked: 168 times

### Re: d(x,b) explanation?

eaglei22 wrote:... B is the base register loaded from the using statement ... I thought the displacement is moving the "pointer" up and down the memory address stored in the base register.
• The USING Assembler instruction does not "load" anything into any register. It just tells the Assembler that one or more registers contain an address so the Assembler can compute a displacement value.
• The "displacement" is just a number that the machine adds to the contents of a register. In this code, the Assembler generates the exact same machine code for the two A instructions.
APGM     CSECT
...
USING APGM,12
...
A     0,DATA
A     0,DATA-APGM(0,12)
I think the term "index register" is poorly chosen. The 704/709/704x/709x computers had several 15 bit index registers that were distinct from the one and only 36 bit "general purpose" register and the 36 bit MQ register. In the System/360 architecture an "index register" is just a regular 32-bit register that is an "index register" only because it is used as a second register in an instruction that allows for index registers.

z/Architecture machines have 16 64-bit "general purpose" registers. The traditional System/360 32 bit register instructions just use the low order 32 bits of these registers.

You have another misconception. z/Architecture systems have 3 addressing modes:
• The 24 bit addressing mode inherited from the original System/360 architecture. When this addressing mode is used only the low order 24-bits of the registers specified as base and index registers are used in addressing arithmetic.
• The 31-bit addressing mode inherited from "Extended Architecture" systems. When this addressing mode is used only the low order 31 bits of the registers specified as base and index registers are used in addressing arithmetic. Most IBM system programs and vendor programs use this addressing mode, as do essentially all compiled programs compiled using recent compilers.
• The 64-bit addressing mode that uses the 64-bit registers in z/Architecture machines. This addressing mode is very infrequently encountered in Assembler programs; Java uses it, but that's about all.
steve-myers
Global moderator

Posts: 1773
Joined: Thu Jun 03, 2010 6:21 pm
Has thanked: 4 times
Been thanked: 168 times

### Re: d(x,b) explanation?

One more comment.

Most Assembler programmers never use index registers. The few that do use index registers don't use them very often. There are at least 2 reasons -
• Many instructions do not support their use.
• Many data areas contain more than 1 byte; the index value must be adjusted to account for this issue. The Add instruction used in our examples is a prime reason for this; the data area it uses contains 4 bytes, so the index must be a multiple of 4.
Many times when indexing might be appropriate many Assembler programmers just use a register containing the exact address of the data and update the register address as required. No index register is required.
steve-myers
Global moderator

Posts: 1773
Joined: Thu Jun 03, 2010 6:21 pm
Has thanked: 4 times
Been thanked: 168 times

### Re: d(x,b) explanation?

An Example - The following program is an example of the correct use of the USING Assembler instruction, establishing addressing and the use of indexing. The program returns the sum of the binary values in TABLE as a return code in register 15. This program also illustrates the use of the BXLE instruction, another instruction that seems to scare many Assembler programmers.
INDEX    CSECT
USING *,12
SAVE  (14,12),,*
LR    12,15
SR    3,3
LA    4,L'TABLE
LA    5,TABSIZE-L'TABLE
SR    15,15
LOOP     A     15,TABLE(3)
BXLE  3,4,LOOP
RETURN (14,12),T,RC=(15)
TABLE    DC    F'1,5,-6,0'
TABSIZE  EQU   *-TABLE
END   INDEX

The LR immediately after the SAVE macro call copies the entry point address in register 15 to register 12.

LA 4,L'TABLE loads the length of an entry in TABLE.

LA 5,TABSIZE-L'TABLE loads the offset of the last entry in the table into register 5.

BXLE (Branch indeX Low or Equal) is a complex instruction. First, it adds the contents of register 4 to register 3. Then it compares the contents of register 3 and register 5. If register 3 is less than or equal to register 5 it performs the branch. This is a classic use of BXLE in that registers 3 and 5 contain values suitable for indexing.

One reason why many programmers shy away from BXLE (and its companion, BXH) it uses so many registers. It's a sad truth about Assembler programmers; we tend to manage register usage very poorly, so it often seems difficult to assign three registers for a BXLE loop, two of them the even/odd pair BXLE and BXH usually require.
steve-myers
Global moderator

Posts: 1773
Joined: Thu Jun 03, 2010 6:21 pm
Has thanked: 4 times
Been thanked: 168 times