to the control unitopcode2nd byte (imm)next PCds+2··PC4DMEM··IMEM·· ··r0r1r2r3RD1RD2WDA1A2REGISTERS2300ALUAB··MUX0101selMUX0101sel
Lit trace with moving dashes: it carries the value the step is aboutWhite tags riding the traces: the values themselvesFront faces: each part's current value (·· = nothing yet)Mux lamps: the select bit, glowing = 1Two TINY-8 instructions travel through the same hardware: ADD r0, r1 goes through the register file's two read ports and the ALU; LD r2, [16] goes through data memory. Only the mux settings differ. 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). 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).

Fetch and decode

  1. The datapath is the road data takes through a CPU. It starts at the program counter (PC), a register holding the next instruction's address: 4. Instruction memory reads addresses 4 and 5 and hands back two bytes: 0x51 0x00.

Execute ADD r0, r1

LD r2, [16]

The working

;; step 1/10 · fetch
;; about: Program counter, Instruction memory
program (TINY-8):
   0  LDI r0, 2
   2  LDI r1, 3
   4  ADD r0, r1
   6  LD r2, [16]
   8  HALT
  16  data byte 7

r0 = 2 and r1 = 3 already (the two LDIs ran).
PC = 4 → bytes 0x51 0x00 = ADD r0, r1

A lit wire with moving dashes carries the value the step is about; the small white tags riding on it are those values. 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.