Intermediate Assignments

The Propeller chip's expression engine allows for, and processes, assignment operators at intermediate stages. This is called "intermediate assignments" and it can be used to perform complex calculations in less code. For example, the following equation relies heavily on X, and X + 1.

X := X - 3 * (X + 1) / ||(X + 1)

The same statement could be rewritten, taking advantage of the intermediate assignment property of the increment operator:

X := X++ - 3 * X / ||X

Assuming X started out at -5, both of these statements evaluate to -2, and both store that value in X when done. The second statement, however, does it by relying on an intermediate assignment (the X++ part) in order to simplify the rest of the statement. The Increment operator '+' is evaluated first (highest precedence) and increments X's -5 to -4. Since this is a "post increment" (see Increment, pre- or post- '++'), it first returns X's original value, -5, to the expression and then writes the new value, -4, to X. So, the "X++ - 3…" part of the expression becomes "-5 – 3…" Then the absolute, multiply, and divide operators are evaluated, but the value of X has been changed, so they use the new value, -4, for their operations:

-5 – 3 * -4 / ||-4 → -5 – 3 * -4 / 4 → -5 – 3 * -1 → -5 – -3 = -2

Occasionally, the use of intermediate assignments can compress multiple lines of expressions into a single expression, resulting in slightly smaller code size and slightly faster execution.

The remaining pages of this section further explain each math and logic operator shown in Math and Logic Operators Table in the same order shown.

Unless otherwise noted, content on this site is licensed under the
Creative Commons Attribution-ShareAlike 4.0 International License.