The datapath: where the data flows
لم يُترجم بعد؛ يُعرض باللغة الإنجليزية
The datapath is the hardware an instruction's data flows through: the program counter, instruction memory, the register file with its two read ports and one write port, the ALU, data memory, and the multiplexers that pick which value goes where. Follow two TINY-8 instructions, ADD r0, r1 and LD r2, [16], through the same wires, value by value, and see that only the mux settings change.
5 أسئلة سريعة
اختر إجابة لتعرف السبب. تُحفَظ نتيجتك مع تقدّمك.
01Why does the register file have two read ports?
ADD needs r0 and r1 together. Two read ports give both values at once, one to the ALU's A input and one to the B mux.
02TINY-8 instructions are 2 bytes long. The PC holds 4. What does the PC + 2 adder produce?
4 + 2 = 6, the address where the next instruction starts. The PC takes that value on the clock tick at the end of the instruction.
03In ADD r0, r1, what does the B mux pass to the ALU?
For ADD the select bit is 0, so the register value passes. An instruction like ADDI would set it to 1 and use the byte from the instruction instead.
04For LD r2, [16], where does the value written into r2 come from?
The second byte, 16, goes to data memory as the address. Memory returns 7, and the write-back mux, now set to 1, passes it to the register file's write port.
05ADD and LD travel through the same datapath. What is different between them?
The hardware is shared. The control unit reads the opcode and sets each mux select bit and the register write enable, so one datapath can run every instruction.
المسرد
- Datapath
- The part of a processor that holds and moves data: program counter, memories, register file, ALU and the multiplexers between them.
- Program counter (PC)
- A register that holds the address of the next instruction to fetch.
- Register file
- A small block of registers (here r0 to r3) with read ports that give register values and a write port that stores a new one.
- Port
- One set of address and data wires into or out of a memory or register file. Two read ports means two independent reads at once.
- Multiplexer (mux)
- A switch made of gates: its select bits decide which one of its inputs reaches its output.
- ALU
- Arithmetic logic unit: the circuit that adds, subtracts and does logic on two inputs.
- Opcode
- The bits of an instruction that say which operation it is. In TINY-8, the top four bits of the first byte.
- Control unit
- The logic that reads the opcode and sets the mux selects and write enables of the datapath.
الملاحظات والمصادر
- The datapath is the part of a processor that holds and moves data: the program counter, the memories, the register file, the ALU and the multiplexers between them. The control unit decides, for each opcode, how the multiplexers are set and whether a register is written (Patterson and Hennessy, Computer Organization and Design, sections 4.3 and 4.4; Harris and Harris, Digital Design and Computer Architecture, section 7.3).
- A register file with two read ports and one write port is the textbook design: two register numbers pick two values to read at once, with no clock, and the write port stores its data in the chosen register on the clock edge when write enable is 1 (Harris and Harris, section 5.5.6).
- TINY-8 keeps program and data in one 256-byte memory. Textbook single-cycle datapaths draw separate instruction and data memories, because one instruction can need to read both in the same clock cycle; the figure does the same (Harris and Harris, section 7.3.1).
- The figure shows only the paths ADD and LD use. A full TINY-8 datapath also needs a path from the second byte into the registers (LDI), from a register into data memory (ST), a jump mux in front of the PC (JMP, JZ, JNZ) and the input and output ports (IN, OUT).
- TINY-8 is this course's teaching CPU: 8-bit data, four registers r0 to r3, and 2-byte instructions whose first byte is oooo ddss (opcode, destination register, source register). Every number on the figure comes from its simulator.
- In Python, b0 >> 4 shifts the byte right by four bits, leaving the opcode, and & 3 keeps the lowest two bits, so (b0 >> 2) & 3 is d and b0 & 3 is s. & 0xFF keeps 8 bits, like the 8-bit ALU.
- A lit wire with moving dashes carries the value the step is about; the small white tags riding on it are those values.
- Harris and Harris, Digital Design and Computer Architecture (sections 2.8, 5.5.6 and 7.3)
- Patterson and Hennessy, Computer Organization and Design RISC-V Edition (sections 4.3 and 4.4)
- MIT OpenCourseWare 6.004 Computation Structures
- UC Berkeley CS 61C: Great Ideas in Computer Architecture
- Nisan and Schocken, Nand2Tetris: computer architecture (chapter 5)
- Python reference: shifting and bitwise operations
اختبار يتاح بعد الخطوة الأخيرة.