itte 臂组件
下面的行在arm汇编中做了什么:
000031e6 2916 cmp r1, #22
000031e8 bf1a itte ne
我得到第一行(比较r1到22)但是第二行呢(我以前从未见过itte命令,谷歌搜索什么也没有返回)
What does the following line do in arm assembly:
000031e6 2916 cmp r1, #22
000031e8 bf1a itte ne
I get the first line (comparing r1 to 22) but what about the second line (I've never seen the itte command before and googling returned nothing)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
它是ARM的IF-THEN-ELSE指令,在Thumb-2指令集中引入。 (根据上面的具体示例,如果您显示了
ITTE
指令后面的接下来 3 条指令,将会很有帮助,当您读完这个答案后,您就会明白为什么。)指令用于处理小序列的条件代码,最多 4 条指令。将其视为实现 ARM 条件执行的不同方式(例如 BNE - 仅在未设置零标志时才执行分支指令)。
它的好处是它避免了采用分支的惩罚(假设您已经了解了管道等)。
该指令有点复杂,但是一旦您了解它,它就非常优雅。
它采用以下形式:
IT
,其中
x
、y
和>z
是可选的,并且必须是T
(表示“then”)或E
(表示“else”)。
是反映的任何条件,例如NE
或EQ
或GT
等在 APSR 标志中。因此,
I
后面总是有一个T
(毕竟指令是IT
!),然后是 0-3E< /code> 或
T
。对于每个T
和每个E
,您必须有一个按相同顺序匹配的后续指令。每个匹配的后续指令必须具有与IT
指令匹配的条件。请耐心听我说,我知道这很令人困惑。我将在这里举几个例子来说明。
该指令的最小形式类似于:
在这种情况下,如果 LT 为 true(根据 APSR 标志),则将进行减法。请注意,
SUB
中的LT
与IT
指令中的LT
相匹配。一个完整的例子是这样的:
所以我们有 THEN ELSE THEN THEN (
TETT
),带有NE
条件。请注意,在后面的 4 个条件指令中(4 个指令,TETT
各 1 个),“THEN”指令具有NE
条件,而“ELSE”指令(IT
指令之后的第二条指令 - 请记住 E 是 4 个 E 和 T 中的第二条)具有相反的条件。它不能是其他任何东西,也就是说,如果它是类似LT
而不是EQ
的东西,那将是一个错误。EQ
与NE
相反。因此,如果 NE 为 true,则指令 1、3 和 4 将被执行。否则 (
EQ
),仅执行指令 2 (ADDEQ
)。我给出了 1 条和 4 条指令的示例,但您也可以有 2 条
(IT{T,E}
) 和 3 条指令 (IT{T,E}{T,E}
) 形式也是如此。最后,为了让大家明白这一点,我将给出一个示例,说明如何使用此指令实现以下 C 代码:
转换为
这应该足以让您咀嚼一段时间。
It is the ARM's IF-THEN-ELSE instruction, which was introduced in the Thumb-2 instruction set. (Based on your specific example above, it would have been helpful if you had shown the next 3 instructions that followed the
ITTE
instruction, you'll understand why when you're done reading this answer.)This instruction is used for handling small sequences of conditional code, up to 4 instructions. Think of it as a different way of implementing the ARM's conditional execution (e.g. BNE - the branch instruction is only executed if the zero flag is not set).
The benefit of it is that it avoids the penalty of taking a branch (presumably you've learned about pipelines etc.)
The instruction is a bit involved but once you wrap your head around it, it's pretty elegant.
It takes the form:
IT<x><y><z><cond>
where
x
,y
, andz
are optional, and must be eitherT
(for "then") orE
(for "else").<cond>
is any of the conditions such asNE
orEQ
orGT
, etc. that are reflected in the APSR flags.So you always have one
T
following theI
(the instruction isIT
after all!), and then 0-3E
's orT
's. For eachT
and eachE
, you must have a subsequent instruction in the same order that matches up. Each matching subsequent instruction must have conditions that match up with theIT
instruction.Bear with me, I know this is confusing. I'll give a couple examples here to illustrate.
The minimal form of the instruction would be something like:
In this case, if
LT
is true (per the APSR flags), the subtraction will take place. Notice theLT
in theSUB
matches theLT
in theIT
instruction.A full-blown example would be something like:
So we have THEN ELSE THEN THEN (
TETT
), withNE
condition. Notice in the 4 conditional instructions that follow (4 instructions, 1 each forTETT
), the "THEN" instructions have theNE
condition, and the "ELSE" instruction (the 2nd instruction after theIT
instruction - remember the E was the 2nd of 4 E's and T's) has the opposite condition. It cannot be anything else, i.e. it would be an error if it was something likeLT
instead ofEQ
.EQ
is the opposite ofNE
.So if
NE
is true, then instructions 1, 3 and 4 would be executed. Otherwise (EQ
), only instruction 2 (ADDEQ
) would be executed.I've given examples of 1 and 4 instructions, but you can also have 2
(IT{T,E}
)and 3 instruction (IT{T,E}{T,E}
) forms as well.Finally, to bring home the point, I'll give an example of how the following C code can be implemented using this instruction:
converts to
That should give you enough to chew on for a while.
简单来说,
ITTE
根据上面的cmp
指令执行以下 3 个执行:IF THEN {} THEN {} ELSE {}。在ARMv6T2及更高版本的架构中,您可以使用
IT
指令进行条件执行。在 ARMv6T2 之前的体系结构中,没有IT
指令,因此除B
分支指令外,Thumb 指令无法有条件执行。汇编器检查 IT 指令,但在汇编为 ARM 代码。对于您的解决方案,让我们首先了解 ARM 汇编的简单
IT
指令(在 Thumb 2 中引入)的语法,它是ITTE
的基础。IT{pattern} {cond}
If-then,设置最多 4 条后续指令的执行条件
最多可以是三个 T(then) 和 E(else) 字母的任意组合,IT 后面的第一条指令始终是 cond (T) 可以修改程序计数器的指令必须位于 IT 块的最后
< code>then 条件必须与条件代码匹配,任何
else
条件必须是相反条件。下表显示了条件代码及其相反条件:让我们了解另一个
cmp
操作说明。CMP Rn, #imm
Rn 必须是 Lo 寄存器。 imm 范围 0-255。
这些指令根据结果更新 N、Z、C 和 V 标志。
请记住:
IT
允许一到四个以下 Thumb 指令(IT 块)有条件或您可以说这里 ITTE 用于处理条件代码的小序列,最多 4 条指令。简单示例
Ex 1:
Ex 2:
这里
ITTE
对前两条指令施加NE条件,对下一条指令施加EQ条件。注意: IT 块中存在的任何分支都必须是该块中的最后一条指令。参考自 此处
以下示例将具有未定义的行为,因为分支指令在分支指令的中间使用。
实现上述内容的正确方法是将 mov 放在 blx 之前,如下所示:
有关更多信息 THUMB-2指令集参考手册第4-92页
第二条指令的条件IT 块
IT 块中第三条指令的条件
IT 块中第四条指令的条件指定指令上的可选汇编限定符
此处定义的两个限定符:
IT 块中第一条指令的条件,即 EQ、NE、CC、CS。In simple words
ITTE
executes following 3 execution as IF THEN {} THEN {} ELSE {} based on abovecmp
instruction.In ARMv6T2 and later architectures, you can use the
IT
instruction for conditional execution. In architectures before ARMv6T2, there is noIT
instruction and therefore Thumb instructions cannot be executed conditionally except for theB
branch instruction.The assembler checks the IT instructions, but omits them on assembly to ARM code.For your solution lets first understand syntax of simple
IT
instruction (introduced in Thumb 2)of ARM assembly ,which is base ofITTE
.IT{pattern} {cond}
If-then, sets the execution conditions for up to 4 following instructions
can be any combination of up to three T(then) and E(else) letters,the first instruction following IT is always cond (T) Instructions that can modify the program counter must be last in an IT block
The
then
conditions must match the condition code, and anyelse
conditions must be the opposite condition.The table below shows the condition codes and their opposites:Let's understand another
cmp
instruction.CMP Rn, #imm
Rn must be a Lo register. imm range 0-255.
These instructions update the N, Z, C and V flags according to the result.
Remember :
IT
allows one to four following Thumb instructions (the IT block) to be conditional or you can say here ITTE is used for handling small sequences of conditional code, up to 4 instructions.Simple examples
Ex 1:
Ex 2:
Here
ITTE
imposes the NE condition on first two following instruction and the EQ condition on the next.NOTE: Any branches that exist in an IT block must be the last instruction in the block.Taken reference from here
Following example will be having undefined behaviour because branch instruction is used in middle of branch instruction.
Correct way to implement the above would be to put the mov before the blx, as follows:
For more info THUMB-2 Instruction set reference manual Page 4-92
<x>
condition for second instruction in IT block<y>
condition for third instruction in IT block<z>
condition for fourth instruction in IT block<q>
specifies optional assembler qualifiers on the instructionTwo qualifier defined here :
<Firstcondition>
Condition for first instruction in IT block i.e EQ, NE,CC,CS.它似乎是
IT
(if-then
) 指令系列的一部分:http://infocenter.arm.com/help/topic/com.arm.doc.qrc0006e/QRC0006_UAL16.pdf(第二页)。基本指令是IT
,然后用T
表示“then”,E
表示“else”,得到ITTE
和条件代码NE
==“不等于”。It appears to the part of the
IT
(if-then
) instruction family: http://infocenter.arm.com/help/topic/com.arm.doc.qrc0006e/QRC0006_UAL16.pdf (second page). The basic instruction isIT
and then you haveT
for "then" andE
for "else" to giveITTE
and a condition code ofNE
== "not equal".它是 If-Then 指令系列的一部分(这是对 Thumb-2 代码使用条件执行的唯一方法)
查看此链接:
http://infocenter.arm。 com/help/index.jsp?topic=/com.arm.doc.dui0204j/Cjabicci.html
It's part of the If-Then family of instructions (which is the only way to use conditional execution for Thumb-2 code)
Check out this link:
http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0204j/Cjabicci.html