hiiiiiiiiiii all,
first i thank everyone helps me or tried to do.i have a problem in writing STL code using pointers in simatic s7 to sort array of datablock in descending order
i actually write code to do the following
1-FB has 3 inputs .one for the DB to be sorted(pointer format),second one for the destination DB(sorted)(also pointer format,the last i/p for length.
2-in my code i scan all the DB to get the maximum value element and then put it in the begging of the dest. array.then i put zero value in the place of the maximum in source DB.and i scan again the DB to get the maximum and put it in dest. array in next position and go in loops till finish.
3-i tried that on simulator and it gives no error but the output is all the dest. array is a copy of the maximum value
4-i want to know where is the mistake in my code or if there are any other criteria (logic) to do so.
5-here is my code
L #DB_LEN //LENGTH OF DATA BLOCK
T #TMP_LEN1 //COUNTER FOR SCANING DB
T #TMP_LEN2 //COUNTER FOR SCANING DB
L P##SRC_DB //un sorted DB
LAR1
L W [AR1,P#0.0]
T #SDB_NR
OPN DB [#SDB_NR]
L D [AR1,P#2.0]
LAR1
L W [AR1,P#0.0]
T #TMP_MAX
L P##ORD_DB // DB to put the sorted data
LAR2
L W [AR2,P#0.0]
T #DDB_NR
L D [AR2,P#2.0]
LAR2
LOOP: L #TMP_MAX
+AR1 P#2.0
L W [AR1,P#0.0]
<I
JCN RR
T #TMP_MAX
L #TMP_LEN1
L -1
+I
T #TMP_LEN1
L 0
==I
JC XX
JC LOOP
RR: TAK
T #TMP_MAX
L #TMP_LEN1
L -1
+I
T #TMP_LEN1
L 0
==I
JC XX
JC LOOP
XX: L #TMP_MAX
OPN DB [#DDB_NR]
T W [AR2,P#0.0]
TAR2
LAR1
+AR2 P#2.0
L 0
T #TMP_MAX
L #TMP_LEN2
L -1
+I
T #TMP_LEN2
T #TMP_LEN1
L 0
==I
JCN LOOP
SET
SAVE
first i thank everyone helps me or tried to do.i have a problem in writing STL code using pointers in simatic s7 to sort array of datablock in descending order
i actually write code to do the following
1-FB has 3 inputs .one for the DB to be sorted(pointer format),second one for the destination DB(sorted)(also pointer format,the last i/p for length.
2-in my code i scan all the DB to get the maximum value element and then put it in the begging of the dest. array.then i put zero value in the place of the maximum in source DB.and i scan again the DB to get the maximum and put it in dest. array in next position and go in loops till finish.
3-i tried that on simulator and it gives no error but the output is all the dest. array is a copy of the maximum value
4-i want to know where is the mistake in my code or if there are any other criteria (logic) to do so.
5-here is my code
L #DB_LEN //LENGTH OF DATA BLOCK
T #TMP_LEN1 //COUNTER FOR SCANING DB
T #TMP_LEN2 //COUNTER FOR SCANING DB
L P##SRC_DB //un sorted DB
LAR1
L W [AR1,P#0.0]
T #SDB_NR
OPN DB [#SDB_NR]
L D [AR1,P#2.0]
Code:
L W [AR1,P#0.0]
T #TMP_MAX
L P##ORD_DB // DB to put the sorted data
LAR2
L W [AR2,P#0.0]
T #DDB_NR
L D [AR2,P#2.0]
LAR2
LOOP: L #TMP_MAX
+AR1 P#2.0
L W [AR1,P#0.0]
<I
JCN RR
T #TMP_MAX
L #TMP_LEN1
L -1
+I
T #TMP_LEN1
L 0
==I
JC XX
JC LOOP
RR: TAK
T #TMP_MAX
L #TMP_LEN1
L -1
+I
T #TMP_LEN1
L 0
==I
JC XX
JC LOOP
XX: L #TMP_MAX
OPN DB [#DDB_NR]
T W [AR2,P#0.0]
TAR2
LAR1
+AR2 P#2.0
L 0
T #TMP_MAX
L #TMP_LEN2
L -1
+I
T #TMP_LEN2
T #TMP_LEN1
L 0
==I
JCN LOOP
SET
SAVE