# 哈佛架构

哈佛架构是一种计算机架构，其程序指令和数据分别存放在各自独立的存储器中，各有独立的总线，因此处理器可以同时取指令和访问数据。与之相对的是冯·诺依曼（或称普林斯顿）架构，后者用单一存储器和单一总线同时服务于指令和数据，使得取指令与数据传输在本质上只能串行进行。<sup>[1](https://www.cs.cmu.edu/afs/cs/academic/class/15849c-s02/www/scribe/stanley/index.html)</sup><sup> • </sup><sup>[2](https://blue.cs.sonoma.edu/~bob/IntroCompOrg-x64/bookch1.html)</sup>

| 关键事实 | 详情 |
|---|---|
| 定义性特征 | 程序存储器与数据存储器彼此分离，各自拥有通往CPU的总线<sup>[3](https://www.sciencedirect.com/science/article/pii/B9780122341205500205)</sup> |
| 主要性能优势 | 并行取指令及其操作数，避开冯·诺依曼瓶颈<sup>[3](https://www.sciencedirect.com/science/article/pii/B9780122341205500205)</sup><sup> • </sup><sup>[2](https://blue.cs.sonoma.edu/~bob/IntroCompOrg-x64/bookch1.html)</sup> |
| 字长自由度 | 指令与数据可以采用不同字长；AVR指令宽16位或32位而数据为8位，PIC16F1指令走14位总线而数据总线为8位<sup>[4](https://developerhelp.microchip.com/xwiki/bin/view/products/mcu-mpu/8-bit-avr/structure/memory/)</sup><sup> • </sup><sup>[5](https://skills.microchip.com/introduction-to-the-pic16f1-enhanced-mcu-architecture/691578)</sup> |
| 现代形态 | 改进型哈佛：一级指令缓存与数据缓存分离，由统一的主存储器支撑<sup>[6](https://openocd.org/files/thesis.pdf)</sup><sup> • </sup><sup>[7](https://documentation-service.arm.com/static/684be32a3f793d5d7b223563)</sup> |
| 典型用户 | 微控制器（AVR、PIC）与实时处理器（Cortex-R），这些场合确定性并行访问至关重要<sup>[4](https://developerhelp.microchip.com/xwiki/bin/view/products/mcu-mpu/8-bit-avr/structure/memory/)</sup><sup> • </sup><sup>[7](https://documentation-service.arm.com/static/684be32a3f793d5d7b223563)</sup> |
| 主要缺点 | 若需要虚拟内存则须两套地址转换机制、存储器利用率低、难以支持自修改代码<sup>[3](https://www.sciencedirect.com/science/article/pii/B9780122341205500205)</sup><sup> • </sup><sup>[8](https://lectures.pbl.ee.ethz.ch/embedded-systems/hs22/lec/Embedded_Systems_HS2022_2x2.pdf)</sup> |

## 基本设计

在哈佛机器中，CPU连接着两套独立的存储器系统。每套各有自己的地址总线和数据总线：一条通路从程序存储器运送指令，另一条通路在数据存储器与CPU之间往返运送操作数。<sup>[3](https://www.sciencedirect.com/science/article/pii/B9780122341205500205)</sup>由于两条通路独立运作，一条指令及其操作数可以并行取来，这正是该架构相对于共享总线的冯·诺依曼设计的核心性能优势。<sup>[3](https://www.sciencedirect.com/science/article/pii/B9780122341205500205)</sup>

这种分离还松开了共享存储器所施加的约束。指令字与数据字可以长度不同，寄存器长度也获得灵活性，因为机器的两侧不再需要就单一字格式达成一致。<sup>[3](https://www.sciencedirect.com/science/article/pii/B9780122341205500205)</sup>指令可以驻留在只读存储器中以求保护，而数据则放在可写的RAM里。<sup>[3](https://www.sciencedirect.com/science/article/pii/B9780122341205500205)</sup>

## 与冯·诺依曼架构的对比

冯·诺依曼机器把指令和数据放在一个存储器中，经由一条地址总线和一条数据总线访问。如果一条指令要求读取或写入数据，那么在当前数据传输完成之前，下一条指令无法通过同一条总线取来；这种减速称为冯·诺依曼瓶颈。<sup>[2](https://blue.cs.sonoma.edu/~bob/IntroCompOrg-x64/bookch1.html)</sup>哈佛式安排以更多的总线布线和双份的存储器基础设施为代价，消除了这种争用。<sup>[9](https://d13mk4zmvuctmz.cloudfront.net/assets/main/study-material/notes/electrical-engineering_engineering_microcontroller_introduction_notes.pdf)</sup>

权衡是双向的。冯·诺依曼设计更简单、更灵活，其统一地址空间适合通用计算和虚拟内存。哈佛设计则为它的并行性付出代价：若需要虚拟内存，就得有两套地址转换机制；存储器利用率也差，因为数据存储器中的空闲空间无法用来存放指令，反之亦然。<sup>[3](https://www.sciencedirect.com/science/article/pii/B9780122341205500205)</sup>

## 改进型哈佛架构

实际处理器很少实现严格的原始形态——在那种形态下，数据存储器与指令存储器之间的传输不可能，或只能通过特殊功能实现。<sup>[6](https://openocd.org/files/thesis.pdf)</sup>改进型哈佛架构放宽了这一限制：数据与指令的两套独立存储器系统连接到一个统一存储器，二者共处同一地址空间。<sup>[6](https://openocd.org/files/thesis.pdf)</sup>一种常见的实现方式是把统一RAM在芯片内部分成独立的一级缓存，一个用于指令，一个用于数据。<sup>[10](https://www.think-embedded.com/courses/computer-architecture/chapter1-page4-cpu-memory-io-overview.html)</sup>

**ARM处理器**体现了这一模式。Cortex-R处理器的一级缓存直接连接内核；这些是哈佛缓存，指令与数据各有缓存，背后由一个更大、更慢、统一的二级缓存（通常为256 KB、512 KB或1 MB）支撑，指令与数据都存放在其中。<sup>[7](https://documentation-service.arm.com/static/684be32a3f793d5d7b223563)</sup>在Arm文档撰写之时，16 KB或32 KB的一级缓存容量最为常见，这是在1 GHz或更高的内核速度下能够单周期访问的最大RAM容量。<sup>[7](https://documentation-service.arm.com/static/684be32a3f793d5d7b223563)</sup>

分离的缓存带来了一致性义务。Arm架构定义了一致性点（Point of Coherency），在此所有能访问存储器的代理都看到同一位置的同一副本；还定义了统一性点（Point of Unification），在此内核的指令缓存与数据缓存保证看到同一副本。自修改代码依赖统一性点，通过一个两阶段流程实现：先按地址清理相关的数据缓存条目，再使对应的指令缓存条目失效，同时还要使用内存屏障。<sup>[11](https://support.arm.com/documentation/den0042/0100/Caches/Point-of-coherency-and-unification)</sup>

## 在微控制器中的应用

**AVR。** AVR微控制器采用改进型哈佛架构构建：Flash程序存储器空间位于与SRAM不同的地址总线上，并且有两条数据总线，一条通达所有数据，另一条是专用的输入/输出总线，只能有限访问一小段存储器。<sup>[4](https://developerhelp.microchip.com/xwiki/bin/view/products/mcu-mpu/8-bit-avr/structure/memory/)</sup>CPU利用哈佛式分离来最大化性能与并行度，以单级流水线执行指令：一条指令执行时，下一条已从程序存储器预取，因此每个时钟周期完成一条指令。<sup>[12](https://onlinedocs.microchip.com/oxy/GUID-B990D80E-52D0-4869-8631-E8A045F89631-en-US-4/GUID-F9B6741C-7F50-477E-81A8-5423F10CD41A.html)</sup>所有AVR指令宽16位或32位，而工作寄存器为8位，这种不对称由分离的总线直接容纳。<sup>[4](https://developerhelp.microchip.com/xwiki/bin/view/products/mcu-mpu/8-bit-avr/structure/memory/)</sup>Flash例如组织为32K×16，典型耐久度至少为10,000次写/擦除循环，独立的EEPROM数据空间则至少为100,000次。<sup>[4](https://developerhelp.microchip.com/xwiki/bin/view/products/mcu-mpu/8-bit-avr/structure/memory/)</sup>由于程序空间与数据空间彼此不同，Flash中的常量表要用专用的加载程序存储器（LPM）指令读取，而非普通的加载指令。<sup>[4](https://developerhelp.microchip.com/xwiki/bin/view/products/mcu-mpu/8-bit-avr/structure/memory/)</sup>

**PIC。** Microchip PIC16F1增强型架构同样通过14位指令总线把指令从Flash程序存储器送入ALU，同时一条8位数据总线连接ALU与数据存储器。<sup>[5](https://skills.microchip.com/introduction-to-the-pic16f1-enhanced-mcu-architecture/691578)</sup>

## 安全影响

这种分离并非绝对的保护。研究人员已经展示了如何利用程序漏洞，向基于Atmel AVR的传感器节点的程序存储器中永久注入任意代码，表明哈佛架构设备可以经由其更新与程序存储器机制、而非数据存储器遭到攻击。<sup>[13](https://arxiv.org/abs/0901.3482)</sup>

同样的分离也限制了合法的代码操作。纯哈佛机器无法处理自修改代码，因为指令不能通过数据通路写入。<sup>[8](https://lectures.pbl.ee.ethz.ch/embedded-systems/hs22/lec/Embedded_Systems_HS2022_2x2.pdf)</sup>改进型哈佛设计则通过上文所述的缓存维护序列恢复了这一能力。<sup>[11](https://support.arm.com/documentation/den0042/0100/Caches/Point-of-coherency-and-unification)</sup>

## 名称的由来

这一术语来自哈佛大学建造的早期计算机。[哈佛马克一号](https://www.edgepedia.org/zh/harvard-mark-i)（Harvard Mark I）由研究生霍华德·艾肯（Howard Aiken）于1937年设计，1944年开始运行，它从打孔纸带读取指令，其存储计数器充当存储器，打孔卡片用于输入题目和接收输出。<sup>[14](https://news.harvard.edu/gazette/story/2021/07/harvards-mark-1-finds-its-new-home/)</sup><sup> • </sup><sup>[15](https://news.harvard.edu/gazette/story/2025/08/turning-information-into-something-physical/)</sup><sup> • </sup><sup>[17](https://chsi.harvard.edu/harvard-ibm-mark-1-function)</sup>

## References

1. [CS849C Lecture 2, Carnegie Mellon University](https://www.cs.cmu.edu/afs/cs/academic/class/15849c-s02/www/scribe/stanley/index.html)
2. [Introduction to Computer Organization, Chapter 1 (Sonoma State University)](https://blue.cs.sonoma.edu/~bob/IntroCompOrg-x64/bookch1.html)
3. [Harvard Architectures, VLSI Electronics Microstructure Science, Volume 20 (1989), ScienceDirect](https://www.sciencedirect.com/science/article/pii/B9780122341205500205)
4. [AVR Memory, Microchip Developer Help](https://developerhelp.microchip.com/xwiki/bin/view/products/mcu-mpu/8-bit-avr/structure/memory/)
5. [Introduction to the PIC16F1 Enhanced MCU Architecture, Microchip](https://skills.microchip.com/introduction-to-the-pic16f1-enhanced-mcu-architecture/691578)
6. [Wetzels, M., MSc thesis, Eindhoven University of Technology](https://openocd.org/files/thesis.pdf)
7. [ARM Cortex-R Series (Armv7-R) Programmer's Guide, Arm](https://documentation-service.arm.com/static/684be32a3f793d5d7b223563)
8. [Embedded Systems lecture notes, ETH Zurich (HS2022)](https://lectures.pbl.ee.ethz.ch/embedded-systems/hs22/lec/Embedded_Systems_HS2022_2x2.pdf)
9. [Microcontroller introduction notes](https://d13mk4zmvuctmz.cloudfront.net/assets/main/study-material/notes/electrical-engineering_engineering_microcontroller_introduction_notes.pdf)
10. [Think-Embedded, Chapter 1.4: Optimizing the System](https://www.think-embedded.com/courses/computer-architecture/chapter1-page4-cpu-memory-io-overview.html)
11. [Point of coherency and unification, Arm Cortex-R Programmer's Guide](https://support.arm.com/documentation/den0042/0100/Caches/Point-of-coherency-and-unification)
12. [AVR Architecture section 9.3, Microchip online documentation](https://onlinedocs.microchip.com/oxy/GUID-B990D80E-52D0-4869-8631-E8A045F89631-en-US-4/GUID-F9B6741C-7F50-477E-81A8-5423F10CD41A.html)
13. [Code injection attacks on harvard-architecture devices, arXiv:0901.3482](https://arxiv.org/abs/0901.3482)
14. [Harvard's Mark 1 finds its new home, Harvard Gazette (2021)](https://news.harvard.edu/gazette/story/2021/07/harvards-mark-1-finds-its-new-home/)
15. [Turning information into something physical, Harvard Gazette (2025)](https://news.harvard.edu/gazette/story/2025/08/turning-information-into-something-physical/)
16. [Harvard Mark III magnetic head, Computer History Museum](https://www.computerhistory.org/revolution/birth-of-the-computer/4/86/353)
17. [Harvard Ibm Mark 1 Function, chsi.harvard.edu](https://chsi.harvard.edu/harvard-ibm-mark-1-function)

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

Topic: 技术与人造世界 › 计算技术与数字系统 › 计算机硬件 › Processors & processor engineering › Computer architecture theory › Computer architecture (overview)

Copyright 2026 Edgepedia

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

Source: https://www.edgepedia.org/zh/harvard-architecture

English original: https://www.edgepedia.org/harvard-architecture
