S7: Pointer offset as variabel

L D [AR2,P#0.0], did you use LAR2 P#DIX 0.0 just to set the upper area bits? Isn't there way around having to do this by forcing the L D [AR2,#P0.0] instruction to use the DI register by saying L DIW [AR2,#P0.0]? Or must the area bits always be set?


I think you'll find he's pointing to the first word in the Instance DB prior to adding the pointer as below

Code:
[FONT=monospace]
  L     #i_Offset_write; 
  SLD   4; 
  +AR2  ;[/FONT]



this is the best way to do this.
 
Yes, but why not simply
Code:
  L     #i_Offset_write; 
  SLD   4; 
  LAR2 ;
unless the upper area bits must be set to point to the DI area?

The question is must the area bits always be set or can one override the area bits in the AR registers by specifying the what DI or DB register to use in the instruction such as L DBW [AR2,P#0.0].

I have not been able to find any documentation on what takes precedence. The instruction or the area bits in the address register.

BTW, I would have saved the DI and AR2 away and restored them at the end. This way the FC can be called from a FB and not mess up the DI and AR2 register.
 
Peter, no need to save AR2 when using it inside FC, it is saved automatically by compiler when you call the FC (again LD or s7guy has shown that in some post).

It should work also:

L plaa
LAR2

L DIW[plaa]

Have not tested it with DI but with DB it works, so i see no reason why would it not work with DI too.

I think its about how one likes to do it.
 

Similar Topics

Hello Folks! I have an application where I need to copy a string into various locations within a DB. So, I've set up a Function Block to accept...
Replies
3
Views
4,985
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
554
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,631
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,389
Hi All, in many library function of TiaPortal some data must be write using the pointer format........ eg.: P#DB90.DBX0.0 WORD 10 is it...
Replies
5
Views
2,823
Back
Top Bottom