# 寻址方式

寻址方式（addressing mode）是处理器指令集架构所定义的一条规则，用于计算指令操作数的位置：这个位置可以是随指令本身携带的数值，可以是一个寄存器，也可以是由寄存器、常量（有时还包括[程序计数器](https://www.edgepedia.org/zh/program-counter)）算出的[内存地址](https://www.edgepedia.org/zh/memory-address)。所选的寻址方式决定了指令需要多少位、会发生多少次内存访问，以及单条指令能够表达哪些数据访问模式，例如数组索引或栈的压入弹出。

| 关键事实 | 细节 |
|---|---|
| 核心方式 | 最常见的类型是立即、直接、间接、变址和寄存器寻址<sup>[1](https://www.sciencedirect.com/science/article/pii/B9780120645503500076)</sup> |
| 使用频率 | 在实测指令流中，立即、直接、寄存器间接和基址+偏移量四种方式合计占全部寻址方式使用的 88%<sup>[2](https://cseweb.ucsd.edu/classes/fa01/cse141/isa.pdf)</sup> |
| A64 方式 | 基址寄存器、偏移量、前索引和后索引；前索引在访问之前更新基址，后索引在访问之后更新<sup>[3](https://developer.arm.com/-/media/Files/pdf/graphics-and-multimedia/ARMv8_InstructionSetOverview.pdf)</sup> |
| x86-64 一般形式 | 基址 + 变址 × 比例因子 + 位移量，比例因子限于 1、2、4 或 8，另有指令指针相对寻址<sup>[4](https://ocw.mit.edu/courses/6-172-performance-engineering-of-software-systems-fall-2018/8955b91dbd47c241fb2904c700fdb697_MIT6_172F18_lec4.pdf)</sup> |
| RISC-V 基础 ISA | 有效地址 = 寄存器 rs1 加符号扩展的 12 位偏移量；跳转与分支为 PC 相对，以支持位置无关代码<sup>[5](https://docs.riscv.org/reference/isa/v20260120/unpriv/rv32.html)</sup> |
| 向量方式 | RISC-V 向量扩展增加了单位步长、常量步长和索引（分散/聚集）寻址，用于逐元素的内存访问<sup>[6](https://docs.riscv.org/reference/isa/_attachments/riscv-unprivileged.pdf)</sup> |

## 标准寻址方式

教科书通常把寻址方式归并为少数几种形式。在**立即寻址**中，操作数字段包含操作数本身，通常是嵌在指令里的数值常量。在**直接寻址**中，该字段包含操作数的地址。在**间接寻址**中，该字段包含一个内存地址或寄存器名，其内容被用作操作数的地址；当多条指令引用同一个操作数时，这种方式很有用。**变址寻址**把一个变量加到基址上，适合对连续若干组数据进行计算；**寄存器寻址**则以某个寄存器为操作数，寄存器间接形式则把寄存器的内容当作地址<sup>[1](https://www.sciencedirect.com/science/article/pii/B9780120645503500076)</sup>。一份相关的综述列出了六种主要的计算方案：立即、直接、变址、基址、间接和双操作数<sup>[7](https://www.sciencedirect.com/topics/computer-science/immediate-addressing)</sup>。

立即寻址在某种意义上根本不算内存寻址方式：被操作的数据本身就是指令格式的一部分<sup>[7](https://www.sciencedirect.com/topics/computer-science/immediate-addressing)</sup>，而且它只能提供源操作数，永远不能充当目的操作数<sup>[8](https://www.cs.umd.edu/users/meesh/411/CA-online/chapter/instruction-set-architecture/index.html)</sup>。

实测指令流表明，少数几种方式占据主导地位。在一项指令分析中，立即、直接、寄存器间接和基址+偏移量四种方式合计占全部寻址方式使用的 88%<sup>[2](https://cseweb.ucsd.edu/classes/fa01/cse141/isa.pdf)</sup>。这种集中正是精简指令集设计只保留少数几种方式的原因之一：每增加一种方式都要消耗编码位，并使每一个负责译码和计算地址的阶段变得复杂。

## Arm A64：基址、偏移量、前索引与后索引

Armv8-A 的 A64 指令集把加载和存储的地址写在方括号内，并提供四种方式，区别在于基址寄存器是否更新以及何时更新。设指针位于 X1，各形式及其 C 语言类比为<sup>[3](https://developer.arm.com/-/media/Files/pdf/graphics-and-multimedia/ARMv8_InstructionSetOverview.pdf)</sup>：

- `LDR W0, [X1]`，仅用基址寄存器；X1 不变，等价于 `out = *intptr`。
- `LDR W0, [X1, #4]`，偏移量寻址；X1 不变，等价于 `out = intptr[1]`。
- `LDR W0, [X1, #4]!`，前索引；X1 在加载之前更新，等价于 `out = *(++intptr)`。
- `LDR W0, [X1], #4`，后索引；X1 在加载之后更新，等价于 `out = *(intptr++)`。

在指令语法中，前索引在方括号之后加一个感叹号表示，如 `LDR W0, [X1, #12]!`；该指令执行完毕后，X1 的值为 X1+12<sup>[9](https://developer.arm.com/-/media/Arm%20Developer%20Community/PDF/Learn%20the%20Architecture/Armv8-A%20Instruction%20Set%20Architecture.pdf?revision=ebf53406-04fd-4c67-a485-1b329febfb3e)</sup>。后索引寻址适合从栈中弹出数据：指令先加载栈指针处的值，然后把栈指针移到下一个位置<sup>[9](https://developer.arm.com/-/media/Arm%20Developer%20Community/PDF/Learn%20the%20Architecture/Armv8-A%20Instruction%20Set%20Architecture.pdf?revision=ebf53406-04fd-4c67-a485-1b329febfb3e)</sup>。

偏移量寻址中的偏移量可以是常量，也可以是另一个寄存器，这适合访问结构体：编译器保存一个指向结构体基址的指针，用偏移量选取成员<sup>[9](https://developer.arm.com/-/media/Arm%20Developer%20Community/PDF/Learn%20the%20Architecture/Armv8-A%20Instruction%20Set%20Architecture.pdf?revision=ebf53406-04fd-4c67-a485-1b329febfb3e)</sup>。A64 还有成对加载（LDP）和成对存储（STP）指令，一次传送两个寄存器，常用于压栈和出栈，例如 `STP X0, X1, [SP, #-16]!` 把两个寄存器压入栈<sup>[9](https://developer.arm.com/-/media/Arm%20Developer%20Community/PDF/Learn%20the%20Architecture/Armv8-A%20Instruction%20Set%20Architecture.pdf?revision=ebf53406-04fd-4c67-a485-1b329febfb3e)</sup>。

**一致性作为设计目标。** A64 加载和存储指令的一个显著特点是：寻址方式与所传送的数据宽度和寄存器类型相互正交<sup>[10](https://developer.arm.com/-/media/Files/pdf/graphics-and-multimedia/Porting%20to%20ARM%2064-bit.pdf)</sup>。对于标量整数、浮点数和 SIMD 寄存器，各种宽度与符号的变体都使用统一的加载和存储寻址方式，这使编译器的指令选择与编码更为容易<sup>[11](https://developer.arm.com/community/arm-community-blogs/b/architectures-and-processors-blog/posts/the-a64-isa-and-compilers)</sup>。这与 A32 形成对照：在 A32 中，半字传送（LDRH 及相关形式）的编码与字节、字传送不同，支持的偏移范围也不一样，给编译器编写者带来负担<sup>[11](https://developer.arm.com/community/arm-community-blogs/b/architectures-and-processors-blog/posts/the-a64-isa-and-compilers)</sup>。A64 还加长了偏移量：PC 相对的加载和存储指令可达 ±1 MB，足以覆盖任何单个编译单元，从而简化了字面量池的管理<sup>[11](https://developer.arm.com/community/arm-community-blogs/b/architectures-and-processors-blog/posts/the-a64-isa-and-compilers)</sup>。除独占访问和有序访问外，所有加载和存储都支持非对齐地址<sup>[11](https://developer.arm.com/community/arm-community-blogs/b/architectures-and-processors-blog/posts/the-a64-isa-and-compilers)</sup>。

## x86-64：基址、变址、比例因子、位移量

x86-64 架构支持间接寻址，即内存地址是计算出来的，而非直接给出。其最一般的形式是 基址 + 变址 × 比例因子 + 位移量，其中基址和变址是通用寄存器，位移量是 8 位、16 位或 32 位的值，比例因子为 1、2、4 或 8；未指定的分量默认为零（变址和位移量）或一（比例因子）<sup>[4](https://ocw.mit.edu/courses/6-172-performance-engineering-of-software-systems-fall-2018/8955b91dbd47c241fb2904c700fdb697_MIT6_172F18_lec4.pdf)</sup>。比例因子与常见 C 数据类型的宽度相吻合，因此 `movl (%ebx, %esi, 4), %eax` 读取的是 EBX 加四倍 ESI 所形成地址处的 32 位值，这是数组索引的一种自然表达<sup>[12](https://docs.oracle.com/cd/E19455-01/806-3773/assemblersyntax-21/index.html)</sup>。

IA-32 汇编语法把它写作 `[sreg:][offset][([base][,index][,scale])]`，其中 sreg 是可选的段寄存器覆盖，offset 是相对段基址的位移量，可以是绝对地址也可以是可重定位地址，base 和 index 可以是任意 32 位寄存器<sup>[12](https://docs.oracle.com/cd/E19455-01/806-3773/assemblersyntax-21/index.html)</sup>。在 64 位模式下，架构增加了 RIP 相对寻址，地址相对于指令指针进行索引<sup>[4](https://ocw.mit.edu/courses/6-172-performance-engineering-of-software-systems-fall-2018/8955b91dbd47c241fb2904c700fdb697_MIT6_172F18_lec4.pdf)</sup>。一条 x86-64 指令最多只能有一个操作数指定内存地址<sup>[4](https://ocw.mit.edu/courses/6-172-performance-engineering-of-software-systems-fall-2018/8955b91dbd47c241fb2904c700fdb697_MIT6_172F18_lec4.pdf)</sup>。

## RISC-V：基础指令集一种方式，扩展中更多

RV32I 基础指令集刻意保持极简。它是加载-存储架构，只有加载和存储指令访问内存，有效地址由寄存器 rs1 加上符号扩展的 12 位偏移量得到<sup>[5](https://docs.riscv.org/reference/isa/v20260120/unpriv/rv32.html)</sup>。浮点加载和存储使用相同的基址+偏移量方式，基址在 rs1 中，偏移量为 12 位有符号字节偏移<sup>[13](https://docs.riscv.org/reference/isa/v20191213/_attachments/riscv-unprivileged.pdf)</sup>。控制转移统一采用 PC 相对：所有无条件跳转指令都使用 PC 相对寻址，以帮助支持位置无关代码，JAL 跳转的目标范围为 ±1 MiB<sup>[5](https://docs.riscv.org/reference/isa/v20260120/unpriv/rv32.html)</sup>。

压缩指令扩展（RVC）保持相同的基址+偏移量形式，但把零扩展的立即数按数据宽度缩放——字 ×4、双字 ×8、四字 ×16——以扩大 16 位指令的到达范围，并另外提供一种基于栈指针的形式，因为寄存器的保存与恢复实在太常见了<sup>[14](https://docs.riscv.org/reference/isa/v20260120/unpriv/c-st-ext.html)</sup>。

向量扩展增加了可一次寻址多个元素的方式：单位步长操作从基址开始访问连续存放的元素；常量步长操作按寄存器中保存的字节偏移量步进；索引操作把向量偏移量操作数的每个元素加到基址上，得到每个元素的有效地址，即分散/聚集形式<sup>[6](https://docs.riscv.org/reference/isa/_attachments/riscv-unprivileged.pdf)</sup>。索引操作刻意没有定义为按数据宽度缩放元素索引，这样就能把一个指针向量与一个标量偏移量相加，访问对象向量中某个成员字段<sup>[6](https://docs.riscv.org/reference/isa/_attachments/riscv-unprivileged.pdf)</sup>。

## 寻址方式集合为何重要

寻址方式处于编码空间与编译器便利性的交汇处。丰富的方式让一条指令表达原本需要多条指令才能表达的内容，例如 A64 的后索引加载取代了加载加加法；但每一种方式都要占用操作码位，并需要地址生成硬件。RISC-V 的设计者在考虑非对齐访问支持时明确指出了这一权衡：新的硬件寻址方式会占用指令编码中相当大的空间，或者迫使采用诸如仅寄存器间接这样极为简化的方式<sup>[5](https://docs.riscv.org/reference/isa/v20260120/unpriv/rv32.html)</sup>。四种方式占 88% 的集中现象<sup>[2](https://cseweb.ucsd.edu/classes/fa01/cse141/isa.pdf)</sup>解释了为什么现代 64 位 ISA 都收敛到一个小而统一的集合：基址加偏移量（可选写回），加上用于代码和数据的 PC 相对形式，而把分散/聚集之类不规则的模式推给可选的向量扩展<sup>[6](https://docs.riscv.org/reference/isa/_attachments/riscv-unprivileged.pdf)</sup>。

## References

1. [Addressing Modes, Introduction to Microprocessors (ScienceDirect, 1977)](https://www.sciencedirect.com/science/article/pii/B9780120645503500076)
2. [Instruction Set Architecture, CSE 141, UC San Diego](https://cseweb.ucsd.edu/classes/fa01/cse141/isa.pdf)
3. [ARMv8-A A64 ISA Overview, Arm](https://developer.arm.com/-/media/Files/pdf/graphics-and-multimedia/ARMv8_InstructionSetOverview.pdf)
4. [6.172 Performance Engineering of Software Systems, Lecture 4, MIT OpenCourseWare](https://ocw.mit.edu/courses/6-172-performance-engineering-of-software-systems-fall-2018/8955b91dbd47c241fb2904c700fdb697_MIT6_172F18_lec4.pdf)
5. [RV32I Base Integer Instruction Set, Version 2.1, RISC-V Ratified Specifications Library](https://docs.riscv.org/reference/isa/v20260120/unpriv/rv32.html)
6. [The RISC-V Instruction Set Manual Volume I: Unprivileged Architecture, RISC-V International](https://docs.riscv.org/reference/isa/_attachments/riscv-unprivileged.pdf)
7. [Immediate Addressing, ScienceDirect Topics](https://www.sciencedirect.com/topics/computer-science/immediate-addressing)
8. [Instruction Set Architecture, Computer Architecture, University of Maryland](https://www.cs.umd.edu/users/meesh/411/CA-online/chapter/instruction-set-architecture/index.html)
9. [Armv8-A Instruction Set Architecture, Arm Learn the Architecture](https://developer.arm.com/-/media/Arm%20Developer%20Community/PDF/Learn%20the%20Architecture/Armv8-A%20Instruction%20Set%20Architecture.pdf?revision=ebf53406-04fd-4c67-a485-1b329febfb3e)
10. [Porting to 64-bit ARM, Arm](https://developer.arm.com/-/media/Files/pdf/graphics-and-multimedia/Porting%20to%20ARM%2064-bit.pdf)
11. [The A64 ISA and compilers, Arm Community](https://developer.arm.com/community/arm-community-blogs/b/architectures-and-processors-blog/posts/the-a64-isa-and-compilers)
12. [Addressing Modes, IA-32 Assembly Language Reference Manual, Oracle](https://docs.oracle.com/cd/E19455-01/806-3773/assemblersyntax-21/index.html)
13. [Volume I: RISC-V Unprivileged ISA V20191213, RISC-V International](https://docs.riscv.org/reference/isa/v20191213/_attachments/riscv-unprivileged.pdf)
14. ["C" Extension for Compressed Instructions, Version 2.0, RISC-V Ratified Specifications Library](https://docs.riscv.org/reference/isa/v20260120/unpriv/c-st-ext.html)

---
*Initially written Sep 17, 2026 · Reviewed: Oct 15, 2026 · Edited: Oct 15, 2026 · Last review: Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 计算机硬件 › Processors & processor engineering › Instruction set architectures › ISA design concepts and classification

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/addressing-mode

English original: https://www.edgepedia.org/addressing-mode
