简体   繁体   English

将ARM程序集助记符转换为字节

[英]Converting ARM assembly mnemonics to bytes

I am sort of a newbie to assembly language, and I need help understanding how mnemonics are converted directly to bytes. 我是汇编语言的新手,我需要帮助理解助记符如何直接转换为字节。

For example, I have a line saying 例如,我有一句话说

b 0x00002B78

which is located at the memory address 0x00002A44. 它位于存储器地址0x00002A44。 How does this translate to EA00004B (the byte representation of the above assembly)? 这如何转换为EA00004B(上述程序集的字节表示)? I am under the impression that the "EA00" signifies the "b" branching part of the assembly, but what about the "004B"? 我的印象是“EA00”表示装配的“b”分支部分,但是“004B”呢? If anyone can give a general understanding of this and resources to find conversions and such, that would be appreciated. 如果有人能够对这个和资源进行一般性的了解以找到转换等,那将是值得赞赏的。 I tried googling this but I am really not to sure what to google exactly. 我试过谷歌搜索这个,但我真的不确定谷歌究竟是什么。 The stuff I have been googling has not been helpful. 我一直在谷歌搜索的东西没有帮助。

All the information you're looking for is in the ARM Architecture Reference Manual . 您正在寻找的所有信息都在“ ARM体系结构参考手册”中 If you look up the b instruction, you'll see its encoding and how it works. 如果你查看b指令,你会看到它的编码及其工作原理。 Here's the specific instruction you care about: 以下是您关注的具体说明:

摘自ARM文档

The E is the condition field, which you can look up in this table: E是条件字段,您可以在此表中查找:

条件字段

For you, it's "execute always". 对你来说,这是“永远执行”。 Then the A , which in binary is the 1010 to match bits 27:24 (you have a branch instruction, not a branch & link instruction). 然后A ,二进制是1010匹配位27:24(你有一个分支指令,而不是分支和链接指令)。 Lastly the rest of the instruction is the immediate offset field. 最后,指令的其余部分是立即偏移字段。 It's a PC-relative offset, which is why it's encoded as 0x00004b . 它是PC相对偏移量,这就是它编码为0x00004b

Let's look at your specific example now. 我们现在来看看您的具体示例。 You have the instruction: 你有这样的指示:

b 0x00002B78

located at address 0x00002a44 . 位于地址0x00002a44 OK, great. 好,很好。 So first off, we can stick in the opcode bits: 首先,我们可以坚持使用操作码位:

cccc 101L xxxx xxxx xxxx xxxx xxxx xxxx

Now, the L bit is zero for our case: 现在,对于我们的情况, L位为零:

cccc 1010 xxxx xxxx xxxx xxxx xxxx xxxx

We want to execute this instruction unconditionally, so we add the AL condition code bits: 我们想无条件地执行该指令,因此我们添加AL条件代码位:

1110 1010 xxxx xxxx xxxx xxxx xxxx xxxx

And now all we have to do is calculate the offset. 现在我们所要做的就是计算偏移量。 The PC will be 0x2a4c when this instruction is executed (the PC is always "current instruction + 8" in ARM), so our relative jump needs to be: 执行该指令时PC将为0x2a4c (ARM中的PC始终为“当前指令+8”),因此我们的相对跳转需要为:

0x2b78 - 0x2a4c = 0x12c

Great - now we apply the reverse of the transformations described in the documentation above, rightshifting 0x12c by two: 太棒了 - 现在我们应用上面文档中描述的转换的反向,将0x12c 0x12c两个:

0x12c / 4 = 0x4b = 0b1001011

And that's the last field: 那是最后一个领域:

1110 1010 0000 0000 0000 0000 0100 1011

Turning that binary instruction back into hex gives you the instruction encoding you were looking for: 将该二进制指令转回十六进制为您提供您正在寻找的指令编码:

0xea00004b

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM