Propeller Manual

Table Of Contents
3: Assembly Language Reference – IF_x (Conditions)
IF_x (Conditions)
Every Propeller Assembly instruction has an optional “condition” field that is used to
dynamically determine whether or not it executes when it is reached at run time. The basic
syntax for Propeller Assembly instructions is:
Label Condition Instruction Operands Effects
The optional Condition field can contain one of 32 conditions (see Table 3-3) and defaults to
IF_ALWAYS when no condition is specified. The 4-bit Value shown for each condition is the
value used for the
–CON– field in the instruction’s opcode.
This feature, along with proper use of instructions’ optional Effects field, makes Propeller
Assembly very powerful. Flags can be affected at will and later instructions can be
conditionally executed based on the results. Here’s an example:
test _pins, #$20 wc
and _pins, #$38
shl t1, _pins
shr _pins, #3
movd vcfg, _pins
if_nc mov dira, t1
if_nc mov dirb, #0
if_c mov dira, #0
if_c mov dirb, t1
The first instruction, test _pins, #$20 wc, performs its operation and adjusts the state of
the C flag because the
WC effect was specified. The next four instructions perform operations
that could affect the C flag, but they do not affect it because no
WC effect was specified. This
means that the state of the C flag is preserved since it was last modified by the first
instruction. The last four instructions are conditionally executed based on the state of the C
flag that was set five instructions prior. Among the last four instructions, the first two
mov
instructions have
if_nc conditions, causing them to execute only “if not C” (if C = 0). The
last two
mov instructions have if_c conditions, causing them to execute only “if C” (if C = 1).
In this case, the two pairs of
mov instructions are executed in a mutually exclusive fashion.
When an instruction’s condition evaluates to
FALSE, the instruction dynamically becomes a
NOP, elapsing 4 clock cycles but affecting no flags or registers. This makes the timing of
multi-decision code very deterministic.
Propeller Manual v1.1 · Page 295