| |||
| Home > ARM and Thumb Instructions > Branch and control instructions > 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.
IT{x{y{z}}} {cond}
where:
xspecifies the condition switch for the second instruction in the IT block.
yspecifies the condition switch for the third instruction in the IT block.
zspecifies the condition switch for the fourth instruction in the IT block.
condspecifies the condition for the first instruction in the IT block.
The condition switch for the second, third and fourth instruction in the IT block can be either:
TThen. Applies the condition to
the instruction.cond
EElse.
Applies the inverse condition of to
the instruction.cond
The instructions (including branches) in the IT block, except
the BKPT instruction, must specify the condition in
the { part of
their syntax.cond}
You do not need to write IT instructions in your
code, because the assembler generates them for you automatically
according to the conditions specified on the following instructions.
However, if you do write IT instructions, the assembler
validates the conditions specified in the IT instructions
against the conditions specified in the following instructions.
Writing the IT instructions ensures that you
consider the placing of conditional instructions, and the choice
of conditions, in the design of your code.
When assembling to ARM code, the assembler performs the same
checks, but does not generate any IT instructions.
With the exception of CMP, CMN, and TST,
the 16-bit instructions that normally affect the condition code
flags, do not affect them when used inside an IT block.
A BKPT instruction in an IT block is always executed,
so it does not need a condition in the {} part
of its syntax. The IT block continues from the next instruction.cond
You can use an IT block for unconditional instructions
by using the AL condition.
Conditional branches inside an IT block have a longer branch range than those outside the IT block.
The following instructions are not permitted in an IT block:
IT
CBZ and CBNZ
TBB and TBH
CPS, CPSID and CPSIE
SETEND.
Other restrictions when using an IT block are:
A branch or any instruction that modifies the PC is only permitted in an IT block if it is the last instruction in the block.
You cannot branch to any instruction in an IT block, unless when returning from an exception handler.
You cannot use any assembler directives in an IT block.
The assembler shows a diagnostic message when any of these
instructions are used in an IT block.
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 LR and SPSR.
Instructions designed for use as 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.
This 16-bit Thumb instruction is available in ARMv6T2 and above.
In ARM code, IT is a pseudo-instruction that
does not generate any code.
There is no 32-bit version of this instruction.
ITTE NE ; IT can 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
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, and is not in IT block
ITT EQ
MOVEQ r0,r1
BEQ dloop ; branch at end of IT block is permitted
ITT EQ
MOVEQ r0,r1
BKPT #1 ; BKPT always executes
ADDEQ r0,r0,#1