Why does DataLoc++ work one way but not another
dbpage
Posts: 217
Why does
DataLoc := 0 repeat i from 0 to 10 long[VarData][DataLoc] := DataLoc++Result in
0 0 1 2 3 4 5 6 7 8 9 ...and
DataLoc := 0 repeat i from 0 to 10 long[VarData][DataLoc] := DataLoc DataLoc++Result in
0 1 2 3 4 5 6 7 8 9 10 ...
Comments
Your first snippet behaves how it does because the right hand side of an assignment operator in Spin is evaluated before the left hand side. The DataLoc in "long[VarData][DataLoc]" is already incremented by the time the address to store the value at is calculated.
In other words, "long[x] := y" expects x to be above y on the stack. Therefore, y has to be calculated first. The incrementation of DataLoc happens when the y in my example is evaluated, and it is used again after that when the x in my example is evaluated.
Thanks!