如何确定一个字(4 个字节)是 16 位指令还是 32 位指令? [英] How to determine if a word(4 bytes) is a 16-bit instruction or 32-bit instruction?

查看:28
本文介绍了如何确定一个字(4 个字节)是 16 位指令还是 32 位指令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何知道字中的字节代表的是 16 位指令还是 32 位指令?
我提到了ARM ARMv7M,我不清楚如何区分它是16位指令还是32位指令.
它说
如果被解码的半字的位 [15:11] 采用以下任一值,则该半字是 32 位指令的第一个半字:
• 0b11101• 0b11110• 0b11111.否则,半字为 16 位指令

How do I know if the bytes in the word represent a 16-bit instruction or a 32-bit instruction ?
I referred the ARM ARMv7M and I am not clear how to distinguish if it a 16-bit instruction or a 32-bit instruction.
It says
If bits [15:11] of the halfword being decoded take any of the following values, the halfword is the first halfword of a 32-bit instruction:
• 0b11101 • 0b11110 • 0b11111. Otherwise, the halfword is a 16-bit instruction

这是否意味着处理器总是获取半字,检查它们并决定它是 16 位还是 32 位?
前半句是什么意思?一个字中的位 [31-16] 或位 [15-0] ?

Does it mean that the processor always fetches halfwords, examines them and decides if it's 16 or 32-bit ?
What does the first halfword mean ? Bit[31-16] or Bit[15-0] in a word ?

如果我有 32 位指令,那么我能知道它是 32 位指令还是 16 位指令吗?

If I have 32-bits then can I know if it's a 32-bit instruction or a 16-bit instruction ?

谢谢.

推荐答案

在 Thumb 中,32 位"指令仍然由两个单独的半字组成,因此前半字"是编码的前半字 ,它没有说明内存中的布局.Thumb 指令是半字对齐的,因此任何给定的内存字都可以容纳两条 16 位指令、一条 16 位指令和一条 32 位指令的一半、两条不同的 32 位指令的两半或一整条 32-位指令.

In Thumb, "32-bit" instructions are still composed of two separate halfwords, so the "first halfword" is the first halfword of the encoding, which says nothing about the layout in memory. Thumb instructions are halfword-aligned, so any given word of memory could hold two 16-bit instructions, a 16-bit instruction and one half of a 32-bit instruction, two halves of two different 32-bit instructions, or one whole 32-bit instruction.

从概念上讲,处理器一次解码一个半字,因此如果它看到上述位模式之一,它知道在实际执行该指令之前还需要解码下一个半字.由于 Cortex-M3/M4 实际上只从内存中获取整个 32 位字,因此指令获取"的数量与实际解码和执行的指令数量之间的相关性取决于代码本身.试想一下,这些提取是为了重新填充一个 4 字节的缓冲区,管道从中提取出单个半字(据我所知,这可能与事实相去甚远).

Conceptually, the processor decodes one halfword at a time, thus if it sees one of the above bit patterns, it knows it needs to also decode the next halfword before it can actually execute this instruction. Reality complicates this somewhat since the Cortex-M3/M4 only ever actually fetch whole 32-bit words from memory, so the correlation between the number of "instruction fetches" and the number of instructions actually decoded and executed depends on the code itself. Just imagine that those fetches are to refill a 4-byte buffer that the pipeline slurps individual halfwords out of (which may not be all that far off the truth, for all I know).

因此,如果您有一个半字在其最高位包含这些值之一,那么您就知道它是 32 位编码的前半部分,您需要将其与下一个半字一起解释.相反,如果半字的最高位具有任何其他值,那么它要么是 16 位编码,要么是 32 位编码的后半部分,具体取决于前一个半字是什么.

So, if you have a halfword containing one of those values in its top bits, then you know it's the first half of a 32-bit encoding, and you need to interpret it in conjunction with the next halfword. Conversely, if you have a halfword with any other value in its top bits, then it's either a 16-bit encoding, or the second half of a 32-bit encoding, depending on what the previous halfword was.

请注意,指令总是小端的,因此 32 位编码的实际内存布局如下所示,其中地址 A 是偶数:

Note that instructions are always little-endian, so the actual in-memory layout of a 32-bit encoding looks like this, where address A is an even number:

          --------------------------------
address A | bits 7:0 of first halfword   |
          --------------------------------
      A+1 | bits 15:8 of first halfword  |
          --------------------------------
      A+2 | bits 7:0 of second halfword  |
          --------------------------------
      A+3 | bits 15:8 of second halfword |
          --------------------------------

这篇关于如何确定一个字(4 个字节)是 16 位指令还是 32 位指令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆