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코인 + 오늘 첫 완료 시 작은 보너스 추가
지금 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.
출력을 보려면 '실행'을 클릭하세요.