Forgive my English and a little bad, how do I within a fc access a temporary array?
language: stl
statement: array data [1..100] of int
as I am trying to access
#data [#address]
Indexed access the temporary array within a fc
-
- Posts: 11
- Joined: Sat Sep 25, 2010 12:17 pm
-
- Posts: 199
- Joined: Wed Dec 24, 2008 4:37 pm
- Location: Europe
Re: Indexed access the temporary array within a fc
Hello ,
see the sample below:
see the sample below:
Code: Select all
L P##Array_Data // Start adress of 6 byte long pointer in memory
LAR1
L W [AR1,P#0.0] // load value of first Word in Array
L W [AR1,P#2.0] // load value of second Word in Array
L W [AR1,P#4.0] // load value of third Word in Array
etc.
-
- Posts: 2
- Joined: Wed Dec 19, 2012 1:55 pm
Re: Indexed access the temporary array within a fc
One idea, but not tested:
In the standard library, there are very promissing blocks:
FC91 WRD_TBL
FC89 TBL_WRD
Other approach:
L #Index
SLD 4 //because the address is bit-oriented, so for 16-bit it is shift by 4 (*16), for 8bit it is shift by 3 (*8), DINT is shift by 5 (*32)
L P##Array_Data // Start adress of 6 byte long pointer in memory
+D //Do the pointer arithmetics
LAR1 //Load the AR1 adress-register
L W [AR1,P#0.0] // load value of Array_Data[Index]. Note it is 16-bit INT. // For DINT it is L D [AR1,P#0.0]
In the standard library, there are very promissing blocks:
FC91 WRD_TBL
FC89 TBL_WRD
Other approach:
L #Index
SLD 4 //because the address is bit-oriented, so for 16-bit it is shift by 4 (*16), for 8bit it is shift by 3 (*8), DINT is shift by 5 (*32)
L P##Array_Data // Start adress of 6 byte long pointer in memory
+D //Do the pointer arithmetics
LAR1 //Load the AR1 adress-register
L W [AR1,P#0.0] // load value of Array_Data[Index]. Note it is 16-bit INT. // For DINT it is L D [AR1,P#0.0]