| Candidates should be able to: | Notes and guidance |
|---|---|
| Show understanding of the basic Von Neumann model for a computer system and the stored program concept | |
| Show understanding of the purpose and role of registers, including the difference between general purpose and special purpose registers | Special purpose registers including: • Program Counter (PC) • Memory Data Register (MDR) • Memory Address Register (MAR) • The Accumulator (ACC) • Index Register (IX) • Current Instruction Register (CIR) • Status Register |
| Show understanding of the purpose and roles of the Arithmetic and Logic Unit (ALU), Control Unit (CU) and system clock, Immediate Access Store (IAS) | |
| Show understanding of how data are transferred between various components of the computer system using the address bus, data bus and control bus | |
| Show understanding of how factors contribute to the performance of the computer system | Including: • processor type and number of cores • the bus width • clock speed • cache memory |
| Understand how different ports provide connection to peripheral devices | Including connection to: • Universal Serial Bus (USB) • High Definition Multimedia Interface (HDMI) • Video Graphics Array (VGA) |
| Describe the stages of the Fetch-Execute (F-E) cycle | Describe and use 'register transfer' notation to describe the F-E cycle |
| Show understanding of the purpose of interrupts | Including: • possible causes of interrupts • applications of interrupts • use of an Interrupt Service Routine (ISR) • when interrupts are detected during the fetch-execute cycle • how interrupts are handled |
处理器基础
A-Level 计算机科学 · 第 4 主题
4.1
中央处理器(CPU)体系结构
大纲
来源:剑桥国际大纲
冯·诺依曼体系结构(Von Neumann architecture)是几乎每一台通用计算机的基础:
- 一个单一存储器——立即存取存储器(Immediate Access Store,IAS)——同时容纳程序指令和数据(存储程序(stored program)概念)。
- 一个处理器(processor,CPU)从存储器取指令并一次运行一条。
- 除非一个分支改变流程,指令按顺序运行。
存储程序的想法就是使一台计算机灵活的东西:改变程序,你就改变它所做的事,不用重新布线。
Tap the parts of a Von Neumann computer
Explore each block. The CPU (control unit, ALU, registers) talks to a single main memory over the buses — and that one shared memory for instructions AND data is the Von Neumann idea.
| 英文 | 中文 | 拼音 |
|---|---|---|
| Von Neumann architecture | 冯·诺依曼体系结构 | féng · nuò yī màn tǐ xì jié gòu |
| stored program | 存储程序 | cún chǔ chéng xù |
| processor | 处理器 | chǔ lǐ qì |
| arithmetic and logic unit | 算术逻辑单元 | suàn shù luó jí dān yuán |
| Immediate Access Store | 立即存取存储器 | lì jí cún qǔ cún chǔ qì |
4.1
CPU 的主要部件
所有这些部件都位于一个小芯片内。本节后面的图显示它们如何连接;下面的照片显示实物。


算术逻辑单元(ALU)
ALU(算术逻辑单元)做算术(加、减……)和逻辑(AND、OR、比较)。它从寄存器(registers)取操作数,并把结果放回一个寄存器。
控制单元(CU)
控制单元(control unit)译码每条指令,并发送控制信号来执行它——打开数据通路、告诉 ALU 做什么,以及控制存储器读和写。
系统时钟
时钟发送一串稳定的脉冲,使 CPU 保持同步。每条指令占固定数目的周期,时钟频率(clock speed,例如 3.8 GHz)是性能的一个因素。
寄存器
寄存器是 CPU 内微小、非常快的存储。专用寄存器(special purpose registers)各在周期中有一个固定的工作:
- 程序计数器(Program Counter,PC)——下一条指令的地址。
- 内存地址寄存器(Memory Address Register,MAR)——正在读或写的地址。
- 内存数据寄存器(Memory Data Register,MDR)——正在往存储器去或从存储器来的数据。
- 当前指令寄存器(Current Instruction Register,CIR)——正在译码的指令。
- 累加器(Accumulator,ACC)——ALU 正在处理的值。
- 状态寄存器(Status Register)——容纳分支所用的标志(flags,进位、零、负、溢出)。
- 变址寄存器(Index Register)——变址寻址中所用的一个偏移量。
通用寄存器(general-purpose registers)由程序员用于计算过程中的临时值。寄存器与存储器之间的数据移动用寄存器传送(register transfer)记法写——例如 MAR ← [PC]("把 PC 的内容复制到 MAR")。

| 英文 | 中文 | 拼音 |
|---|---|---|
| register | 寄存器 | jì cún qì |
| control unit | 控制单元 | kòng zhì dān yuán |
| clock speed | 时钟频率 | shí zhōng pín lǜ |
| Program Counter | 程序计数器 | chéng xù jì shù qì |
| Memory Address Register | 内存地址寄存器 | nèi cún dì zhǐ jì cún qì |
| Memory Data Register | 内存数据寄存器 | nèi cún shù jù jì cún qì |
| Current Instruction Register | 当前指令寄存器 | dāng qián zhǐ lìng jì cún qì |
| Accumulator | 累加器 | lěi jiā qì |
| Status Register | 状态寄存器 | zhuàng tài jì cún qì |
| flags | 标志 | biāo zhì |
| Index Register | 变址寄存器 | biàn zhǐ jì cún qì |
| general-purpose registers | 通用寄存器 | tōng yòng jì cún qì |
| special purpose registers | 专用寄存器 | zhuān yòng jì cún qì |
| register transfer | 寄存器传送 | jì cún qì chuán sòng |
4.1
总线
三条内部总线(buses,一组组并行导线)连接各部件:
- 地址总线(address bus)——传送存储器地址。单向(CPU → 存储器)。
- 数据总线(data bus)——传送数据。双向。
- 控制总线(control bus)——传送控制信号(读、写、中断)。双向。
一条 $n$ 位地址总线能到达 $2^{n}$ 个存储单元。数据总线宽度决定每次访问移动多少位(常常是字长)。

| 英文 | 中文 | 拼音 |
|---|---|---|
| buses | 总线 | zǒng xiàn |
| address bus | 地址总线 | dì zhǐ zǒng xiàn |
| data bus | 数据总线 | shù jù zǒng xiàn |
| control bus | 控制总线 | kòng zhì zǒng xiàn |
4.1
影响性能的因素
- 时钟频率——每秒更多的周期。
- 核心数(cores)——一个多核 CPU 一次运行几个线程。
- 字长(word size)——一个 64 位 CPU 每周期处理 64 位块,并能寻址比一个 32 位的多得多的存储器。
- RAM 数量(随机存取存储器)——更多的 RAM 容纳更多的工作集;太少迫使操作系统页(page)到磁盘。
- 高速缓存(cache memory)大小——更多的高速缓存减少平均存储器访问时间。
- 辅助存储器(secondary storage)类型——一个 SSD 加载程序比一个 HDD 快得多。
- 总线宽度和速度——更宽/更快的总线更快地移动数据。
使规格与工作负载匹配:一个四核在并行工作上胜过一个双核,但更高的每核速度在单线程工作上胜出。
| 英文 | 中文 | 拼音 |
|---|---|---|
| cores | 核心 | hé xīn |
| word size | 字长 | zì zhǎng |
| RAM | 随机存取存储器 | suí jī cún qǔ cún chǔ qì |
| page | 页 | yè |
| secondary storage | 辅助存储器 | fǔ zhù cún chǔ qì |
| cache memory | 高速缓存 | gāo sù huǎn cún |
4.1
端口
一个端口(port)是一个用于连接外围设备(peripheral)的物理插座:
- USB(通用串行总线)——通用(键盘、驱动器、手机)。
- HDMI(高清多媒体接口)——向一个屏幕的数字视频和音频。
- VGA(视频图形阵列)——向一个显示器的较老的模拟视频输出。
- Ethernet(RJ-45)——有线 LAN。音频插孔——耳机/麦克风。
不同的端口用不同的信号,所以一根 HDMI 电缆不会装进一个 USB 插座。USB-C 不寻常,它携带视频、数据和电力。
| 英文 | 中文 | 拼音 |
|---|---|---|
| port | 端口 | duān kǒu |
| peripheral | 外围设备 | wài wéi shè bèi |
4.1
取指-执行周期
CPU 重复取指-执行周期(fetch-execute cycle),每条机器指令运行一次。
取指
- PC 的地址被复制到 MAR。
- PC 被递增以指向下一条指令。
- 一个读信号经控制总线传送。
- 存储器把指令放到数据总线上。
- 它被复制到 MDR,然后到 CIR。

译码
CU 译码 CIR 中的指令——什么运算,以及哪些操作数或地址。
执行
CU 执行它:算术/逻辑去 ALU(结果到 ACC);一个加载/存储在存储器和一个寄存器之间移动数据;一个分支改变 PC。然后周期重复。

The fetch-execute cycle
Tap round the loop the CPU repeats billions of times a second. Watch how fetch uses the PC/MAR/MDR/CIR registers, then decode and execute act on what was fetched.
The fetch–execute cycle
Step through how the CPU runs one instruction — fetch it from memory, decode it, then execute it, over and over.
| 英文 | 中文 | 拼音 |
|---|---|---|
| fetch-execute cycle | 取指-执行周期 | qǔ zhǐ - zhí xíng zhōu qī |
4.1
中断
一个中断(interrupt)是一个暂停正常周期的信号,以便 CPU 能处理一个紧急事件(一次按键、一个数据包到达、一个硬件故障、除以零、操作系统计时器)。
处理一个:
- 完成当前指令。
- 保存状态(PC 和寄存器)。
- 把中断服务程序(interrupt service routine,ISR)的地址加载到 PC 并运行它。
- ISR 处理事件。
- 恢复保存的状态并继续。
中断让系统及时响应,而 CPU 不用不断检查设备,并且这是操作系统多任务的方式。

| 英文 | 中文 | 拼音 |
|---|---|---|
| interrupt | 中断 | zhōng duàn |
| interrupt service routine | 中断服务程序 | zhōng duàn fú wù chéng xù |
4.2
汇编语言
大纲
| Candidates should be able to: | Notes and guidance |
|---|---|
| Show understanding of the relationship between assembly language and machine code | |
| Describe the different stages of the assembly process for a two-pass assembler | Apply the two-pass assembler process to a given simple assembly language program |
| Trace a given simple assembly language program | |
| Show understanding that a set of instructions are grouped | Including the following groups: • Data movement • Input and output of data • Arithmetic operations • Unconditional and conditional instructions • Compare instructions |
| Show understanding of and be able to use different modes of addressing | Including immediate, direct, indirect, indexed, relative |
来源:剑桥国际大纲
CPU 实际运行机器码(machine code)——位模式,专属于一个体系结构。汇编语言(assembly language)是一种可读的形式,每条机器指令一条指令,用像 LDD、ADD、JMP 这样的助记符(mnemonics)书写。一个汇编器(assembler)把它翻译成机器码。

两遍汇编器
一个两遍汇编器读源两次:
- 第一遍构建一个符号表(symbol table):每当一个标签(label,如
LOOP:)出现时,记录它的地址;还不生成代码。 - 第二遍生成代码:翻译每条指令,当一条引用一个标签(如
JMP LOOP)时,在符号表中查找它的地址。
两遍处理前向引用(forward references,一个跳到后面定义的标签的跳转)。
示例指令集
剑桥用一个小的通用集:数据移动(LDD、LDM、LDI、LDX、STO、MOV)、算术(ADD、SUB、INC、DEC)、逻辑/位(AND、OR、XOR、LSL、LSR)、比较和分支(CMP、JMP、JPE、JPN)、I/O(IN、OUT),以及 END。确切的助记符在试卷的参考表中给出。
How a two-pass assembler works
Step through it. The assembler reads your code twice: pass 1 just finds where every label lives, so pass 2 can fill in the addresses — that is how a jump to a label defined later still works.
| 英文 | 中文 | 拼音 |
|---|---|---|
| machine code | 机器码 | jī qì mǎ |
| assembly language | 汇编语言 | huì biān yǔ yán |
| mnemonics | 助记符 | zhù jì fú |
| assembler | 汇编器 | huì biān qì |
| symbol table | 符号表 | fú hào biǎo |
| label | 标签 | biāo qiān |
| forward references | 前向引用 | qián xiàng yǐn yòng |
4.2
寻址方式
寻址方式(addressing mode)说明 CPU 如何找到操作数:
- 立即寻址(immediate addressing)——操作数是指令中的值。
LDM #10加载 10。 - 直接寻址(direct addressing)——指令容纳一个地址;操作数是那里的值。
LDD 200。 - 间接寻址(indirect addressing)——指令容纳一个地址,它容纳另一个地址,那才是数据。
LDI 200。 - 变址寻址(indexed addressing)——有效地址是
address + index register;用于数组。LDX 100且 IR = 5 读地址 105。
(相对寻址(relative addressing)把地址作为从 PC 起的一个偏移量给出——用于跳转。)

例题。 内存中:地址 200 存放 250,地址 250 存放 99,地址 105 存放 7。变址寄存器中是 5。分别执行 LDM #200、LDD 200、LDI 200 和 LDX 100 之后,累加器中各是什么?跟着每种寻址方式要找多远来看。LDM #200 是立即寻址 - 操作数就是指令中写的那个数,所以累加器中是 200。LDD 200 是直接寻址 - 去地址 200 取出其中的内容:250。LDI 200 是间接寻址 - 地址 200 中存的是 250,那是另一个地址,所以继续去地址 250:99。LDX 100 是变址寻址 - 把变址寄存器加到地址上,$100 + 5 = 105$,再读地址 105:7。用"跳几次"来区分它们:立即 0 次,直接 1 次,间接 2 次,变址 1 次(在加上变址值之后)。
| 英文 | 中文 | 拼音 |
|---|---|---|
| addressing mode | 寻址方式 | xún zhǐ fāng shì |
| immediate addressing | 立即寻址 | lì jí xún zhǐ |
| direct addressing | 直接寻址 | zhí jiē xún zhǐ |
| indirect addressing | 间接寻址 | jiàn jiē xún zhǐ |
| indexed addressing | 变址寻址 | biàn zhǐ xún zhǐ |
| relative addressing | 相对寻址 | xiāng duì xún zhǐ |
4.2
跟踪汇编程序
要跟踪它:做一个表,列有 PC、ACC、变址寄存器、每个变量和任何标志。逐条走过指令,每条之后更新表;当分支改变 PC 时跟随它们;在 END 停止。一个常见模式是用变址寻址在一个数组上循环。
4.3
位操作
大纲
| Candidates should be able to: | Notes and guidance |
|---|---|
| Show understanding of and perform binary shifts | Logical, arithmetic and cyclic Left shift, right shift |
| Show understanding of how bit manipulation can be used to monitor/control a device | Carry out bit manipulation operations Test and set a bit (using bit masking) |
| Instruction Label | Opcode | Operand | Explanation |
| AND #n / Bn / &n | Bitwise AND operation of the contents of ACC with the operand |
| AND | Bitwise AND operation of the contents of ACC with the contents of |
| XOR #n / Bn / &n | Bitwise XOR operation of the contents of ACC with the operand |
| XOR | Bitwise XOR operation of the contents of ACC with the contents of |
| OR #n / Bn / &n | Bitwise OR operation of the contents of ACC with the operand |
| OR | Bitwise OR operation of the contents of ACC with the contents of |
| LSL #n | Bits in ACC are shifted logically n places to the left. Zeros are introduced on the right hand end |
| LSR #n | Bits in ACC are shifted logically n places to the right. Zeros are introduced on the left hand end |
| Labels an instruction | |
| Gives a symbolic address | |
| All questions will assume there is only one general purpose register available (Accumulator) ACC denotes Accumulator IX denotes Index Register can be an absolute or symbolic address # denotes a denary number, e.g. #123 B denotes a binary number, e.g. B01001010 & denotes a hexadecimal number, e.g. &4A |
来源:剑桥国际大纲
一个逻辑移位(logical shift)把所有位向左或向右移若干位,用 0 填充新位置。
- 左移 1(
LSL #1)——位向左移,一个 0 从右边进入;对一个无符号数这是 × 2。 - 右移 1(
LSR #1)——位向右移,一个 0 从左边进入;对一个无符号数这是整数 ÷ 2。
移 $n$ 位乘以或除以 $2^{n}$。例子:00001011(11)LSL #1 → 00010110(22)。
一个算术右移保留符号位,使一个负的有符号数保持为负。一个循环移位(cyclic shift,旋转)把从一端掉出的位从另一端送回,所以没有位丢失。

用于监控/控制的位操作
嵌入式设备常常每个信号用一个寄存器位(bit)(例如位 $n$ = LED $n$)。用一个掩码(mask)——位掩码——你可以:
- 置位 $n$:
R = R OR一个位 $n$ 置位的掩码。 - 清位 $n$:
R = R AND一个位 $n$ 清零而其余置位的掩码。 - 翻转位 $n$:
R = R XOR一个位 $n$ 置位的掩码。 - 测试位 $n$:
R AND掩码,然后检查结果是否非零。

位操作快、用很少的存储器,并让一个字节容纳至多 8 个开/关状态。
Shift and mask the bits of a byte
Pick an operator and watch each result bit. A left shift (<<) moves every bit up one place (×2); a right shift (>>) moves them down (÷2); AND with a mask clears the bits you don't want.
| 英文 | 中文 | 拼音 |
|---|---|---|
| logical shift | 逻辑移位 | luó jí yí wèi |
| mask | 掩码 | yǎn mǎ |
| bit | 位 | wèi |
| cyclic shift | 循环移位 | xún huán yí wèi |
4.3
考试技巧
- 用寄存器传送术语(PC、MAR、MDR、CIR、ACC)学取指-执行周期,以及什么递增 PC。
- 说出每个寄存器的工作;地址总线是单向的,数据总线是双向的。
- 区分寻址方式(立即、直接、间接、变址)——一个常见的题目。
- 解释时钟频率、核心数、高速缓存大小和字长如何影响性能。
- 对于一个二进制移位,说明它是逻辑的还是算术的;左移乘以 2,右移除以 2。
本主题的互动课程
逐步学习,并即时检测练习。