[?]: Pointer Information

SIMATIC S7-200/300/400, Step7, PCS7, CFC, SFC, PDM, PLCSIM,
SCL, Graph, SPS-VISU S5/S7, IBHsoftec, LOGO ...
yogi_g2982
Posts: 15
Joined: Fri May 18, 2012 8:54 am

[?]: Pointer Information

Post by yogi_g2982 »

Hi,

I need help to learn pointer.
I need some documents to learn pointer and some good example.
I have seen lot of pointer program in that many times programmer used this instruction SLD 3, SLD 4 and SLD 5 to create pointer.
Can anybody tell me why we used this instruction (SLD 3, SLD 4 and SLD 5 ) in pointer.


Waiting for your reply,

Yogesh
delege
Posts: 9
Joined: Wed Sep 08, 2010 6:09 pm

Re: [?]: Pointer Information

Post by delege »

If you to the online help of siemens, u'll see the that the 1st three bits of the pointer is the bit adress.
e.g.
you start adress is 128.

Code: Select all

l 128
lar1
l w [ar1, p#0.0]
In this example above, you would load the word 16, and not the assumed 128.
Hence, after calculating your start adress, you must shift 3 bits to left.

Code: Select all

l 128
sld 3
lar1
l w [ar1, p#0.0]
following example would also work, because SLD 3 is same like 2^3 and same like multiply with 8 (2^3=8)

Code: Select all

l 128
l 8
*D
lar1
l w [ar1, p#0.0]
that one would also work:

Code: Select all

l p#128.0
lar1
l w [ar1, p#0.0]
this one is also well :)

Code: Select all

lar1 p#128.0
l w [ar1, p#0.0]
zigouiik
Posts: 8
Joined: Thu Oct 07, 2010 3:52 pm
Location: FRANCE

Re: [?]: Pointer Information

Post by zigouiik »

A pointer is used to address an operand. The advantage of this type of addressing is that you can dynamically change the operand of the instruction during program execution.

Pointer to the memory-indirect addressing:
Program instructions using indirect addressing in memory, are composed of an operation, an address identifier and an offset (which should be indicated in brackets).

Pointer example in double word format:

Code: Select all

L P # 8.7   // load the pointer value in ACCU 1
T MD2      // move the pointer to MD2
U E [MD2]  // query the signal state of input I 8.7
= A [MD2]  // and affect the signal state at output A 8.7
Pointer for addressing intrazone and interzone:
The program instructions using this type of addressing is composed of an operation of the following: address identifier, identifier of the address register, offset.
The address register (AR1 / 2) and the offset shall be indicated in brackets together.

Addressing Example intrazone:
The pointer contains no indication of memory area:

Code: Select all

L P # 8.7              // load the pointer value in ACCU 1
LAR1                   // load pointer ACCU 1 AR1
U E [AR1, P # 0.0] // query the signal state of input I 8.7 and
= A [AR1, P # 1.1] // affect the signal state at output Q 10.0
0.0 The offset has no effect. 10.0 The output is calculated from 8.7 (AR1) plus the offset 1.1. The result is 10.0 and not 9.8.

Addressing Example interzone
Addressing in interzone, the memory area is specified in the pointer (in the example, E or A).

Code: Select all

L P # E8.7 // load the pointer value and the area ID in ACCU 1
LAR1 // load the memory area address E and 8.7 in AR1
L P # A8.7 // load the pointer value and the area ID in ACCU 1
LAR2 // load the memory area A and the address in AR2 8.7
U [AR1, P # 0.0] // query the signal state of input I 8.7 and
= [AR2, P # 1.1] // affect the signal state at output Q 10.0.
0.0 The offset has no effect. 10.0 The output is calculated from 8.7 (AR2) plus 1.1 (lag). The result is 10.0 and not 9.8, see pointer format

Creating the pointer adress:
To create the adress you need to reserve the first 3 bits for the pointer bit adress.
To do so, you slide the value 3 steps to the left (SLD3).
If you slide more than 3 steps you will play on the value itself.

Addressing Example

Code: Select all

L 3              // load the value 3 = 0000 0011 in binary
SLD3            // slide the value 3 steps to the left = 0001 1000 (value=0011, bit adress=000)
LAR1           // load pointer ACCU 1 AR1 = P # 3.0

L 3              // load the value 3 = 0000 0011
SLD4            // slide the value 4 steps to the left = 0011 0000 (value=0110, bit adress=000)
LAR1           // load pointer ACCU 1 AR1 = P # 6.0 : the value has been multiply by 2

L 3              // load the value 3 = 0000 0011
SLD5            // slide the value 4 steps to the left = 0110 0000 (value=1100, bit adress=000)
LAR1           // load pointer ACCU 1 AR1 = P # 12.0 : the value has been multiply by 4
Using a loop and a simple 'value + 1', you can access any WORD or DWORD you want.
nashama
Posts: 50
Joined: Thu Apr 21, 2011 9:37 am

Re: [?]: Pointer Information

Post by nashama »

Thank you zigouiik, LargoD, delege.

Good explanation.

Regards