短寻址模式和长寻址模式有什么区别

发布于 2024-09-09 11:40:45 字数 103 浏览 2 评论 0原文

在浏览处理器架构的一些数据表时,我看到了这些术语, 短寻址模式和长寻址模式

任何人都可以给我这些术语的一般概念(不需要特定于处理器!)

/renjith_g

While going through some data sheets of a processor architecture , i saw the terms,
short addressing mode and long addressing mode

Can anybody give me the general idea of the terms(not needed to be processor specific!)

/renjith_g

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

落在眉间の轻吻 2024-09-16 11:40:50
  • 短寻址模式使用
    相对地址,计算为(一些
    寄存器+一些小常量),
    通常允许小/少/快
    指令,但只能寻址小范围的内存;
  • 长寻址模式
    使用绝对地址,即
    一般要求大/多/慢
    指令,但可以访问任何内存。

我将给出 ARM 代码作为示例,但这可能适用于(一般意义上)许多其他处理器。

每个 ARM 指令(忽略 Thumb)都是 32 位长,在本示例中,我们假设 ARM 可以访问 32 位地址空间。

每条指令都必须进行解码,主要是将这 32 位分解为不同的字段,其中一些位必须用于存储指令的类型。

因此,希望您能够清楚地知道,您不能在一条指令中将任意地址加载到寄存器中:这

MOV Rn, #AABBCCDD

是行不通的 - 因为我们需要使用位来指定指令 (MOV) 和目标寄存器 (Rn),所以我们没有剩余的 32 位来存储 32 位地址。

因此,如果我们想要寄存器中某个内容的地址,我们有几个选择:

1。使用 PC-relative

有一个伪操作,其工作原理如下:

ADR Rn, .label
...
.label

其扩展为:

ADD Rn, PC, (.label - here)

假设 .label 在当前指令的大约 4k 范围内,我们可以从当前 PC(程序计数器)中进行加/减来得到那个地址。那是一个相对地址。

2.使用多个指令

您可以使用adds或ors构建任意地址:(

MOV Rn, #AA000000
ADD Rn, Rn, #00BB0000
ADD Rn, Rn, #0000CC00
ADD Rn, Rn, #000000DD

实际上您可以更有效地做到这一点,但您明白了)。

3.将绝对地址存储在已知的相对位置

如果你知道你想要的地址存储在附近,你可以从内存中加载它:

ADR Rn, .store
LDR Rn, [Rn]

.store
EQU #AABBCCDD

现在,其他处理器架构可能有可变长度指令(例如x86),所以你可以选择是否使用短相对寻址模式(例如相对于 PC 或其他寄存器),或保存整个 32 位地址的较长(并且可能)较慢的指令。

  • A short addressing mode uses a
    relative address, calculated as (some
    register + some smallish constant),
    which generally allows small/few/fast
    instructions, but can only address a small range of memory;
  • A long addressing mode
    uses absolute addresses, which
    generally require large/many/slow
    instructions, but which can access any memory.

I'll give as an example ARM code, but this probably applies (in the general sense) to many other processors.

Each ARM instruction (ignoring Thumb) is 32 bits long, and for the sake of this example, we'll pretend the ARM can access a 32-bit address space.

Each instruction must be decoded, essentially by breaking down those 32 bits into various fields - and some of those bits must be used to store the type of the instruction.

Hopefully therefore, it should be clear that you can't load an arbitrary address into a register in one instruction:

MOV Rn, #AABBCCDD

Won't work - since we need to use bits to specify the instruction (MOV) and the destination register (Rn), we don't have 32 bits left to store a 32-bit address.

So, if we want the address of something in a register, we have a few options:

1. Use PC-relative

There's a pseudo-op which works as follows:

ADR Rn, .label
...
.label

Which gets expanded to:

ADD Rn, PC, (.label - here)

Provided .label is within about 4k of the current instruction, we can add/subtract from the current PC (program counter) to get that address. That's a relative address.

2. Use multiple instructions

You can build up an arbitray address using adds or ors:

MOV Rn, #AA000000
ADD Rn, Rn, #00BB0000
ADD Rn, Rn, #0000CC00
ADD Rn, Rn, #000000DD

(Actually you can do it much more efficiently, but you get the idea).

3. Store the absolute address in a known relative location

If you know the address you want is stored nearby, you can load it from memory:

ADR Rn, .store
LDR Rn, [Rn]

.store
EQU #AABBCCDD

Now, other processor architectures may have variable-length instructions (eg x86), so you can choose whether to use a short relative addressing mode (eg relative to PC or another register), or a longer (and probably) slower instruction which holds an entire 32-bit address.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文