122-32000 Parallax Inc, 122-32000 Datasheet - Page 253

MANUAL PROPELLER

122-32000

Manufacturer Part Number
122-32000
Description
MANUAL PROPELLER
Manufacturer
Parallax Inc
Datasheets

Specifications of 122-32000

Accessory Type
Manual
Lead Free Status / RoHS Status
Lead free / RoHS Compliant
For Use With/related Products
Propeller Education (PE) Kit
Lead Free Status / Rohs Status
Lead free / RoHS Compliant
4: Spin Language Reference – Operators
For example:
X = (20 + 8) * 4 – 6 / 2
This will evaluate the expression in parentheses first, the 20 + 8, causing the expression to
now result in 109, instead of 49.
Table 4-10 indicates each operator’s level of precedence from highest (level 0) to lowest
(level 12). Operators with a higher precedence are performed before operators of a lower
precedence; multiply before add, absolute before multiply, etc. The only exception is if
parentheses are included; they override every precedence level.
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
started out at -5, both of these statements evaluate to -2, and both store that value
X
in
when done. The second statement, however, does it by relying on an intermediate
X
assignment (the
part) in order to simplify the rest of the statement. The Increment
X++
operator ‘
’ is evaluated first (highest precedence) and increments X’s -5 to -4. Since this is
++
a “post increment” (see Increment, pre- or post- ‘+ +’, page 257) it first returns
’s original
X
value, -5, to the expression and then writes the new value, -4, to
. So, the “
…” part
X
X++ - 3
of the expression becomes “-5 – 3…” Then the absolute, multiply, and divide operators are
evaluated, but the value of
has been changed, so they use the new value, -4, for their
X
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 slighter faster execution.
The remaining pages of this section further explain each math and logic operator shown in
Table 4-9 in the same order shown.
Propeller Manual v1.0 · Page 253

Related parts for 122-32000