A full-stack implementation of a general-purpose computer system, built from the ground up.
This repository documents my journey of constructing a complete computer system—from the most elementary logic gate to a high-level object-oriented game and a functioning Operating System.
The project follows the "First Principles" approach, demystifying the "black box" of computing by implementing every single layer of abstraction personally.
🔗 Course: Nand2Tetris (The Elements of Computing Systems)
The core philosophy of this project is Abstraction. Modern computers are built in layers, where each layer relies on the one below it while hiding its complexity.
I built this system in two main phases, creating a bridge between hardware and software:
Starting with nothing but a primitive NAND gate, I designed the hardware using HDL (Hardware Description Language).
- Logic Gates: Combined NAND gates to create AND, OR, XOR, and Multiplexers.
- Arithmetic: Built a Half-Adder, Full-Adder, and a 16-bit ALU (Arithmetic Logic Unit).
- Memory: Constructed sequential logic chips (Bit, Register, RAM8... RAM16K) and a Program Counter (PC).
- CPU: Integrated the ALU and Registers into a Central Processing Unit capable of executing machine instructions (Fetch-Decode-Execute cycle).
Once the hardware was simulated, I built the software tools required to run programs on it. These tools were developed in Python.
- Assembler: Translates symbolic Hack Assembly into binary machine code.
- VM Translator: A backend that maps a Stack-Machine architecture (Intermediate Representation) onto the register-based hardware.
- Compiler: A full-scale compiler (Front-end & Back-end) for the high-level Jack language.
- Operating System: A standard library (Math, Memory, Screen, String) implementing core services efficiently in software.
This project required a versatile use of different programming paradigms and languages:
| Component | Technology / Language | Usage |
|---|---|---|
| Hardware | HDL (Hardware Description Language) | Designing Chip Logic, ALU, CPU, and RAM. |
| System Tools | Python | Writing the Assembler, VM Translator, and Compiler. |
| Parsing | Regex & Context-Free Grammar | Used in the Compiler's Tokenizer and Parser (LL1). |
| Low-Level | Hack Assembly | Writing optimized code for I/O and arithmetic. |
| High-Level | Jack (Java-like) | Developing the Operating System and the Game Application. |
Through this project, I gained hands-on experience in core Computer Science and Engineering concepts:
- Logic Design: Understanding combinatorial vs. sequential logic.
- CPU Architecture: Designing a Von Neumann architecture with instruction decoding and control bits.
- Memory Hierarchy: Building RAM units and understanding the Program Counter's role.
- Lexical Analysis: Using Regular Expressions (Regex) to tokenize source code.
- Parsing: Implementing a Recursive Descent Parser to generate XML Parse Trees.
- Code Generation: Translating high-level OOP constructs (objects, methods, arrays) into low-level stack operations.
- Symbol Tables: Managing variable scope (static, field, local, argument) and memory allocation.
- Math Implementation: Implementing multiplication ($O(\log n)$) and division algorithms in software constraints.
- Graph Algorithms: Implementing BFS (Breadth-First Search) for pathfinding in the game project.
- Memory Management: Writing a Heap Allocator (malloc/free) using a Free-List data structure.
- Virtualization: Implementing a Stack Machine VM that abstracts the underlying hardware.
- Drivers: Writing low-level drivers for Screen (Memory Mapped I/O, Bit-masking) and Keyboard.
computer-structure-fundamentals-projects/
├── I. Hardware Platform (HDL)
│ ├── 01-Boolean-Logic/ # Logic Gates (Not, And, Or, Xor, Mux)
│ ├── 02-Boolean-Arithmetic/ # Half/Full Adder, Inc16, ALU
│ ├── 03-Sequential-Logic/ # Flip-Flops, Registers, RAM8-RAM16K, PC
│ ├── 04-Machine-Language/ # Assembly code (Mult, I/O drivers)
│ └── 05-Computer-Architecture/ # CPU, Memory, and the complete Computer chip
│
├── II. System Software (Python)
│ ├── 06-Assembler/ # Logic to translate .asm to .hack binary
│ ├── 07-VM-Translator-I/ # Stack arithmetic & memory segments
│ ├── 08-VM-Translator-II/ # Control flow (branching) & Function call stack
│ ├── 10-Compiler-Syntax/ # Tokenizer & Parser (outputs XML structure)
│ └── 11-Compiler-Code-Gen/ # Full compilation to VM code (Symbol Tables)
│
└── III. High-Level Applications (Jack Language)
├── 09-The-Maze-Game/ # A complex game featuring AI (BFS) and custom graphics
└── 12-Operating-System/ # The Standard Library (Math, Screen, String, Memory, etc.)
Developed by Elal Gilboa as part of the Nand2Tetris certification.