Lesson 68: Fetch, decode, execute
このページには最新のブラウザ(SharedArrayBuffer対応)が必要です。Chrome、Edge、Firefox、Safariを最新バージョンに更新してください。
English
Inside the CPU
- The CPU repeats three steps: fetch an instruction from memory, decode it, execute it.
- Registers are tiny, fast stores inside the CPU. This sketch uses a variable for each one.
| Register | Holds |
|---|---|
| PC (program counter) | the address of the next instruction |
| MAR (memory address register) | the address to read from or write to |
| MDR (memory data register) | the data or instruction read from memory |
| CIR (current instruction register) | the instruction being decoded |
| ACC (accumulator) | the result of a calculation |
English
The program in memory
| Address | Contents | Meaning |
|---|---|---|
| 0 | 106 | LOAD from 6 |
| 1 | 207 | ADD from 7 |
| 2 | 308 | STORE to 8 |
| 3 | 900 | HALT |
| 6 | 5 | data |
| 7 | 7 | data |
English
In the exam
- 0478/12/M/J/24 Q5(a): complete the paragraph about fetching an instruction. The answers, in order: the PC holds the address of the next instruction; it is sent to the MAR on the address bus; then to RAM; the instruction at that address is sent to the MDR on the data bus; then to the CIR, which is in the control unit (CU).
難易度 3/5 · 200 コイン + 今日初回達成時の小ボーナス
This sketch is a tiny CPU. memory holds a program, and the variables are its registers. Write the four steps of fetch(): the PC goes to the MAR, the instruction at that address goes to the MDR, the PC goes up by 1, and the MDR goes to the CIR. The sketch fetches the first 4 instructions and prints the registers each time.
実行ボタンをクリックして出力を確認してください。
難易度 4/5 · 280 コイン + 今日初回達成時の小ボーナス
Now decode(デコード) かつ execute each instruction. 207 means opcode 2 (ADD) with address 7: CIR / 100 gives the opcode and CIR % 100 the address. LOAD is done. Add ADD, STORE and HALT, so the program works out 5 + 7 and stores 12 at address 8.
実行ボタンをクリックして出力を確認してください。