Indirect Addressing with AR1 and AR2

Top  Previous  Next

 

For some applications the procedure of the memory indirect addressing is not flexible enough. That is why there are two special registers (AR 1 and AR 2, address register 1 and 2) in the CPU and by their help the index is calculated only during the access. Before the first use of the address registers these have to be loaded with a pointer to an operand. If you want to access the operand I 5.6 you will program:

 

      LAR1   P#5.6   // Load pointer to ‘anything’ 5.6 in AR1

 

Now the address 5.6 is in the address register 1. You ask the input with the following operation:

 

      A I[AR1,P#0.0]

 

But if you want to ask the address I 5.7, program:

 

      A I[AR1,P#0.1]

 

The pointer behind the comma is added to the value in the address register 1, and the result is interpreted as byte- and bit-number of the input. Doing this it is considered that bytes have only got 8 bits, so bit 5.9 becomes bit 6.0.

If you program

 

      A I[AR1,P#0.2]

 

now, the input 6.0 will be evaluated.

You call the whole thing register-indirect-area-internal addressing. You call it area-internal because (in the example) only inputs are accessed.

 

Naturally you can access these not just by bytes, words and DWords.

Example:

 

      L MW[AR2,P#2.0]

 

But there is also the register-indirect-area-crossing addressing. That means that in the approach you do not even have to decide whether inputs, outputs or markers are accessed.

You do it like this:

You load the AR1 with the address Q 5.3:

 

      LAR1   P#Q5.3

 

Then you assign the value of the RLO to the output Q 5.3 by programming:

 

      = [AR1,P#0.0]

 

And corresponding you assign to the output Q 17.2

 

      = [AR1,P#11.7]     // (5.3 + 11.7 = 17.2)

 

Here you can also access to bytes, words and DWords:

 

      L     W[AR1,P#4.0]

 

Strangely the area crossing access to local data is not allowed in a S7-300, but it is in a S7-400. We have prohibited this access in TrySim.

 

!! Attention with Use of the Address Registers !!

 

S7-300 and S7-400 are registered trademarks of the Siemens AG.