# ARM 汇编语言

**ARM 汇编语言**是 Arm 架构指令集的人类可读记法。Arm 架构是一个 RISC（精简指令集计算）处理器架构家族，最早实现在 1985 年完成的 ARM1 芯片中<sup>[1](https://newsroom.arm.com/blog/40-year-anniversary-of-arm-architecture)</sup>。Arm 处理器的汇编程序用若干指令集方言之一编写，其中最突出的是用于 64 位 AArch64 执行状态的 A64，以及用于 32 位 AArch32 状态的 A32 和 T32，并且必须遵循该架构的应用二进制接口（ABI）才能与编译器生成的代码互操作<sup>[2](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> • </sup><sup>[3](https://developer.apple.com/documentation/xcode/writing-arm64-code-for-apple-platforms?changes=_1)</sup>。

| 关键事实 | 详情 |
|---|---|
| 指令集 | Armv8-A 支持三种指令集：A32（“ARM”）、T32（“Thumb”）和 A64；A64 用于 AArch64 执行状态<sup>[2](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 编码 | 定长 32 位指令；A64 中的“64”指执行状态，而非内存中的指令大小<sup>[2](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> |
| 寄存器 | 31 个非分组 64 位通用寄存器（X0–X30）；寄存器 31 视上下文充当零寄存器或栈指针；PC 不能作为具名寄存器访问<sup>[4](https://developer.arm.com/community/arm-community-blogs/b/architectures-and-processors-blog/posts/the-a64-isa-and-compilers)</sup> |
| W 和 X 寄存器 | 写入 W（32 位）寄存器会将对应 X（64 位）寄存器的高 32 位清零<sup>[2](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> |
| 分支范围 | 条件分支可达 ±1 MB，无条件分支可达 ±128 MB；PC 相对加载/存储偏移可达 ±1 MB<sup>[4](https://developer.arm.com/community/arm-community-blogs/b/architectures-and-processors-blog/posts/the-a64-isa-and-compilers)</sup> |
| 调用标准 | 《Arm 64 位架构过程调用标准》（AAPCS64）定义了参数传递、寄存器使用和栈管理<sup>[5](https://github.com/ARM-software/abi-aa/blob/main/aapcs64/aapcs64.rst)</sup> |
| Apple 要求 | 在 Apple 平台上，栈指针必须遵循 ARM64 标准 ABI 并保持 16 字节对齐<sup>[3](https://developer.apple.com/documentation/xcode/writing-arm64-code-for-apple-platforms?changes=_1)</sup> |

## 指令集与执行状态

Arm 架构将指令集与寄存器宽度的执行状态分离。在 Armv8-A 中，在 AArch64 执行状态下执行时使用 A64 指令集，而在 AArch32 执行状态下使用 A32 和 T32（历史上称为“ARM”和“Thumb”）<sup>[2](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 是定长 32 位编码：每条指令在内存中恰好占用 32 位，寄存器字段位于固定位置，立即数大多位于连续位字段中<sup>[4](https://developer.arm.com/community/arm-community-blogs/b/architectures-and-processors-blog/posts/the-a64-isa-and-compilers)</sup>。

该架构通过简单顺序执行（SSE）模型定义行为：处理器表现得就像按内存顺序逐条取指、译码和执行指令。真实处理器在内部进行流水线和重排序，但每个处理器都必须与该模型保持一致<sup>[2](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 编程模型

**寄存器。** A64 提供 31 个非分组通用寄存器，每个 64 位宽，构成一个正交集合，但寄存器 31 例外，它视上下文表示零寄存器或栈指针<sup>[4](https://developer.arm.com/community/arm-community-blogs/b/architectures-and-processors-blog/posts/the-a64-isa-and-compilers)</sup>。零寄存器 XZR 和 WZR 始终读为 0，并忽略写入。X30 用作过程返回的链接寄存器（LR），异常返回则由单独的 ELR_ELx 寄存器处理<sup>[2](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>。栈指针可用作加载和存储的基地址，也可用于有限的一组数据处理指令，但它不是通用寄存器；Armv8-A 提供多个栈指针，每个异常级别一个<sup>[2](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>。

每个 64 位寄存器 Xn 都有一个 32 位视图 Wn。写入 W 寄存器会将映射的 X 寄存器高 32 位清零，因此在 `SUB W5, W8, W4` 之后，X5 的高 32 位包含零<sup>[2](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>。浮点和高级 SIMD 数据使用单独的 128 位寄存器组，可作为 Bx（8 位）、Hx（16 位）等访问，直至 Qx（128 位）；所使用的寄存器名称决定计算的大小<sup>[2](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>。

**程序计数器。** 与 A32 和 T32 中 PC 和 SP 是通用寄存器不同，A64 不将程序计数器暴露为具名寄存器。移除直接 PC 访问简化了编译器处理，使返回预测更容易，并简化了 ABI 规范<sup>[4](https://developer.arm.com/community/arm-community-blogs/b/architectures-and-processors-blog/posts/the-a64-isa-and-compilers)</sup>。

**加载、存储和分支。** 对于标量整数、浮点和 SIMD 寄存器，加载和存储寻址模式在所有大小和符号变体上都是统一的，这简化了编译器的指令选择<sup>[4](https://developer.arm.com/community/arm-community-blogs/b/architectures-and-processors-blog/posts/the-a64-isa-and-compilers)</sup>。除独占和有序访问外，所有加载和存储都支持非对齐地址<sup>[4](https://developer.arm.com/community/arm-community-blogs/b/architectures-and-processors-blog/posts/the-a64-isa-and-compilers)</sup>。条件分支可达 ±1 MB，无条件分支可达 ±128 MB，这些范围足以覆盖几乎任何单个编译单元<sup>[4](https://developer.arm.com/community/arm-community-blogs/b/architectures-and-processors-blog/posts/the-a64-isa-and-compilers)</sup>。

## 从 A32 到 A64 的变化

A64 从 ARMv7 的 A32 和 T32 功能演变而来，旨在提供类似的能力，因此熟悉这些指令集的程序员不会感到太多意外，但 Arm 利用这次重新设计来合理化指令集<sup>[4](https://developer.arm.com/community/arm-community-blogs/b/architectures-and-processors-blog/posts/the-a64-isa-and-compilers)</sup>：

- 不再支持多寄存器加载和存储指令 LDM 和 STM；它们的工作由继承自 Thumb-2 的加载和存储对（LDP/STP）完成<sup>[4](https://developer.arm.com/community/arm-community-blogs/b/architectures-and-processors-blog/posts/the-a64-isa-and-compilers)</sup>。
- 条件执行围绕条件选择与条件比较操作进行了重构。没有与 T32 IT 指令等价的指令，谓词执行（指令根据标志有条件地运行）不再作为一般情况提供<sup>[4](https://developer.arm.com/community/arm-community-blogs/b/architectures-and-processors-blog/posts/the-a64-isa-and-compilers)</sup>。
- CPSR 不再作为单个寄存器存在；新的系统指令访问各个字段<sup>[4](https://developer.arm.com/community/arm-community-blogs/b/architectures-and-processors-blog/posts/the-a64-isa-and-compilers)</sup>。
- 协处理器概念被移除，浮点支持由硬件提供，ABI 中没有“软浮点”选项<sup>[4](https://developer.arm.com/community/arm-community-blogs/b/architectures-and-processors-blog/posts/the-a64-isa-and-compilers)</sup>。
- FP/SIMD 寄存器打包方案被简化，使 D0 映射到 Q0 的下半部分，D1 映射到 Q1 的下半部分，从而增加了向量化机会<sup>[4](https://developer.arm.com/community/arm-community-blogs/b/architectures-and-processors-blog/posts/the-a64-isa-and-compilers)</sup>。

移植相应地很直接：在 Android 的移植中，大约 80% 的代码只需要简单的重新编译，大多数 A32 汇编指令可以轻松映射到 A64<sup>[4](https://developer.arm.com/community/arm-community-blogs/b/architectures-and-processors-blog/posts/the-a64-isa-and-compilers)</sup>。

## 调用约定与 ABI

调用编译器生成代码或被其调用的汇编代码，必须遵循该架构关于调用函数和管理栈的 ABI 规则；不遵循的代码可能行为异常或崩溃<sup>[3](https://developer.apple.com/documentation/xcode/writing-arm64-code-for-apple-platforms?changes=_1)</sup>。对于 AArch64，相关标准是 AAPCS64，它规定了参数传递、返回值处理、寄存器使用和栈布局<sup>[5](https://github.com/ARM-software/abi-aa/blob/main/aapcs64/aapcs64.rst)</sup>。调用 `va_start` 的可变参数函数会将传入的参数寄存器保存到其自身栈帧中的两个保存区，一个用于 64 位通用寄存器 x0–x7，一个用于 128 位 FP/SIMD 寄存器 v0–v7<sup>[5](https://github.com/ARM-software/abi-aa/blob/main/aapcs64/aapcs64.rst)</sup>。

平台供应商在标准之上附加了额外要求。Apple 表示其平台在几个特定方面偏离标准 64 位 ARM 架构，除此之外遵循该规范，并且 Apple 平台上的栈指针遵循 ARM64 标准 ABI 并要求 16 字节对齐<sup>[3](https://developer.apple.com/documentation/xcode/writing-arm64-code-for-apple-platforms?changes=_1)</sup>。

## 汇编器与工具链

有多种汇编器接受 Arm 汇编源代码。Arm 自己的工具链包括 armasm 汇编器，记录在《ARM 编译器 armasm 用户指南》中，涵盖 A32/T32 的 UAL 语法和 A64 汇编<sup>[6](https://documentation-service.arm.com/static/5f3e9263b13d4764d4613b69)</sup>。Microsoft 随 [Visual Studio](https://www.edgepedia.org/zh/visual-studio) 提供自己的 armasm 和 armasm64 汇编器；Microsoft 指出其 armasm 与 Arm 开发者网站上描述的 armasm 不是同一工具<sup>[7](https://learn.microsoft.com/en-us/cpp/assembler/arm/arm-assembler-reference?view=msvc-170)</sup>。在 GNU 和 LLVM 生态系统中，GNU 工具链的 `as` 汇编 Arm 源代码，而在基于 LLVM 的 Arm 嵌入式工具链中，clang 集成汇编器编译 `.s` 和 `.S` 文件；两者在细微语法点上有所不同，例如 Thumb 指令的 `.N` 和 `.W` 后缀以及设置标志指令的 `S` 后缀，不过通常可以编写两者都接受的代码<sup>[8](https://github.com/arm/arm-toolchain/blob/arm-software/arm-software/embedded/docs/migrating.md)</sup>。

每条指令的权威参考是相关架构版本的《Arm 架构参考手册》（Arm ARM），其中给出每条指令的编码、参数、伪代码和限制<sup>[2](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>。Arm 还建议阅读所用特定汇编器随附的文档，因为伪指令等汇编器特定特性因工具而异<sup>[9](https://support.arm.com/documentation/ddi0487/maa/Preface/About-this-Manual?lang=en)</sup>。

## 起源

该汇编语言源自为第一代 Arm 处理器设计的指令集。[Acorn Computers](https://www.edgepedia.org/zh/acorn-computers) 由 [Chris Curry](https://www.edgepedia.org/zh/chris-curry) 和 [Hermann Hauser](https://www.edgepedia.org/zh/hermann-hauser) 于 1978 年创立，在 BBC Micro 项目之后决定为更强大的机器构建自己的处理器<sup>[1](https://newsroom.arm.com/blog/40-year-anniversary-of-arm-architecture)</sup>。该项目于 1983 年 10 月开始，Sophie Wilson 设计指令集，Steve Furber 进行硬件设计，ARM1 于 1985 年 4 月产出可工作的硅片，使用三微米工艺、25,000 个晶体管<sup>[1](https://newsroom.arm.com/blog/40-year-anniversary-of-arm-architecture)</sup>。1987 年的 Acorn Archimedes 是第一台基于 RISC 的家用计算机，1990 年 Arm Ltd 作为 Acorn、Apple 和 VLSI Technology 的合资企业成立<sup>[1](https://newsroom.arm.com/blog/40-year-anniversary-of-arm-architecture)</sup>。近年来该架构每年更新，Armv9-A 为 AI 工作负载增加了可伸缩向量扩展 2（SVE2）和可伸缩矩阵扩展（SME）指令集<sup>[10](https://www.arm.com/architecture/cpu/a-profile/armv9)</sup>。

## References

1. [Celebrating 40 Years of the Arm Architecture: From Cambridge to the World, Arm Newsroom](https://newsroom.arm.com/blog/40-year-anniversary-of-arm-architecture)
2. [Armv8-A Instruction Set Architecture, Learn the Architecture guide, Arm](https://developer.arm.com/-/media/Arm%20Developer%20Community/PDF/Learn%20the%20Architecture/Armv8-A%20Instruction%20Set%20Architecture.pdf?revision=ebf53406-04fd-4c67-a485-1b329febfb3e)
3. [Writing ARM64 code for Apple platforms, Apple Developer Documentation](https://developer.apple.com/documentation/xcode/writing-arm64-code-for-apple-platforms?changes=_1)
4. [The A64 ISA and compilers, Arm Community blog](https://developer.arm.com/community/arm-community-blogs/b/architectures-and-processors-blog/posts/the-a64-isa-and-compilers)
5. [Procedure Call Standard for the Arm 64-bit Architecture (AAPCS64), ARM-software/abi-aa on GitHub](https://github.com/ARM-software/abi-aa/blob/main/aapcs64/aapcs64.rst)
6. [ARM Compiler armasm User Guide, Arm](https://documentation-service.arm.com/static/5f3e9263b13d4764d4613b69)
7. [ARM Assembler reference, Microsoft Learn](https://learn.microsoft.com/en-us/cpp/assembler/arm/arm-assembler-reference?view=msvc-170)
8. [Migrating from Arm GNU Toolchain, arm-toolchain documentation on GitHub](https://github.com/arm/arm-toolchain/blob/arm-software/arm-software/embedded/docs/migrating.md)
9. [Arm Architecture Reference Manual for A-profile architecture, About this Manual, Arm](https://support.arm.com/documentation/ddi0487/maa/Preface/About-this-Manual?lang=en)
10. [Armv9-A CPU Architecture, Arm](https://www.arm.com/architecture/cpu/a-profile/armv9)

---
*Initially written Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 软件与编程 › Programming languages › Individual programming languages

Copyright 2026 Edgepedia

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

Source: https://www.edgepedia.org/zh/arm-assembly-language

English original: https://www.edgepedia.org/arm-assembly-language
