3.1 · Computer architecture
3.1 · 计算机体系结构
Inside the CPU
CPU 内部结构
The components of a Von Neumann processor, the cycle it repeats billions of times a second, what makes one CPU faster than another, and the dedicated processors built into everyday devices.
冯·诺依曼处理器的各个组件、它每秒重复数十亿次的周期、是什么让一个 CPU 比另一个更快,以及内置于日常设备中的专用处理器。
Explainer · 3.1.1
讲解 · 3.1.1
The central processing unit
中央处理器
The CPU takes in the instructions and data given to a computer, processes them, and produces the output. It runs the fetch–decode–execute cycle for every instruction of every program.
CPU接收给予计算机的指令和数据,处理它们,并产生输出。它为每个程序的每一条指令运行取指-译码-执行周期。
A microprocessor is a CPU built as a single integrated circuit on one chip. In a small device the whole processor is one microprocessor.
微处理器是把 CPU 制成一个单独集成电路芯片的产物。在小型设备中,整个处理器就是一个微处理器。
Explainer · 3.1.2(a)
讲解 · 3.1.2(a)
Von Neumann components
冯·诺依曼体系结构组件
A Von Neumann CPU stores programs and data in the same memory. Inside it are two units, five special registers, and three buses.
冯·诺依曼 CPU 把程序和数据存储在同一个存储器中。它内部包含两个单元、五个特殊寄存器和三条总线。
| Part | 组件 | Role | 作用 |
|---|---|---|---|
| ALU (arithmetic logic unit) | ALU(算术逻辑单元) | carries out arithmetic (add, subtract, shift) and logic (AND, OR, NOT) operations | 执行算术运算(加、减、移位)和逻辑运算(与、或、非) |
| CU (control unit) | CU(控制单元) | decodes each instruction and sends control signals along the control bus to coordinate the other components | 译码每一条指令,并沿控制总线发送控制信号,以协调其他组件 |
| PC (program counter) | PC(程序计数器) | holds the address of the next instruction to be fetched | 保存待取指的下一条指令的地址 |
| MAR (memory address register) | MAR(存储器地址寄存器) | holds the address of the memory location being read from or written to | 保存正在被读取或写入的存储单元的地址 |
| MDR (memory data register) | MDR(存储器数据寄存器) | holds the data or instruction just read from that location, or about to be written to it | 保存刚从该位置读取的,或即将写入该位置的数据或指令 |
| CIR (current instruction register) | CIR(当前指令寄存器) | holds the current instruction while it is decoded and executed | 在译码和执行期间保存当前指令 |
| ACC (accumulator) | ACC(累加器) | stores a value during an ALU calculation (it does not do the calculation) | 在 ALU 运算期间保存一个数值(它本身不做运算) |
| Address bus | 地址总线 | carries addresses from the CPU to memory (one direction only) | 将地址从 CPU 传送到存储器(仅单向) |
| Data bus | 数据总线 | carries data and instructions between the CPU and memory (both directions) | 在 CPU 与存储器之间传送数据和指令(双向) |
| Control bus | 控制总线 | carries control and timing signals from the CU (both directions) | 传送来自 CU 的控制与定时信号(双向) |
Two swaps that markers report every series: the MDR does not hold data “from the MAR”, it holds the data found at the address that is in the MAR. And the accumulator does not do calculations, the ALU does; the ACC just holds a value while the ALU works.
考官每一季都会报告两处混淆:MDR 保存的不是"来自 MAR 的数据",而是保存在 MAR 中所存地址处找到的数据。而累加器不做运算,做运算的是 ALU;ACC 只是在 ALU 运算期间保存一个数值。
Try it yourself
动手试试
Explore the CPU
探索 CPU
Click any component to see what it does.
点击任意组件,查看它的作用。
Explainer · 3.1.2(b)
讲解 · 3.1.2(b)
The fetch–decode–execute cycle
取指-译码-执行周期
| Stage | 阶段 | What happens | 发生的过程 |
|---|---|---|---|
| Fetch | 取指 | the address in the PC is copied to the MAR (along the address bus); the instruction at that address is copied from memory into the MDR (along the data bus); the MDR’s contents are copied into the CIR; the PC is incremented by 1 | PC中的地址被复制到MAR(沿地址总线);该地址处的指令从存储器复制到MDR(沿数据总线);MDR 的内容被复制到CIR;PC 加 1 |
| Decode | 译码 | the CU interprets the instruction in the CIR, working out the operation and the data it needs | CU 解读CIR 中的指令,判断出所需的操作及数据 |
| Execute | 执行 | the CU sends control signals along the control bus; the operation is carried out (for a calculation, by the ALU using the ACC) | CU 沿控制总线发送控制信号;操作被执行(若是运算,则由ALU借助ACC完成) |
Asked to describe the decode stage, many candidates describe execute instead. Decode is just: the control unit works out what the instruction in the CIR means. Also, drawing three boxes labelled “fetch”, “decode”, “execute” is not a description, name the registers and buses involved.
被要求描述译码阶段时,许多考生却描述了执行阶段。译码其实很简单:控制单元判断出 CIR 中指令的含义。另外,画三个分别标着"取指""译码""执行"的方框并不算描述,必须点出涉及的具体寄存器和总线。
Try it yourself
动手试试
Step through the FDE cycle
逐步演示取指-译码-执行周期
One instruction, ADD 5, stored at address 64. Step forward and watch the value move between registers, and the buses light up.
一条存储在地址 64 处的指令 ADD 5。逐步前进,观察数值在寄存器之间移动,以及总线随之点亮。
Explainer · 3.1.3
讲解 · 3.1.3
Cores, cache and clock
核心、缓存与时钟
| Factor | 因素 | Effect on performance | 对性能的影响 |
|---|---|---|---|
| Number of cores | 核心数量 | each core is a full ALU, CU and set of registers. More cores lets the CPU work on more instructions at once. But cores must communicate, so doubling the cores does not double the speed | 每个核心都是一整套完整的 ALU、CU 和寄存器组。更多的核心让 CPU 能同时处理更多指令。但核心之间必须相互通信,所以核心数翻倍并不会让速度翻倍 |
| Cache size | 缓存大小 | cache is fast memory inside the CPU. It holds frequently used instructions and data, which the CPU checks before going to the slower RAM. A larger cache means fewer trips to RAM, so faster | 缓存是CPU 内部的高速存储器。它保存经常使用的指令和数据,CPU 在访问较慢的 RAM 之前会先检查缓存。缓存越大,访问 RAM 的次数就越少,速度也就越快 |
| Clock speed | 时钟速度 | the clock produces the timing signal. Its speed, in Hz, is the number of cycles per second (3.5 GHz = 3.5 billion per second). A higher clock speed runs the cycle faster, but too high causes overheating and the CPU becomes unstable | 时钟产生定时信号。它以 Hz 为单位的速度,即每秒周期数(3.5 GHz = 每秒 35 亿次)。更高的时钟速度让周期运行得更快,但过高会导致过热,使 CPU 变得不稳定 |
“3.5 GHz” on its own is not a definition, say 3.5 billion clock cycles per second. When comparing cores, state the direction: more cores gives better performance. And cache holds frequently used data, not just data that was “just used”.
单说"3.5 GHz"并不是一个完整的定义,要说每秒 35 亿次时钟周期。比较核心数时,要说明方向:核心越多,性能越好。而缓存保存的是经常使用的数据,而不仅仅是"刚刚用过"的数据。
Try it yourself
动手试试
Tune the CPU
调节 CPU
Change each factor and see the estimated performance, and what each change costs.
改变每个因素,查看估算的性能,以及每次改动的代价。
Explainer · 3.1.4
讲解 · 3.1.4
Instruction set
指令集
A CPU’s instruction set is the complete list of every command it can carry out, and those commands are in machine code. Each instruction is an opcode (what to do, for example ADD) plus an operand (the data or the register to act on).
CPU 的指令集是它能执行的所有命令的完整列表,这些命令都是机器码。每条指令由一个操作码(要做什么,例如 ADD)加上一个操作数(要作用的数据或寄存器)组成。
“A set of instructions” just repeats the term and earns nothing. The marked point is that it is all the commands a particular CPU is able to process, and that they are machine-code commands, not program-code statements.
"一组指令"只是把术语重复了一遍,得不到任何分数。真正的得分要点是:它是某个特定 CPU 能够处理的全部命令,并且这些命令是机器码命令,而不是程序代码语句。
Explainer · 3.1.5
讲解 · 3.1.5
Embedded systems
嵌入式系统
An embedded system is hardware and software built into a larger device to carry out one dedicated set of functions.
嵌入式系统是内置于更大型设备中的硬件与软件,用于执行一组专用功能。
| Characteristic | 特征 | Detail | 细节 |
|---|---|---|---|
| Dedicated | 专用 | does one fixed task; the program is not meant to be changed by the user | 执行一项固定的任务;程序不打算由用户更改 |
| Small and low cost | 体积小、成本低 | designed to fit inside a device and be cheap to mass-produce | 设计成能装入设备内部,且便于低成本量产 |
| Low power, fast response | 低功耗、响应快 | uses little power and reacts to inputs in real time | 耗电很少,并能实时对输入做出反应 |
| Often no operating system | 通常没有操作系统 | a simple interface, sometimes a single dial or button | 界面简单,有时只是一个旋钮或按钮 |
Found in domestic appliances (washing machines, microwaves), cars (engine management, ABS, airbags), security systems, lighting systems and vending machines.
常见于家用电器(洗衣机、微波炉)、汽车(发动机管理、防抱死系统、安全气囊)、安防系统、照明系统和自动售货机中。
A laptop or PC is not an embedded system: it is general purpose, running many different programs that the user can change. The distinguishing feature of an embedded system is a single dedicated task, not just “being small”.
笔记本电脑或台式机不是嵌入式系统:它是通用型设备,能运行许多用户可自行更改的不同程序。嵌入式系统的区分特征是单一专用任务,而不仅仅是"体积小"。
Try it yourself
动手试试
Embedded or not
是不是嵌入式
Click each device to tag it as an embedded system or a general-purpose computer, then check.
点击每个设备,将其标记为嵌入式系统或通用计算机,然后检查答案。
Check your understanding
检验你的理解
Which register holds the address of the next instruction to be fetched?
哪个寄存器保存下一条待取指令的地址?
Check your understanding
检验你的理解
What happens at the decode stage of the FDE cycle?
取指-译码-执行周期的译码阶段发生了什么?
Check your understanding
检验你的理解
Why is a laptop not an embedded system?
为什么笔记本电脑不是嵌入式系统?
Common mistakes
常见错误
3.1.1 to 3.1.5
考官针对 3.1.1 至 3.1.5 报告了以下模式
RecurringTwo register errors: the MDR is said to hold “the data from the MAR”, when it holds the data found at the address stored in the MAR. And the accumulator is said to “carry out calculations”, when the ALU does that and the ACC only stores a value during the calculation.
反复出现两处寄存器错误:有人说MDR保存"来自 MAR 的数据",而它实际保存的是 MAR 中所存地址处的数据。还有人说累加器"执行运算",而实际执行运算的是ALU,ACC 只是在运算期间保存一个数值。
Asked about the decode stage, candidates describe execute instead, or draw three labelled boxes rather than naming the registers and buses. The CIR is sometimes wrongly said to be part of the ALU.
被问及译码阶段时,考生却描述了执行阶段,或者只画三个带标签的方框,而不点出具体的寄存器和总线。CIR有时会被错误地说成是 ALU 的一部分。
An instruction set is defined vaguely as “a set of instructions”, just repeating the term. It is every command a particular CPU can carry out, in machine code. “3.5 GHz” is quoted without “clock cycles per second”.
指令集被笼统地定义为"一组指令",只是把术语重复了一遍。它其实是某个特定 CPU 能够执行的所有命令,以机器码的形式存在。"3.5 GHz"被引用时,没有加上"每秒时钟周期数"这句话。
On performance, candidates state that it improves without saying which direction (more cores, larger cache, higher clock). On embedded systems, the reason a computer is excluded is given as “it is bigger” rather than “it is multi-functional”.
在性能方面,考生只说性能"提高了",却没有说明朝哪个方向变化(核心更多、缓存更大、时钟更高)。在嵌入式系统方面,把电脑排除在外的原因被说成"它更大",而不是"它具有多种功能"。
Register mix-up: “The address goes into the PC, then into the MDR, and the accumulator adds the numbers.”
寄存器混淆:"地址进入 PC,然后进入 MDR,累加器把数字相加。"
Right: “The address goes from the PC to the MAR. The instruction at that address goes into the MDR, then the CIR. The ALU adds the numbers, storing the result in the accumulator.”
正确:"地址从 PC 传到 MAR。该地址处的指令进入 MDR,再进入 CIR。ALU 把数字相加,并把结果存入累加器。"
Circular: “An instruction set is a set of instructions for the CPU.”
循环定义:"指令集就是给 CPU 用的一组指令。"
Right: “An instruction set is the complete list of all the machine-code commands that a particular CPU is able to process.”
正确:"指令集是某个特定 CPU 能够处理的所有机器码命令的完整列表。"
Revision questions
复习题
Past-paper style. Write an answer, then reveal the marking points and mark yourself.
采用历年真题风格。写下答案,然后展开评分要点给自己打分。
[3]State the purpose of the PC, the MAR and the MDR.
[3]陈述 PC、MAR 和 MDR 各自的用途。
Marking points
评分要点
- PC: holds the address of the next instruction to be fetched.
- MAR: holds the address of the memory location currently being read from or written to.
- MDR: holds the data or instruction read from, or to be written to, that memory location.
- PC:存放下一条待取指令的地址。
- MAR:存放当前正在被读取或写入的内存单元的地址。
- MDR:存放从该内存单元读出的、或将要写入的、数据或指令。
[6]Describe the fetch stage of the fetch–decode–execute cycle, naming the registers and buses used.
[6]描述取指-译码-执行周期中的取指阶段,并点出所使用的寄存器和总线。
Marking points
评分要点
- The address in the PC is copied to the MAR (along the address bus).
- The PC is incremented.
- The address in the MAR is placed on the address bus and a read signal is sent on the control bus.
- The instruction at that address is returned along the data bus into the MDR.
- The instruction is copied from the MDR into the CIR ready to be decoded.
- PC 中的地址被复制到 MAR(经地址总线)。
- PC 加 1。
- MAR 中的地址被放到地址总线上,控制总线上发出读信号。
- 该地址处的指令经数据总线返回,进入 MDR。
- 指令从 MDR 复制到 CIR,准备译码。
[4]Explain how increasing the cache size and the number of cores can improve the performance of a CPU.
[4]解释增加缓存大小和核心数量如何能提升 CPU 的性能。
Marking points
评分要点
- A larger cache holds more frequently used data and instructions close to the CPU, so fewer slow accesses to RAM are needed and instructions complete faster.
- More cores let the CPU execute several instructions at the same time (true parallel processing), so more work is done per second, provided the software is written to use multiple cores.
- 更大的缓存能在 CPU 附近存放更多经常使用的数据和指令,所以访问较慢的 RAM 的次数更少,指令完成得更快。
- 更多的核心让 CPU 同时执行多条指令(真正的并行处理),所以每秒完成的工作更多,前提是软件被写成能利用多核。
[2]State what is meant by the instruction set of a CPU.
[2]陈述 CPU 的指令集是什么意思。
Marking points
评分要点
- The instruction set is the complete list of all the machine-code commands / operations that a particular CPU is able to carry out.
- 指令集是某个特定 CPU 能够执行的所有机器码命令 / 操作的完整列表。
[4]Describe two characteristics of an embedded system, and explain why a desktop computer is not one.
[4]描述嵌入式系统的两个特征,并解释为什么台式电脑不是嵌入式系统。
Marking points
评分要点
- Any two characteristics: dedicated to one specific task; built into a larger device; small, low power, with limited or no user interface; the program is fixed in ROM and not changed by the user.
- Why a desktop is not one: it is general-purpose / multi-functional, running many different programs that the user can install and change.
- 任选两个特征:专用于单一特定任务;内建于更大的设备中;体积小、功耗低、用户界面有限或没有;程序固化在 ROM 中,用户不能更改。
- 为什么台式机不是:它是通用型 / 多功能的,运行许多用户可安装和更改的不同程序。
Flashcards
记忆卡片
Active recall for this subtopic’s key terms.
针对本子主题关键术语的主动回忆练习。
Keep this subtopic’s practice with you
把这个子主题的练习保存下来
Free account: unlock every revision question and flashcard for 3.1, and every other IGCSE 0478 statement.
免费账户:解锁 3.1 以及所有其他 IGCSE 0478 考纲陈述的全部复习题和记忆卡片。