ARM汇编器中的编码寄存器操作数如何? [英] How are encoded register operands in ARM assembler ?
问题描述
我反编译了一些ARM ELF文件并阅读了汇编代码.但是,我看不到如何将某些代码转换为助记符.例如,我得到这样的代码:
I decompiled some ARM ELF Files and read the assembler code. But, I don't see how some codes are translated to the mnemonics. For example I get a code like this:
#hex code | #mnemonic | #binary
0xb480 | push {r7} | 1011 0100 1000 0000
0xb580 | push {r7, lr} | 1011 0101 1000 0000
0xb5f0 | push {r4,r5,r6,r7,lr} | 1011 0101 1111 0000
因此,如果推送多个值,您可以清楚地看到 push
的操作码是 0xb4
或 0xb5
.但是,如何创建寄存器列表呢?
So, you can clearly see the opcode for push
is 0xb4
or 0xb5
if pushing multiple values. But how is then the list of registers created ?
第一个例子很清楚, r7
由设置的第8位编码.但是,为什么第二个操作码也推送 lr
?没有位标记吗?
The first example is very clear, r7
is coded by the 8th bit, which is set. But, why does the second opcode also pushes lr
? Is there no bit flag for that ?
推荐答案
在Thumb模式下, PUSH
指令的三种编码.第一个是16位长,自ARMv4T(原始的Thumb实现)以来就存在:
There are three encodings of the PUSH
instruction in Thumb mode. The first one is 16 bits long and exists since ARMv4T (original Thumb implementation):
15141312|11|109|8| 7..0 |
1 0 1 1| 0| 10|M| register_list|
由于 register_list
是8位,因此它只能将寄存器 R0
推送到 R7
(和 LR
,如果 M
位置1).
Since register_list
is 8 bits, it can only push registers R0
to R7
(and LR
, if M
bit is set).
在Thumb-2(ARMv6T2,ARMv7和更高版本)中,添加了两个以上的编码.它们都是32位长:
In Thumb-2 (ARMv6T2, ARMv7 and later), two more encodings have been added. They are both 32 bits long:
1514131211|109|876|5|4|3210||151413| 12 .. 0 |
1 1 1 0 1| 00|100|1|0|1101|| 0 M 0| register_list |
在此代码中, register_list
是13位,因此它可以将 R0
推入 R12
和 LR
.
In this one, register_list
is 13 bits, so it can push R0
to R12
and LR
.
我不会列出第三种编码,但是它可以推送任何单个寄存器.
I won't list the third encoding, but it can push any single register.
BTW, POP
编码非常相似.
BTW, POP
encodings are very similar.
16位 POP
:
15141312|11|109|8| 7..0 |
1 0 1 1| 1| 10|P| register_list|
可以将 R0
弹出到 R7
和 PC
(位 P
).
Can pop R0
to R7
and PC
(bit P
).
32位 POP
多个:
1514131211|109|876|5|4|3210||151413| 12 .. 0 |
1 1 1 0 1| 00|010|1|0|1101|| P M 0| register_list |
可以弹出 R0
到 R12
, PC
(位 P
)和 LR
(位 M
).
Can pop R0
to R12
, PC
(bit P
) and LR
(bit M
).
这篇关于ARM汇编器中的编码寄存器操作数如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!