Case Study · Digital Logic

Custom 4-Bit CPU & Assembly Battleship

A collaborative digital-logic project where we designed and bread-boarded a 4-bit RISC-style CPU, wrote a minimal instruction set architecture, and built two demo programs, an LED Battleship game and a Fibonacci calculator, entirely in our own custom assembly language.

LogisimDigital LogicCustom ISAAssembly
01

overview

The work covered hardware description, micro-architecture, and low-level software development, from wiring the datapath and control logic on a breadboard to writing an assembler and the assembly programs that run on it.

02

live_preview

An instruction pulse moving through the datapath: fetch, decode, execute, memory-mapped I/O, write-back.

Fetch
0000 ADD 0110 OUT 0010 BEQ
Decode
ALU Execute
Memory-Mapped I/O
03

architecture

16-bit Instruction Word

4-bit opcode, 3-bit register fields, 6-bit immediates.

4 Register File

One hard-wired to zero, three general purpose.

ALU & Zero-Flag

Add, sub, and zero-detect for branching.

Memory-Mapped I/O

Shared data/I/O space to drive LEDs & read buttons.

04

isa

# R-Type 0000 rd, rs ; ADD rd ← rd + rs 0001 rd, rs ; SUB rd ← rd – rs # I-Type 0010 rd, rs, imm ; BEQ if rd == rs PC←PC+imm 0011 rd, imm(rs) ; LW rd ← MEM[rs+imm] 0100 rd, imm(rs) ; SW MEM[rs+imm] ← rd 0101 rd, imm ; IN rd ← IO[imm] 0110 rd, imm ; OUT IO[imm] ← rd # J-Type 0111 rd ; JMP PC ← rd
05

demo/battleship

# placeShip: read X/Y buttons, light green LED LOOP: in r1, 0x01 ; read X-axis button in r2, 0x02 ; read Y-axis button add r3, r1 ; update cursor X add r3, r2 ; update cursor Y out r3, 0x10 ; move yellow LED in r0, 0x04 ; read ENTER beq r0, r0, LOOP ; if not pressed, loop out r3, 0x11 ; fix ship (green)
06

learnings