跳到主要内容

A.1 · 计算机基础

IB 计算机科学 HL · 知识点 1

本主题的视频课程 打开视频页面
8:58

计算机基础

你轻触一个照片应用。在一秒钟内,其代码从存储被复制到内存,处理器运行数百万条指令,图形芯片绘制出……

英文讲解 · 可切换中英文字幕

1.1

范围与先修条件

English

This handout teaches Theme A1, Computer fundamentals, for the course first assessed in 2027: hardware, data representation, logic and operating systems. Sections marked AHL are for Higher Level only.

Prerequisites: powers of 2 ($2^{10} = 1024$) and simple arithmetic.

1.2

计算机硬件

English

What happens when you tap an app?

You tap a photo app. Within a second its code is copied from storage into memory, the processor runs millions of instructions, the graphics chip draws the picture, and the operating system shares the processor with the music still playing. This handout follows that path.

A motherboard seen from above: the CPU socket, memory slots and expansion slots joined by dense printed tracks
A motherboard: the CPU, memory and I/O all sit on one set of buses — the printed tracks running between them

The central processing unit

The central processing unit 中央处理器 (CPU) runs program instructions. Its main parts are:

Part Job
control unit 控制单元 (CU) fetches and decodes instructions, and sends control signals to the other parts
arithmetic logic unit 算术逻辑单元 (ALU) does arithmetic (add, subtract) and logic (AND, compare)
registers 寄存器 tiny, very fast stores inside the CPU
The CPU contains the control unit, the ALU and the registers PC, MAR, MDR, CIR and ACC; it is joined to main memory by the address bus (one way, CPU to memory), the data bus (both ways) and the control bus (both ways)
The CPU and main memory, joined by three buses
Register Holds
program counter (PC) the address of the next instruction
memory address register (MAR) the address being read or written
memory data register (MDR) the data or instruction just read, or about to be written
current instruction register (CIR) the instruction being decoded and executed
accumulator (ACC) the result of the last ALU operation

The CPU is joined to memory by buses 总线, sets of parallel wires: the address bus carries addresses from the CPU to memory, the data bus carries data both ways, and the control bus carries signals such as "read" and "write".

The fetch–decode–execute cycle

Fetch: copy the next instruction from memory, then PC + 1; Decode: the control unit works out what the instruction means; Execute: carry it out, the ALU may calculate and the result goes to ACC; the cycle repeats millions of times each second
The cycle every CPU repeats
  1. Fetch: the address in the PC is copied to the MAR; the instruction at that address travels on the data bus to the MDR, then to the CIR. The PC is increased by 1.
  2. Decode: the CU works out what the instruction in the CIR means.
  3. Execute: the instruction is carried out, for example the ALU adds and the result goes into the ACC.

The clock speed 时钟频率 is the number of cycles per second: a 3 GHz CPU has $3 \times 10^9$ clock ticks per second. Performance also depends on the number of cores 核心 (each core runs its own instructions at the same time) and on the size of the cache.

CPU and GPU

A graphics processing unit 图形处理器 (GPU) has thousands of simple cores that do the same operation on many pieces of data at once.

CPU GPU
cores few, powerful thousands, simple
good at varied tasks with many decisions the same calculation on lots of data
uses running the OS and apps graphics, video, machine-learning training

The CPU and GPU work together: the CPU runs the program and hands the parallel work, such as drawing each pixel, to the GPU.

Memory and storage

Type Volatile? Use
RAM 随机存取存储器 yes: loses its data without power the programs and data in use now
ROM 只读存储器 no the start-up instructions (firmware)
cache 高速缓存 yes copies of the data the CPU uses most, inside or next to the CPU
A pyramid: registers at the top, then cache, then RAM (main memory), then secondary storage at the base; towards the top is faster and smaller, towards the base is slower and larger
The memory hierarchy: each level trades speed for size and cost

Cache works because programs reuse the same data and instructions again and again. Level 1 cache is the smallest and fastest; levels 2 and 3 are larger and slower, but all are faster than RAM. A cache hit finds the data in cache; a cache miss must fetch it from RAM.

Secondary storage 辅助存储器 keeps data without power:

Type How it stores bits Strengths Weaknesses
hard disk (HDD) magnetised spots on spinning platters cheap per gigabyte moving parts, slower
solid state (SSD) electric charge in flash memory fast, silent, robust dearer per gigabyte
optical (DVD) pits read by a laser cheap to distribute small, slow

Compression

Compression 压缩 makes files smaller, so they take less storage and transfer faster.

  • Lossless 无损: the original can be rebuilt exactly. Needed for text and program files. Example, run-length encoding (RLE): WWWWWBBBWW becomes 5W3B2W.
  • Lossy 有损: removes detail people are unlikely to notice; the original cannot be rebuilt. Used for photos (JPEG), music (MP3) and video.

Cloud computing

Cloud computing 云计算 provides computing resources over the internet, paid for as they are used.

Service The provider supplies Example
SaaS (software as a service) a finished application web e-mail, online office apps
PaaS (platform as a service) a platform to build and run your own apps a hosted database and web server
IaaS (infrastructure as a service) virtual machines, storage and networks renting servers by the hour

Advantages: no hardware to buy, scales up and down, accessible anywhere. Disadvantages: needs a reliable connection, ongoing costs, and the data is held by another company.

词汇 训练
English 中文 拼音
central processing unit/ˈsentrəl ˈprəʊsesɪŋ ˈjuːnɪt/ 中央处理器 zhōng yāng chǔ lǐ qì
control unit/kənˈtrəʊl ˈjuːnɪt/ 控制单元 kòng zhì dān yuán
arithmetic logic unit/əˈrɪθmətɪk ˈlɒdʒɪk ˈjuːnɪt/ 算术逻辑单元 suàn shù luó jí dān yuán
register/ˈredʒɪstə/ 寄存器 jì cún qì
bus/bʌs/ 总线 zǒng xiàn
clock speed/klɒk spiːd/ 时钟频率 shí zhōng pín lǜ
core/kɔː/ 核心 hé xīn
graphics processing unit/ˈɡræfɪks ˈprəʊsesɪŋ ˈjuːnɪt/ 图形处理器 tú xíng chǔ lǐ qì
RAM/ræm/ 随机存取存储器 suí jī cún qǔ cún chǔ qì
ROM/rɒm/ 只读存储器 zhǐ dú cún chǔ qì
cache/kæʃ/ 高速缓存 gāo sù huǎn cún
secondary storage/ˈsekəndəri ˈstɔːrɪdʒ/ 辅助存储器 fǔ zhù cún chǔ qì
compression/kəmˈpreʃn/ 压缩 yā suō
lossless/ˈlɒsləs/ 无损 wú sǔn
lossy/ˈlɒsi/ 有损 yǒu sǔn
cloud computing/klaʊd kəmˈpjuːtɪŋ/ 云计算 yún jì suàn
1.3

数据表示

English

Binary and hexadecimal

Computers store everything as binary 二进制 digits, bits 位, each 0 or 1. Eight bits make a byte 字节.

A single-digit seven-segment LED display component, showing its seven separate bars
A seven-segment display shows one denary digit, often driven by BCD
A byte splits into two nibbles; each nibble is one hexadecimal digit
A byte splits into two nibbles, and each nibble is one hex digit: 1010 1111 = AF
Place value 128 64 32 16 8 4 2 1
bits of 182 1 0 1 1 0 1 1 0

$128 + 32 + 16 + 4 + 2 = 182$. With $n$ bits there are $2^n$ different values: 8 bits store 0 to 255.

Hexadecimal 十六进制 (base 16) uses the digits 0–9 and A–F (10–15). Each hex digit stands for exactly 4 bits, so hex is a short, readable way to write binary: 1011 0110 is B6, and $11 \times 16 + 6 = 182$. Hex is used for colour codes (#FF8800) and memory addresses.

Unit Size
kibibyte (KiB) $2^{10} = 1024$ bytes
kilobyte (kB) 1000 bytes
megabyte (MB) $10^6$ bytes
gigabyte (GB) $10^9$ bytes

Negative numbers

Two's complement 补码 stores negative integers: the leftmost bit has a negative place value ($-128$ in 8 bits). To write $-42$: write 42 as 00101010, flip every bit to 11010101, then add 1: 11010110. Check: $-128 + 64 + 16 + 4 + 2 = -42$. Eight bits store $-128$ to $127$.

Text, images and sound

  • Text: each character has a code. ASCII uses 7 bits (128 characters, English only); Unicode 统一码 assigns code points to characters and symbols, including Chinese; encodings such as UTF-8, UTF-16 and UTF-32 store those code points using different code-unit sequences.
  • Images: a bitmap is a grid of pixels 像素; the colour depth 色深 is the number of bits per pixel. File size in bits = width × height × colour depth.
  • Sound: the wave is measured at regular intervals. The sample rate 采样率 is samples per second; the bit depth is bits per sample. Size in bits = sample rate × bit depth × channels × seconds.
A 6 by 4 grid of pixels with its width and height labelled; pixels = 6 times 4 = 24, and at 8 bits per pixel the size = 24 times 8 = 192 bits
The same formula on small numbers: count the pixels, then multiply by the colour depth

Worked examples:

$$\text{image size} = \text{width} \times \text{height} \times \text{colour depth}$$
$$1920 \times 1080 \times 24 = 49\,766\,400 \text{ bits} = 6\,220\,800 \text{ bytes} \approx 6.2 \text{ MB}$$
$$\text{sound size} = \text{sample rate} \times \text{bit depth} \times \text{channels} \times \text{time}$$
$$44\,100 \times 16 \times 2 \times 60 = 84\,672\,000 \text{ bits} = 10\,584\,000 \text{ bytes} \approx 10.6 \text{ MB}$$

A higher sample rate, bit depth or colour depth gives better quality and a bigger file.

词汇 训练
English 中文 拼音
binary/ˈbaɪnəri/ 二进制 èr jìn zhì
bit/bɪt/ 位 wèi
byte/baɪt/ 字节 zì jié
hexadecimal/ˌheksəˈdesɪml/ 十六进制 shí liù jìn zhì
two's complement/tuːz ˈkɒmplɪmənt/ 补码 bǔ mǎ
Unicode/ˈjuːnɪkəʊd/ 统一码 tǒng yī mǎ
pixel/ˈpɪksl/ 像素 xiàng sù
colour depth/ˈkʌlə depθ/ 色深 sè shēn
sample rate/ˈsæmpl reɪt/ 采样率 cǎi yàng lǜ
1.4

计算机逻辑

English

Logic gates

A logic gate 逻辑门 takes one or two binary inputs and gives one output. A truth table 真值表 lists the output for every combination of inputs.

Three small black computer chips with rows of metal pins, each printed with a code
A real logic chip: inside are logic gates like the ones on this page
The symbols of six logic gates: NOT, a triangle with a small circle; AND, a D shape; OR, a curved shield shape; NAND, AND with a small circle; NOR, OR with a small circle; XOR, OR with an extra curved line at the back
The six gates; a small circle on the output means NOT
$A$ $B$ AND OR XOR NAND NOR
0 0 0 0 0 1 1
0 1 0 1 1 1 0
1 0 0 1 1 1 0
1 1 1 1 0 0 0

NOT has one input and flips it: NOT 0 = 1. XOR is 1 when the inputs differ; XNOR is 1 when they are the same.

Logic circuits

Gates are joined into circuits. Work out a circuit's truth table by labelling each gate's output and filling in one column per label.

A logic circuit: A and B enter an AND gate, whose output is P; C enters a NOT gate, whose output is Q; P and Q enter an OR gate, whose output is X
$X = (A \text{ AND } B) \text{ OR } (\text{NOT } C)$
$A$ $B$ $C$ $P = A$ AND $B$ $Q =$ NOT $C$ $X = P$ OR $Q$
0 0 0 0 1 1
0 0 1 0 0 0
0 1 0 0 1 1
0 1 1 0 0 0
1 0 0 0 1 1
1 0 1 0 0 0
1 1 0 1 1 1
1 1 1 1 0 1

Three inputs give $2^3 = 8$ rows; list them counting up in binary so none is missed.

词汇 训练
English 中文 拼音
logic gate/ˈlɒdʒɪk ɡeɪt/ 逻辑门 luó jí mén
truth table/truːθ ˈteɪbl/ 真值表 zhēn zhí biǎo
1.5

操作系统

English

What an operating system does

An operating system 操作系统 (OS) manages the hardware and provides services to programs and users.

A smartphone held in one hand, showing the Android home screen with its app icons
A phone runs a mobile operating system that manages memory, processes, files and the hardware for every app
Function What it does
process management 进程管理 starts and stops programs and shares the CPU between them
memory management 内存管理 gives each program its own area of RAM and protects it from others
file management organises files in folders and controls who may read or write them
device management controls hardware through drivers 驱动程序
security checks users' identity and their permissions
user interface a graphical or command-line interface
Four steps in order: identify the user, authenticate the identity, authorize the action, record the permitted change
The OS checks who you are (authentication) before what you may do (authorization)

Scheduling

One CPU core runs one process at a time; the OS scheduler 调度程序 switches between processes so fast that they seem to run together.

Round-robin scheduling shown as a timeline: P1, P2, P3 each get a fixed time slice in turn, then the cycle repeats, sharing the CPU between them
Round-robin: each process gets a fixed time slice in turn, then the next runs (unlike first-come-first-served)
Method Rule Weakness
first come, first served run each process to the end, in arrival order a long job makes short ones wait
round robin each process gets a fixed time slice 时间片 in turn many switches if the slice is small
priority the highest-priority ready process runs low-priority processes may never run

Round robin, time slice 2 ms, processes P1 (5 ms), P2 (3 ms), P3 (1 ms) arriving together:

Time (ms) 0–2 2–4 4–5 5–7 7–8 8–9
runs P1 P2 P3 (ends) P1 P2 (ends) P1 (ends)

P3 finishes at 5 ms, P2 at 8 ms, P1 at 9 ms.

Polling and interrupts

The CPU must know when a device needs attention.

  • Polling 轮询: the CPU checks each device again and again. Simple, but wastes CPU time when nothing has happened.
  • Interrupt 中断: the device sends a signal; the CPU finishes its current instruction, saves its state, runs the interrupt's handler, then carries on. Efficient for events that are rare or unpredictable, such as a key press.
词汇 训练
English 中文 拼音
operating system/ˈɒpəreɪtɪŋ ˈsɪstəm/ 操作系统 cāo zuò xì tǒng
process management/ˈprəʊses ˈmænɪdʒmənt/ 进程管理 jìn chéng guǎn lǐ
memory management/ˈmeməri ˈmænɪdʒmənt/ 内存管理 nèi cún guǎn lǐ
driver/ˈdraɪvə/ 驱动程序 qū dòng chéng xù
scheduler/ˈʃedjʊlə/ 调度程序 diào dù chéng xù
time slice/taɪm slaɪs/ 时间片 shí jiān piàn
polling/ˈpəʊlɪŋ/ 轮询 lún xún
interrupt/ˈɪntərʌpt/ 中断 zhòng duàn
1.6

高级水平学习(AHL):翻译

English

Compilers and interpreters

The CPU runs only machine code 机器码. A program in a high-level language such as Python or Java must be translated.

Compiler translating a whole program once into machine code that runs many times, versus an interpreter translating and running one line at a time
A compiler translates the whole program once into machine code; an interpreter translates and runs one line at a time
Compiler 编译器 Interpreter 解释器
when translates the whole program before it runs translates and runs one statement at a time
output an executable file no separate file
speed of running fast slower: translated every time
errors all reported after compiling; nothing runs until they are fixed stops at the first error it reaches
source code not needed by users needed on every machine

Java uses both: the compiler turns source code into bytecode 字节码, which a virtual machine interprets, or compiles just in time (JIT) while the program runs. The same bytecode then runs on any machine with the virtual machine.

词汇 训练
English 中文 拼音
machine code/məˈʃiːn kəʊd/ 机器码 jī qì mǎ
compiler/kəmˈpaɪlə/ 编译器 biān yì qì
interpreter/ɪnˈtɜːprɪtə/ 解释器 jiě shì qì
bytecode/ˈbaɪtkəʊd/ 字节码 zì jié mǎ
1.7

练习

English
  1. State the role of (a) the program counter; (b) the ALU; (c) the address bus.
  2. Describe the fetch stage of the fetch–decode–execute cycle, naming the registers used.
  3. Explain why a GPU trains a machine-learning model faster than a CPU.
  4. Explain why cache memory speeds up a computer.
  5. Convert (a) 10011101 to denary; (b) 200 to binary; (c) 2F to denary.
  6. Write $-19$ as an 8-bit two's complement number.
  7. Calculate the file size, in bytes, of an 800 × 600 image with a colour depth of 16 bits.
  8. Give the truth table for $X =$ NOT($A$ OR $B$), and name the single gate that does the same.
  9. State two functions of an operating system.
  10. Processes P1 (4 ms) and P2 (3 ms) arrive together; round robin with a 2 ms slice. State when each finishes.
  11. Explain why a keyboard uses interrupts rather than polling.
  12. AHL Give one advantage of a compiler and one of an interpreter for a programmer.

Answers.

  1. (a) holds the address of the next instruction; (b) does arithmetic and logic operations; (c) carries addresses from the CPU to memory.
  2. The address in the PC is copied to the MAR; the instruction at that address is copied along the data bus into the MDR, then to the CIR; the PC is increased by 1.
  3. Training repeats the same calculation on huge amounts of data; the GPU's thousands of cores do these calculations in parallel.
  4. It holds copies of the most-used data and instructions next to the CPU, so they are read far faster than from RAM.
  5. (a) $128 + 16 + 8 + 4 + 1 = 157$; (b) $200 = 128 + 64 + 8$: 11001000; (c) $2 \times 16 + 15 = 47$.
  6. $19$ = 00010011; flip: 11101100; add 1: 11101101.
  7. $800 \times 600 \times 16 = 7\,680\,000$ bits $= 960\,000$ bytes.
  8. Rows 00 → 1, 01 → 0, 10 → 0, 11 → 0: a NOR gate.
  9. E.g. memory management, process management, file management, security.
  10. P1 0–2, P2 2–4, P1 4–6 (ends), P2 6–7 (ends): P1 at 6 ms, P2 at 7 ms.
  11. Key presses are rare and unpredictable; polling would waste CPU time checking, while an interrupt uses the CPU only when a key is pressed.
  12. Compiler: e.g. the finished program runs faster, and the source code need not be shared. Interpreter: e.g. errors are found line by line while testing, and there is no wait to compile.
1.8

考试技巧

English
  • Name registers in full the first time (program counter, PC) and give the direction of each bus.
  • In the fetch stage, follow the order PC → MAR → memory → MDR → CIR, and say that the PC increments.
  • For conversions, show the place values; for two's complement, show flip then add 1.
  • File-size answers: show the formula, the numbers and the unit, and divide by 8 for bytes.
  • Truth tables for $n$ inputs need $2^n$ rows in binary order, with a column for every intermediate output.
  • Compare CPU and GPU, polling and interrupts, or compiler and interpreter point by point, not in two separate lists.
这有帮助吗?

更多 IB 计算机科学 HL 知识点

登录或创建账户

IGCSE, A-Level & AP