| |||
| Home > The Cortex-M3 Instruction Set > Branch and control instructions > IT | |||
If-Then condition instruction.
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
It is possible to use AL (the always condition)
for in an condIT instruction.
If this is done, all of the instructions in the IT block must be
unconditional, and each of x, y,
and z must be T or omitted
but not E.
The IT instruction makes up to four following
instructions conditional. The conditions can be all the same, or
some of them can be the logical inverse of the others. The conditional instructions
following the IT instruction form the IT
block.
The instructions in the IT block, including any branches,
must specify the condition in the { part
of their syntax.cond}
Your assembler might be able to generate the required IT instructions
for conditional instructions automatically, so that you do not need
to write them yourself. See your assembler documentation for details.
A BKPT instruction in an IT block is always executed,
even if its condition fails.
Exceptions can be taken between an IT instruction
and the corresponding IT block, or within an IT block. Such an exception
results in entry to the appropriate exception handler, with suitable return
information in LR and stacked PSR.
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 is permitted to branch to an instruction in an IT block.
The following instructions are not permitted in an IT block:
IT
CBZ and CBNZ
CPSID and CPSIE
MOVS.N Rd,Rm.
Other restrictions when using an IT block are:
a branch or any instruction that modifies the PC must either be outside an IT block or must be the last instruction inside the IT block. These are:
ADD PC, PC, Rm
MOV PC, Rm
B, BL, BX, BLX
any LDM, LDR, or POP instruction
that writes to the PC
TBB and TBH
do not branch to any instruction inside an IT block, except when returning from an exception handler
all conditional instructions except B must
be inside an IT block. condB can
be either outside or inside an IT block but has a larger branch
range if it is inside onecond
each instruction inside the IT block must specify a condition code suffix that is either the same or logical inverse as for the other instructions in the block.
Your assembler might place extra restrictions on the use of IT blocks, such as prohibiting the use of assembler directives within them.
ITTE NE ; Next 3 instructions are conditional
ANDNE R0, R0, R1 ; ANDNE does not update condition flags
ADDSNE R2, R2, #1 ; ADDSNE updates condition flags
MOVEQ R2, R3 ; Conditional move
CMP R0, #9 ; Convert R0 hex value (0 to 15) into ASCII
; ('0'-'9', 'A'-'F')
ITE GT ; Next 2 instructions are conditional
ADDGT R1, R0, #55 ; Convert 0xA -> 'A'
ADDLE R1, R0, #48 ; Convert 0x0 -> '0'
IT GT ; IT block with only one conditional instruction
ADDGT R1, R1, #1 ; Increment R1 conditionally ITTEE EQ ; Next 4 instructions are conditional MOVEQ R0, R1 ; Conditional move ADDEQ R2, R2, #10 ; Conditional add ANDNE R3, R3, #1 ; Conditional AND BNE.W dloop ; Branch instruction can only be used in the last ; instruction of an IT block IT NE ; Next instruction is conditional ADD R0, R0, R1 ; Syntax error: no condition code used in IT block.