8-Bit SAP-1 CPU Architecture (Custom Logic Design)
Project Summary: Inspired by Ben Eater’s SAP-1-based computer, I designed an 8-bit CPU (central processing unit) from scratch using basic logic gates and integrated circuits. I completed the project in October 2025 to demonstrate processor architecture, memory addressing, and machine-code execution at the hardware level.

System Architecture
- CLK (Clock): Provides the timing signal that synchronizes the processor’s operations.
- Program Counter (PC): Holds the 4-bit RAM address (0–15) of the next instruction. It increments during instruction fetch. A jump can load a different address into the PC.
- MAR (Memory Address Register): Temporarily holds the 4-bit RAM address for a read or write.
- RAM (Random Access Memory): Stores the program and its data in 16 addressable locations of 8 bits each.
- Instruction Register (IR): Holds the instruction byte read from RAM and supplies its opcode to the control unit.
- Control Logic (Opcode ROM, Step Counter, Decoder): Sequences the micro-operations for each instruction by activating control lines such as
RAM_OUTandA_IN. - Registers A and B: Temporarily hold the operands for arithmetic. Register A is the accumulator and receives the arithmetic result.
- ALU (Arithmetic Logic Unit): Adds or subtracts the values in registers A and B and can place the 8-bit result on the data bus.
- Flags (Carry and Zero): Record status for conditional jumps. An unsigned addition sets Carry when its sum exceeds 255. Zero indicates a zero result when the flag is updated.
- Output Register and BCD: The output register holds the value to display. The binary-to-BCD converter supplies decimal digits to the seven-segment displays.
How It Works
- Fetch: The PC address is copied to the MAR. RAM places the instruction byte at that address on the bus, the IR captures it, and the PC advances.
- Decode: The control unit uses the upper four bits (the opcode) of the IR to select the appropriate sequence of micro-operations.
- Execute: The control unit asserts the signals that drive the shared bus and load the registers needed for the instruction.
Instruction Set
Each instruction in this design occupies one byte. The upper four bits encode the operation. Depending on the opcode, the lower four bits encode a RAM address or an immediate value, or are unused.
- 0000 (NOP): Perform no operation and continue to the next instruction.
- 0001 (LDA): Load the value at the specified RAM address into register A.
- 0010 (ADD): Add the value at the specified RAM address to register A.
- 0011 (SUB): Subtract the value at the specified RAM address from register A.
- 0100 (STA): Store the contents of register A at the specified RAM address.
- 0101 (LDI): Load the immediate value encoded in the lower four bits into register A without a separate RAM read for the operand.
- 0110 / 0111 / 1000 (JMP, JC, JZ): Jump to the specified address unconditionally, when Carry is set, or when Zero is set, respectively.
- 1110 (OUT): Copy the contents of register A to the output register.
- 1111 (HLT): Stop the processor clock and halt execution.
Machine-Code Example: Sum of Consecutive Integers
Load these hexadecimal bytes into RAM addresses 0–15:
1D 2E 79 4D E0 1E 2F 4E 60 F0 00 00 00 00 01 01Program Walkthrough
The final three RAM locations hold the program’s data:
- Address 13 (D):
00, the initial running total. - Address 14 (E):
01, the initial counter. - Address 15 (F):
01, the constant used to increment the counter.
Instructions (starting at address 0):
- Address 0 — 1D (LDA 13): Load the running total into register A.
- Address 1 — 2E (ADD 14): Add the counter to register A. On the first pass, this adds 1 to 0.
- Address 2 — 79 (JC 9): If the sum exceeds 255, jump to address 9 before storing or displaying the wrapped result.
- Address 3 — 4D (STA 13): Save the new running total at address 13.
- Address 4 — E0 (OUT): Display the current running total.
- Address 5 — 1E (LDA 14): Load the counter into register A.
- Address 6 — 2F (ADD 15): Add the constant 1 to the counter.
- Address 7 — 4E (STA 14): Save the updated counter at address 14.
- Address 8 — 60 (JMP 0): Return to address 0 and repeat.
- Address 9 — F0 (HLT): Halt execution.
The last displayed value is 253, the sum of 1 through 22. Adding 23 would produce 276, so the carry check halts the program before the overflowing sum can replace 253.