2/28/2011 4:04 PM | |
Posts: 316 Rating: (37) |
Hi Danish, you can use this FC: Find Pattern. Or you make your own FC which compare a datablock(loop and anypointers). |
3/1/2011 6:14 PM | |
Joined: 1/28/2009 Last visit: 10/26/2024 Posts: 6852 Rating: (1365) |
Dear Jacek d you are right about the loop syntax like the exerpt from STEP7 online manual: [QUOTE] L L#1 //Load the integer constant (32 bit) into ACCU 1. T MD20 //Transfer the contents from ACCU 1 into MD20 (initialization). L 5 //Load number of loop cycles into ACCU 1-L. NEXT: T MW10 //Jump label = loop start / transfer ACCU 1-L to loop counter. L MD20 * D //Multiply current contents of MD20 by the current contents of MB10. T MD20 //Transfer the multiplication result to MD20. L MW10 //Load contents of loop counter into ACCU 1. LOOP NEXT //Decrement the contents of ACCU 1 and jump to the NEXT jump label if ACCU 1-L > 0 [/QUOTE] About deleting mentioned codes (opening DBs),Check the attached video which test the following codes with and without deleting those codes. [code] OPN DB 1 LAR1 P#DBX 0.0 OPN DB 2 LAR2 P#DBX 0.0 L 64 TST: T MW 10 OPN DB 1 L B [AR1,P#0.0] OPN DB 2 L B [AR1,P#0.0] <>I S Q 5.0 +AR1 P#1.0 +AR2 P#1.0 L MW 10 LOOP TST[/code] BR Attachmentruntime_test.zip (539 Downloads) |
Last edited by: hdhosseini at: 3/1/2011 6:23 PM |
|
3/2/2011 8:11 AM | |
Joined: 10/7/2005 Last visit: 11/19/2024 Posts: 3027 Rating: (1057)
|
Dear all allow me say thatyou are both correct and it seems that there is a bit of a misunderstanding. It is of course imperative to ensure that the correct DB is open before you do any indirect addressing of its elements (sohdhosseiniis correct concerning this as he also proved in his video, quite a nice effortI must say). jacek dis however also correct as it is NOT required to open the correct DB's at the point of "presetting" the address registers(before the"LAR1 P#DBX 0.0" and "LAR2 P#DBX 0.0" commands).
As we are talking about not needed commands, allowme too to proposea runtime optimisation of the logicbased on the following changes: - Usage of both DB registers and no need to open each DB in each loop(Note: preferably done in an FC, be mindful when doing so in an FB as the DB2 register is used for the IDB). - Usage of only AR1 (the "P#x.y" offset will be used if the start addresses differ) Note: I kept the BYTE wise comparison, aWORD or DWORD based comparisonwould of course be even better (less loops to do): [code]LAR1 P#0.0// Load start address into AR1 OPNDB 1// open first DB via DB register 1 OPN DI 2// open second DB via DB register 2 L 64 LOOP: T #_Loop_counter // Loop counter (TEMP variable type INT) L DBB [AR1,P#0.0] // use "P#x.y" offset if DB1's start address is higher than DB2's L DIB [AR1,P#0.0] // use "P#x.y" offset if DB2's start address is higher than DB1's <>I JC CONT// leave loop if difference encountered (or do other handling here) +AR1 P#1.0// bump AR1 by 1 Byte L #_Loop_counter LOOP LOOP JU END CONT: NOP 0// do whatever needs to be done here if difference encountered END: NOP 0 [/code] I hope this helps |
Cheers |
|
1/21/2016 11:08 AM | |
Joined: 9/3/2014 Last visit: 3/13/2019 Posts: 4766 Rating: (122) |
New question published by Ikkez is split to a separate thread with the subject Compare DB with 260 variables. Best regards |
This contribution was helpful to1 thankful Users |
Follow us on