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 the Conditions table below) 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.

Conditions

Condition

Instruction Executes

Value

Synonyms

IF_ALWAYS

always

1111

 

IF_NEVER

never

0000

 

IF_E

if equal (Z = 1)

1010

IF_Z

IF_NE

if not equal (Z = 0)

0101

IF_NZ

IF_A

if above (!C & !Z = 1)

0001

IF_NC_AND_NZ –and– IF_NZ_AND_NC

IF_B

if below (C = 1)

1100

IF_C

IF_AE

if above or equal (C = 0)

0011

IF_NC

IF_BE

if below or equal (C | Z = 1)

1110

IF_C_OR_Z –and– IF_Z_OR_C

IF_C

if C set

1100

IF_B

IF_NC

if C clear

0011

IF_AE

IF_Z

if Z set

1010

IF_E

IF_NZ

if Z clear

0101

IF_NE

IF_C_EQ_Z

if C equal to Z

1001

IF_Z_EQ_C

IF_C_NE_Z

if C not equal to Z

0110

IF_Z_NE_C

IF_C_AND_Z

if C set and Z set

1000

IF_Z_AND_C

IF_C_AND_NZ

if C set and Z clear

0100

IF_NZ_AND_C

IF_NC_AND_Z

if C clear and Z set

0010

IF_Z_AND_NC

IF_NC_AND_NZ

if C clear and Z clear

0001

IF_A –and– IF_NZ_AND_NC

IF_C_OR_Z

if C set or Z set

1110

IF_BE –and– IF_Z_OR_C

IF_C_OR_NZ

if C set or Z clear

1101

IF_NZ_OR_C

IF_NC_OR_Z

if C clear or Z set

1011

IF_Z_OR_NC

IF_NC_OR_NZ

if C clear or Z clear

0111

IF_NZ_OR_NC

IF_Z_EQ_C

if Z equal to C

1001

IF_C_EQ_Z

IF_Z_NE_C

if Z not equal to C

0110

IF_C_NE_Z

IF_Z_AND_C

if Z set and C set

1000

IF_C_AND_Z

IF_Z_AND_NC

if Z set and C clear

0010

IF_NC_AND_Z

IF_NZ_AND_C

if Z clear and C set

0100

IF_C_AND_NZ

IF_NZ_AND_NC

if Z clear and C clear

0001

IF_A –and– IF_NC_AND_NZ

IF_Z_OR_C

if Z set or C set

1110

IF_BE –and– IF_C_OR_Z

IF_Z_OR_NC

if Z set or C clear

1011

IF_NC_OR_Z

IF_NZ_OR_C

if Z clear or C set

1101

IF_C_OR_NZ

IF_NZ_OR_NC

if Z clear or C clear

0111

IF_NC_OR_NZ

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