以下的ARM汇编语句是什么意思:
000031e6 2916 cmp r1, #22
000031e8 bf1a itte ne
我知道如何得到第一行(将r1与22进行比较),但第二行不清楚(我从未见过itte命令,谷歌搜索也没有返回结果)
以下的ARM汇编语句是什么意思:
000031e6 2916 cmp r1, #22
000031e8 bf1a itte ne
我知道如何得到第一行(将r1与22进行比较),但第二行不清楚(我从未见过itte命令,谷歌搜索也没有返回结果)
ITTE
指令后面的下3条指令,那么阅读完这篇答案后你就会明白为什么这很有帮助。)IT<x><y><z><cond>
其中, 和是可选的,并且必须是T(表示"then")或E(表示"else")。 是反映在APSR标志中的任何条件,如NE、EQ或GT等。IT LT
SUBLT.W R2, R1
LT
为真,将进行减法运算。请注意SUB
中的LT
与IT
指令中的LT
相匹配。ITETT NE
ADDNE R0, R0, R1
ADDEQ R0, R0, R3
ADDNE R2, R4, #1
MOVNE R5, R3
因此,如果NE为true,则将执行指令1、3和4。否则(EQ),只执行指令2(ADDEQ)。
我已经给出了1和4指令的示例,但您也可以使用2(ITT)和3指令(ITTET)形式。
最后,为了说明这一点,我将举一个实现以下C代码的示例:
if (R4 == R5)
{
R7 = R8 + R9;
R7 /= 2;
}
else
{
R7 = R10 + R11;
R7 *= 2;
}
转换为
CMP R4, R5
ITTEE EQ
ADDEQ R7, R8, R9 ; if R4 = R5, R7 = R8 + R9
ASREQ R7, R7, #1 ; if R4 = R5, R7 /= 2
ADDNE R7, R10, R11 ; if R4 != R5, R7 = R10 + R11
LSLNE R7, R7, #1 ; if R4 != R5, R7 *=2
这应该能让你有足够的东西消化一段时间了。
简单来说,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 块中的最后一条指令。
Then
条件必须匹配条件码,而任何 else
条件必须是相反的条件。下表显示了条件码及其相反条件:
cmp
指令。
CMP Rn,#imm
Rn必须是Lo寄存器。 imm范围为0-255。
这些指令根据结果更新N,Z,C和V标志。IT
允许对接下来的一个到四条Thumb指令(IT块)进行条件处理,或者在这里可以使用ITTE来处理最多4条指令的小序列。
简单例子cmp r1, #22 Compare r1 value with 22
IT EQ Read this as If EQual Then ADD R1,R1,#1
ADD R1,R1,#1 <- This will only be executed if above r1 value equal to 22(means when z condition flag is equal to 1)
例2:
cmp r1, #22 Compare r1 value with 22
ITE EQ Read this as If EQual Then ADD R1,R1,#1 Else ADD R0,R0,#1
ADD R1,R1,#1 <- This will only be executed if the Z condition flag is 1
ADD R0,R0,#1 <- This will only be executed if the Z condition flag is 0
ITTE是什么?这是你的问题。
CMP R1, #22 Compare r1 value with 22
ITTE NE Read this as IF NotEqual Then ADD R1,R1,#1 Then ADD R0,R0,#1 Else ADD R2,R2,#1
ADD R1,R1,#1 <- This will only be executed if the Z condition flag is 0
ADD R0,R0,#1 <- This will only be executed if the Z condition flag is 0
ADD R2,R2,#1 <- This will only be executed if the Z condition flag is 1
这里ITTE
对接下来的前两个指令施加了NE条件,对下一个指令施加了EQ条件。
注意:任何存在于IT块中的分支必须是块中的最后一条指令。参考自此处。 以下示例将会产生未定义行为,因为在分支指令中途使用了分支指令。
ite eq
blxeq some_label @ UNPREDICTABLE during an IT block.
movne r0, #0
ite ne
movne r0, #0
blxeq some_label @ Ok at the end of an IT block.
如需更多信息,请查看THUMB-2指令集参考手册第4-92页。
IT{x{y{z}}}<q> <Firstcondition>
<x>
,第三条指令的条件为<y>
,第四条指令的条件为<z>
。指令上的可选汇编限定符由<q>
指定。这里定义了两个限定符。 .N Meaning Narrow. Assembler has to choose 16-bit encoding for the instruction if it is not possible then error.
.W Meaning Wide. Assembler has to select 32-bit encoding for the instruction if is not possible then error.
< p > <Firstcondition>
是IT块中第一条指令的条件,例如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
==“不相等”。
这是 If-Then 指令族的一部分(这是在 Thumb-2 代码中使用条件执行的唯一方法)
请查看此链接: http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0204j/Cjabicci.html