S7 Pointer Questions

arocon

Member
Join Date
Oct 2006
Location
Dubai
Posts
171
I am trying to understand pointer in S7 and come across the following code :

//Assume an integer symbol named index exists that contain the index into the table.

L index //load a variable index into the table
SLD 3 // shift left 3 bits to crate an index pointer
L P#20.0 // Load the pointer to the start of the table
+D // Add index pointer to start of table pointer
T MD100 // store the indexd pointer in MD100
L MB[MD100] // read the table element into the accumulator

My question is how shift left 3 bits create an index pointer.

If anybody please explain it will be great help.

Thanks
 
My question is how shift left 3 bits create an index pointer.

If anybody please explain it will be great help.

Thanks

If you open the Step7 help file, and search for 'pointer' or 'any' you'll find the description of the format of the types.

In your case, it is a byte access, but the format of the address is still byte.bit.
Since S7 has got 8 bits per byte, and your input is a byte address, you need to multiply with 8 (SLD 3) to get the right format.

Perhaps it is easier to understand if you think that the contents of the indirect address pointer is a bit-address.
If you want to read byte 10, the start address is the 80th bit.

:unsure:I can see this is a messy description but there are instructors out there/in here that can explain it much better, just wait and see.
icon12.gif


Kalle

Edit: Another try:

- The pointer format is a bit address (= a bit number)
- The command that use the pointer decides if it is used as a bit or byte/(d)word access.
 
Last edited:
To clarify what Kalle was saying above.

A pointer takes up 2 words (4 bytes) of memory as follows:

T = Data Type U = Unused Y = Byte Address I = Bit Address


TTTTTTTT UUUYYYYY
YYYYYYYY YYYYYIII

III gives you binary 0 to 7 so if you want your pointer to start at byte 10 then you would load 10 and SLD3, which would point to 10.0.

You SLD3 and not SLW3 in case your number is big enough to move bits from the second word to the first
 
OK.

I think the array must be BYTE or CHAR (not INT).
Because the code shifts 3bits.

L index //load a variable index into the table
This is simply loading index into Accumulator 1 (ACCU1)

SLD 3 // shift left 3 bits to crate an index pointer
Step 7 represents address offset by bit.
Size of BYTE is 8bits.
So, Offset address[bit] = index * 8[bits]
SLD 3 has same meanings to multiplying 8 in this case.

L P#20.0 // Load the pointer to the start of the table
This instruction loads P#20.0 ( = 160bits )to ACCU1.
Before loading, contents in ACCU1 is moved to ACCU2.

+D // Add index pointer to start of table pointer
ACCU1 = ACCU1(= P#20.0) + ACCU2( index * 8 )

T MD100 // store the indexd pointer in MD100
Store contents of ACCU1 into MD100.

L MB[MD100] // read the table element into the accumulator
Load to accu1.
Memory : M
Access width : BYTE
Address : Content of MD100

Best regards.
 
Last edited:
I found what you may be reading.

Good evening, arocon.

I found a document you may be reading at
http://www.scribd.com/doc/47367113/Sitrain-S7-Pointers

And you are probably reading the section "Working With Memory Indirect Addressing - Indexing".

In the sample, BYTE array is defined from MB20 to MB200 (181 elements.) Sorry, I cannot explain easier than above unless your additional question.
 
OK.

I think the array must be BYTE or CHAR (not INT).
Because the code shifts 3bits.

Its bytes because of this line
L MB[MD100]

MB = Marker Byte.

The shifting 3 bits is to make the index number a pointer.

INDEX = the Pointer offset

P#20.0 = start address of the data in the flag area (MB20). The range is unknown to us but probably the INDEX is limited to a valid range before the call.

As mentioned above, the pointer format includes the bit component, so it shifts left to point to the correct BYTE.

It cannot be more than 80 bytes as the pointer uses MD100.

MD100 = 20+INDEX

Therefore the line

L MB[MD100]

is equivalent to

L MB[20+INDEX].

If INDEX = 6 then MB26 will be read.
 

Similar Topics

Could anyone please explain me what are the different cases Pointer to be used in Simatic S7 programming ? Thanks
Replies
7
Views
3,867
Hi Guys, Hopefully attached is the code i could with some advice on. I believe this code controls the mapping of Internal memory to the...
Replies
8
Views
2,571
I have a word in some DB which I want to load to AR1 and use as a pointer. In order to do this I need to write L DBxy.DBW xy SLD 3 LAR1 I...
Replies
3
Views
531
I am trying to access the value of a pointer via OPC UA in Codesys. I can share it directly and in a struct but I cant access the value of it when...
Replies
5
Views
1,600
Why does my deconstruction of the input pointer only work with its own instance DB not inside the multi instance FB...See .doc The pointer at the...
Replies
8
Views
2,334
Back
Top Bottom