Home / Learn Chip Programming / Project 10: Design Your Own 8-Bit CPU
Project 10: Design Your Own 8-Bit CPU
Build a small CPU in 74HC chips (or Verilog): register, ALU, RAM, program counter and control logic.
Theory in plain words
What it is
A SAP-1 style CPU: 16 bytes of RAM, a 4 bit program counter, accumulator, ALU, output register. A control unit decodes instructions and sets the control lines for each step.
Why we use it
Building a CPU is the best way to understand fetch, decode and execute. Everything in the theory lessons becomes real.
How it works
Each instruction takes fetch (PC to memory address, memory to instruction register) then execute steps. The control logic is a ROM or gates mapping opcode and step to control signals.
Where it is used
- Computer architecture understanding
- Interview preparation
- The base of every processor
Equipment
This build is large. Start with a Verilog or browser simulation. A logic analyzer helps check the bus on a slow clock.
Module plan
| Module | 74HC chips | Job |
|---|---|---|
| Program counter | 74HC161 | counts addresses 0 to 15 |
| Accumulator and B register | 74HC273 / 74HC377 | hold values |
| ALU adder | 74HC283 x2 + 74HC86 XOR | add and subtract |
| RAM | 74HC189 or an AT28C16 / 62256 | holds program and data |
| Instruction register | 74HC377 | holds the current instruction |
| Bus buffers | 74HC245 / 74HC541 | put values on the shared bus |
| Control ROM | AT28C16 EEPROM | microcode: opcode + step to control lines |
| Clock | 555 or crystal + 74HC161 | manual step and slow auto clock |
Live CPU simulator
This is a real stored-program computer: change the program text and the same hardware does a different job.
Verilog version (same CPU)
module sap (input clk, rst, output reg [7:0] out, output reg halt);
reg [7:0] ram [0:15]; reg [3:0] pc; reg [7:0] a, ir; reg [1:0] st;
initial $readmem("prog.hex", ram);
always @(posedge clk) if (rst) begin pc <= 0; a <= 0; st <= 0; halt <= 0; end
else if (!halt) case (st)
0: begin ir <= ram[pc]; pc <= pc + 1; st <= 1; end // fetch
1: begin st <= 0; // execute
case (ir[7:4])
4'h1: a <= ram[ir[3:0]]; 4'h2: a <= a + ram[ir[3:0]]; 4'h3: a <= a - ram[ir[3:0]];
4'h4: ram[ir[3:0]] <= a; 4'h5: a <= {4'b0, ir[3:0]}; 4'h6: pc <= ir[3:0];
4'h7: if (a == 0) pc <= ir[3:0]; 4'hE: out <= a; 4'hF: halt <= 1;
endcase end
endcase
endmodule- Run the browser simulator and write a program that adds two numbers.
- Port it to the Verilog model and simulate it with a testbench.
- Build one module at a time on breadboards (program counter first) and test each with LEDs.
- Connect the modules to the shared bus with 74HC245 buffers and test with a slow clock.
- Program the control ROM (microcode) and run your first program.
Quick quiz
1. Fetch stage does...
PC addresses memory, result goes to IR.
2. JZ jumps when...
Conditional jump on zero flag.