4.3.14. IT

The IT (If-Then) instruction makes up to four following instructions (the IT block) conditional. The conditions can be all the same, or some of them can be the logical inverse of the others.

Note

This is a 16-bit Thumb-2 instruction.

Syntax

IT{x{y{z}}} {cond}

where:

x

is the condition for the second instruction in the IT block.

y

is the condition for the third instruction in the IT block.

z

is the condition for the fourth instruction in the IT block.

cond

is the condition for the first instruction in the IT block.

Conditions for the second, third and fourth instruction in the IT block can be either:

T

Then. The condition applied to the instruction is cond.

E

Else. The condition applied to the instruction is the inverse of cond.

Usage

16-bit instructions in the IT block, other than CMP, CMN and TST, do not affect the condition code flags. You can use IT with the AL condition if you want this effect, without the instructions in the IT block being conditional.

Restrictions

The following instructions are not permitted in an IT block:

  • IT

  • Conditional branches

  • CBZ and CBNZ

  • TBB and TBH

  • CPS, CPSID and CPSIE

  • SETEND.

In addition, an unconditional branch is only allowed in an IT block if it is the last instruction in the block.

Condition flags

This instruction does not change the flags.

Exceptions

Exceptions can occur between an IT instruction and the corresponding IT block, or within an IT block. This exception results in entry to the appropriate exception handler, with suitable return information in r14 and SPSR.

Instructions designed for use for exception returns can be used as normal to return from the exception, and execution of the IT block resumes correctly. This is the only way that a pc-modifying instruction can branch to an instruction in an IT block.

Architectures

This 16-bit Thumb-2 instruction is available in T2 variants of ARMv6 and above.

Example

Branches in IT blocks must be encoded as unconditional branches (the IT condition makes them conditional). Therefore, it is sometimes beneficial to place a conditional branch into an IT block as this increases its effective range:

    ITTE   NE        ; assemblers can allow IT to be omitted
    ANDNE  r0,r0,r1  ; 16-bit AND, not ANDS
    ADDSNE r2,r2,#1  ; 32-bit ADDS (16-bit ADDS does not set flags in IT block)
    MOVEQ  r2,r3     ; 16-bit MOV(CPY)
    ITT    AL        ; emit 2 non-flag setting 16-bit instructions
    ADDAL  r0,r0,r1  ; 16-bit ADD, not ADDS
    SUBAL  r2,r2,#1  ; 16-bit SUB, not SUB
    ADD    r0,r0,r1  ; expands into 32-bit ADD
    IT     NE
    ADD    r0,r0,r1  ; syntax error: no condition code used in IT block

Notes

Branches into an IT block

Except as noted under Exceptions, no instruction in an IT block can be the target of any branch, either from a branch instruction or from any other instruction that changes the PC. The result of such a branch is unpredictable, that is, it cannot be relied upon.

Branches out of an IT block

Instructions that modify the PC must not be used in an IT block, except as the last instruction in the block. The result of any such instruction is unpredictable, that is, it cannot be relied upon.

Unpredictable instructions in an IT block

The assembler warns about unpredictable instructions in an IT block, for example, B, BL, and CPS. This means that the results cannot be relied upon. It also warns about instructions that change the PC, for example, BX, CZB, and RFE.

The assembler does not take account of directives inside IT blocks. Therefore, the following example results in an incorrect warning:

    ITT     EQ
    DCI     0
    B       dloop
BKPT

A BKPT instruction in an IT block is always executed, even if its condition fails.

Copyright © 2002-2005 ARM Limited. All rights reserved.ARM DUI 0204F
Non-Confidential