Processor and memory overview
導入済み
5:52
コンピュータシステム基礎
This course follows a program from a single bit to a running process. The first two units are the alphabet: how bits encode data, and how logic gates compute…
英語のナレーション・英語と中国語の字幕を切り替え可能
このレッスンの内容
| English | 意味 |
|---|---|
| instruction/ɪnˈstrʌkʃn/ | |
| memory/ˈmeməri/ | Circuits that store data, such as registers, RAM and ROM. |
| fetch-decode-execute cycle/fetʃ dɪˈkəʊd ˈeksɪkjuːt ˈsaɪkl/ | 取指-デコード-実行サイクル |
| program counter/ˈprəʊɡræm ˈkaʊntə/ | プログラムカウンタ |
| instruction register/ɪnˈstrʌkʃn ˈredʒɪstə/ | 命令レジスタ |
| register/ˈredʒɪstə/ | レジスタ |
| arithmetic logic unit/əˈrɪθmətɪk ˈlɒdʒɪk ˈjuːnɪt/ | 演算論理回路 |
| memory hierarchy/ˈmeməri ˈhaɪərɑːki/ | メモリ階層構造 |
| cache/kæʃ/ | キャッシュ |
| locality/ləʊˈkælɪti/ | 局所性 |
| cache line/kæʃ laɪn/ | キャッシュライン |
Same work, ten times slower
- Two loops add up every number in a large table. They do the same additions, yet one runs many times slower than the other.
- The clock speed is the same, and so is the instruction count. The difference is how each loop uses memory 存储器, and this lesson explains why.
The fetch-decode-execute cycle
- The processor repeats one loop, the fetch-decode-execute cycle 取指-译码-执行周期. Fetch: the program counter 程序计数器 (PC) gives an address, and the instruction there goes into the instruction register 指令寄存器 (IR).
- Decode turns the instruction into control signals; execute uses the ALU, memory or the PC. With 4-byte instructions the PC then moves on by 4, and a branch writes a new address into it.

Put one pass of the processor's cycle in order.
難易度 3/5 · 200 コイン + 今日初回達成時の小ボーナス
Fetch, decode, execute, then the PC moves on (or a branch sets it).
In fetch-decode-execute, the instruction register (IR) is loaded during —
難易度 1/5 · 100 コイン + 今日初回達成時の小ボーナス
Fetch reads memory at the PC into the IR; decode then interprets it.
The PC holds 1000 and every instruction is 4 bytes. After three instructions with no branch, what does the PC hold?
難易度 2/5 · 140 コイン + 今日初回達成時の小ボーナス
1000 + 3 × 4 = 1012.
Registers and the ALU
- Registers 寄存器 are a few dozen very fast storage places inside the processor. They hold the values the program is working on right now.
- The arithmetic logic unit 算术逻辑单元 (ALU) adds, compares and does logic on register values. Results go back into a register.
The memory hierarchy
- The memory hierarchy 存储层次: registers, then L1, L2 and L3 cache 高速缓存, then DRAM main memory (about 100 ns), then SSD. Each layer is bigger and slower than the one above.
- The reason is cost: fast memory is expensive per byte, and big memory is slow. No single technology is both large and fast.
The memory hierarchy exists because —
難易度 1/5 · 100 コイン + 今日初回達成時の小ボーナス
It is a physical trade-off, solved by stacking layers and using locality.
Match each layer to its rough size and speed.
難易度 2/5 · 140 コイン + 今日初回達成時の小ボーナス
Each step down is bigger and slower.
Locality makes it work
- Programs show locality 局部性. Temporal locality: data used now is likely to be used again soon. Spatial locality: nearby addresses are likely to be used next.
- So a small fast cache can hold most of what the program touches, and most accesses never reach DRAM.
Reading array elements one after another in address order uses spatial locality.
難易度 1/5 · 100 コイン + 今日初回達成時の小ボーナス
Neighbouring addresses come in the same cache line, so the next reads are hits.
Cache lines and data layout
- A cache miss does not fetch one value. It fetches a whole cache line 缓存行, usually 64 adjacent bytes.
- For a large table stored in row-major order, walking row by row uses adjacent values in each cache line. Walking column by column may use only one value per line before moving on, causing many more misses.
For a large row-major array, a row-by-row loop can beat a column-by-column loop at the same operation count because —
難易度 1/5 · 100 コイン + 今日初回達成時の小ボーナス
Consecutive bytes share one line, so layout can beat arithmetic.
Worked example: three instructions
- Memory at address R2 holds 7.
LOAD R1, 0(R2)makes R1 = 7;ADD R3, R1, R1makes R3 = 14;STORE R3, 0(R2)writes 14 back. - Each instruction 指令 moves the PC on by 4, so after the three the PC is 12 bytes further on.
Worked example: average access time
- 95% of accesses hit the cache 高速缓存 at 1 ns; the other 5% go to DRAM at 100 ns.
- Average $= 0.95 \times 1 + 0.05 \times 100 = 5.95$ ns. The rare misses cost more than all the hits together.
90% of accesses hit the cache at 1 ns and 10% go to DRAM at 100 ns. What is the average access time in ns?
難易度 2/5 · 140 コイン + 今日初回達成時の小ボーナス
0.9 × 1 + 0.1 × 100 = 0.9 + 10 = 10.9 ns.
Three common slips
- Mixing up the PC and the IR. The PC holds an address; the IR holds the instruction itself.
- Treating memory time as fixed. A cache 高速缓存 hit and a DRAM miss differ about a hundred times.
- Thinking the CPU sees physical addresses. Virtual memory sits in between (lesson 0305).
Recap
- Fetch (PC to IR), decode (control signals), execute (ALU, memory or PC); then PC + 4 or a branch.
- Each layer is bigger, slower and cheaper per byte:
| Layer | Size | Access time |
|---|---|---|
| Registers | a few dozen values | under 1 ns |
| L1 cache | tens of KB | about 1 ns |
| DRAM | gigabytes | about 100 ns |
| SSD | terabytes | tens of µs |
- Locality and 64-byte cache lines 缓存行 make the hierarchy work, so data layout can matter more than the clock.
何が問題でしたか?この内容はサイトの運営チームだけが確認します。