Hi guys. I'm trying to do something that's probably really easy when you know how, but I don't.
I have a datablock that has 60 data words in it, all in INT format.
I simply want to add together the values of the first 16 datawords.
I'm using an S7-313C 2DP.
Any tips please? Thanks.
How To Add Multiple Datawords Together
-
- Posts: 18
- Joined: Mon Nov 17, 2008 5:08 pm
- Location: America
-
- Posts: 1
- Joined: Thu Sep 02, 2010 9:48 pm
Re: How To Add Multiple Datawords Together
U can use pointer and loop.
Code: Select all
...
L 0
T counter //init of counter variable (better not a temp variable) - INT
T Totale //init of total value variable (better not a temp variable) - DINT
Loop: nop 0
L counter //preparation of pointer by the counter
L 2
*I
SLW 3
LAR1
AUF DB xxx //open your datablock
L DBW[AR1,P#0.0] //load the value through the pointer
ITD //convert to double int
L Total //and add to your total variable
+D
T Total
L counter //increment the counter
+ 1
T counter
L 16 //stop the loop after 16 times
<I
Spb Loop
...