itte在臂总成 [英] itte in arm assembly
问题描述
什么是以下行臂组件做的:
What does the following line do in arm assembly:
000031e6 2916 cmp r1, #22
000031e8 bf1a itte ne
我得到的第一行(R1相比至22日)但对于第二行(之前我从来没有见过的itte命令和谷歌搜索返回任何内容)
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)
推荐答案
这是ARM的IF-THEN-ELSE指令,这是在Thumb-2指令集介绍。 (根据您上述具体的例子,那将是有益的,如果你已经表明,未来3说明随后的 ITTE
指令时,你就会明白为什么当你完成看完这个答案。)
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.)
此指令用于处理条件code小序列,多达4条指令。把它看成是实现ARM的条件执行不同的方式(例如BNE - 只执行分支指令,如果零标志没有被设置)
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).
它的好处是,它避免了服用一个分支处罚(您已经了解管线等presumably。)
The benefit of it is that it avoids the penalty of taking a branch (presumably you've learned about pipelines etc.)
的指令是有点麻烦,但一旦你环绕它你的头,这是pretty优雅。
The instruction is a bit involved but once you wrap your head around it, it's pretty elegant.
形式是这样的:
IT< X>< Y>< Z><&COND GT;
其中, X
,是
和以Z
是可选的,而且必须是 T
(对于然后)或电子
(对于其他)。 < COND>
是任何的条件,如 NE
或 EQ
或 GT
等,这反映在APSR标记。
where x
, y
, and z
are optional, and must be either T
(for "then") or E
(for "else"). <cond>
is any of the conditions such as NE
or EQ
or GT
, etc. that are reflected in the APSR flags.
所以,你总是有一个 T
继 I
(指令是 IT
毕竟!),然后0-3 电子
的或 T
的。对于每个 T
,每个电子
,您必须在匹配了相同的顺序后续指令。每个匹配后续指令必须有匹配的 IT
指令的条件。
So you always have one T
following the I
(the instruction is IT
after all!), and then 0-3 E
's or T
's. For each T
and each E
, you must have a subsequent instruction in the same order that matches up. Each matching subsequent instruction must have conditions that match up with the IT
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:
IT LT
SUBLT.W R2, R1
在此情况下,如果 LT
为真(每APSR标记),减法会发生。注意 LT
在 SUB
匹配 LT
在 IT
指令。
In this case, if LT
is true (per the APSR flags), the subtraction will take place. Notice the LT
in the SUB
matches the LT
in the IT
instruction.
一个成熟的例子是这样的:
A full-blown example would be something like:
ITETT NE
ADDNE R0, R0, R1
ADDEQ R0, R0, R3
ADDNE R2, R4, #1
MOVNE R5, R3
因此,我们有THEN ELSE THEN THEN(邰蒂
),其中 NE
状态。在随后的4个条件指令声明(邰蒂
4的指令,各1个),在然后指令具有 NE
的条件,与ELSE指令(在 IT
指令后的第二个指令 - 记E组的4 E和T的第2)具有相反的状态。它不可能是别的,即这将是一个错误,如果它是像 LT
而不是 EQ
。 EQ
是 NE
。
So we have THEN ELSE THEN THEN (TETT
), with NE
condition. Notice in the 4 conditional instructions that follow (4 instructions, 1 each for TETT
), the "THEN" instructions have the NE
condition, and the "ELSE" instruction (the 2nd instruction after the IT
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 like LT
instead of EQ
. EQ
is the opposite of NE
.
所以,如果 NE
为真,则说明1,3和4会被处决。否则( EQ
),只有2指令( ADDEQ
)将被执行。
So if NE
is true, then instructions 1, 3 and 4 would be executed. Otherwise (EQ
), only instruction 2 (ADDEQ
) would be executed.
我给了1个和4条指令的例子,但你也可以有2 (IT {T,E}
)和3个指令( IT {T,E} {T,E}
)的形式为好。
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.
最后,要带回家的地步,我给怎么下面的C code可以使用此指令来实现的例子:
Finally, to bring home the point, I'll give an example of how the following C code can be implemented using this instruction:
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
这应该给你足够的咀嚼了一会儿。
That should give you enough to chew on for a while.
这篇关于itte在臂总成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!