hack

A complete Hack computer built from first principles in TypeScript

Study project2024 โ†— github โ†— jsr
Hack computer implementation
The Hack instruction set with its corresponding binary codes

The nand2tetris course (The Elements of Computing Systems) challenges you to build a modern computer from scratch. Starting with a single NAND gate and ending with a working, programmable machine. This is my TypeScript implementation of the hardware side.

Every chip is defined as a logical unit, composed only of chips below it in the hierarchy.

// highlights

  1. Gate library โ€” Implemented all 15 elementary chips from the course: NAND, NOT, AND, OR, XOR, MUX, DMUX and their multi-bit variants. Each chip is tested independently before being used to compose higher-level ones.
  2. Arithmetic Logic Unit โ€” Built the ALU that powers the Hack CPU. It supports 18 distinct operations controlled by 6 control bits โ€” zero input, negate input, compute, negate output โ€” all derived from combinations of the gate library.
  3. CPU & Memory โ€” Composed the full CPU from the ALU, two registers (A and D), a program counter, and the instruction decoder. Wired it to RAM and ROM to form a complete von Neumann machine.
  4. Assembler โ€” Wrote an assembler that translates Hack assembly (.asm) into 16-bit binary instructions (.hack). Handles A-instructions, C-instructions, labels, and a symbol table for variable resolution.

// stack

  • TypeScript
  • Deno