Giter Club home page Giter Club logo

nand2tetris's Introduction

A 16 bit computer, built completely from the ground up that is capable of running Tetris

All hardware and software components are built completely from scratch to fully learn and understand how computers work. The ultimate goal is to create a fully functional 16-bit computer capable of running Tetris. This computer can be ran on an FPGA (with all HDL code refactored into Verilog/SystemVerilog or VHDL) or a series of breadboards and wires to make a custom computer. Read about the Hack computer

1. Logic Gates/Boolean Logic

The foundation of any computer system is built on logic gates and boolean logic. In this phase, we construct a large collection of 1-bit and 16-bit logic gates from scratch.

  • Basic Gates: AND, OR, NOT, NAND, NOR, XOR, XNOR
  • Composite Gates: Multiplexers, Demultiplexers, Adders, Subtractors
  • 16-bit Versions: Expanding 1-bit logic gates to operate on 16-bit data

2. Boolean Arithmetic/ALU

Building on the logic gates, we develop the Arithmetic Logic Unit (ALU), which is responsible for performing arithmetic and logic operations.

  • Mathematical Operations: Addition, Subtraction, Bitwise operations
  • Logical Operations: AND, OR, NOT, NAND, NOR, XOR, XNOR
  • 16-bit ALU: Capable of executing complex operations on 16-bit data

3. Memory

Memory is crucial for storing data and instructions. This phase focuses on creating various sizes of RAM chips and clocked chips, including D flip-flops.

  • Basic Memory Elements: D Flip-Flops, Latches
  • RAM Chips: 4-bit, 8-bit, 16-bit, and beyond
  • Clocking Mechanisms: Ensuring synchronized data storage and retrieval

4. Machine Language

With the hardware foundation in place, we define and test programs written in the Hack flavor of Assembly language.

  • Instruction Set Architecture (ISA): Definition of the Hack assembly language
  • Test Programs: Simple programs to test and validate the hardware components

5. CPU

The Central Processing Unit (CPU) integrates all hardware components into a single chip capable of executing instructions.

  • Control Unit: Manages the execution of instructions
  • Data Path: Routes data between the ALU, memory, and registers
  • Integration: Combining all components to form a cohesive CPU

6. Assembler

The assembler translates Hack machine language into binary code that the CPU can execute.

  • Syntax Parsing: Converts assembly language into machine code
  • Code Generation: Outputs binary files ready for execution

7. VM Part I

The first part of the Virtual Machine (VM) translation as part of a two-step compilation process handles basic VM bytecode and translates it into machine code.

  • Stack Arithmetic: Handling basic stack operations
  • Memory Access: Translating memory access commands
  • Code Translation: Converting VM code to Hack assembly

8. VM Part II

In this phase, we extend the capabilities of the VM translator to handle more complex commands, including program flow and function calling.

  • Program Flow: Translating conditional and unconditional branching commands
  • Function Calling: Handling function calls and returns
  • Advanced Memory Access: Managing memory segments like pointers, static, and temp

9. High-Level Language (Jack)

The high-level language Jack is introduced, providing a more abstract and user-friendly way to write programs.

  • Space Invaders: A basic version of Space Invaders, implementing the core mechanics
  • Syntax and Semantics: Definition of the Jack language, including syntax and semantic rules
  • Standard Library: Basic standard library functions for string manipulation, I/O, and mathematics
  • Sample Programs: Example Jack programs demonstrating language features

10. Compiler I

The first part of the Jack compiler translates Jack high-level language into VM code. Broken up into a Parsing module and a Syntax Analysis module.

  • Syntax analysis: Tokenizing the Jack code for parsing
  • Recursive descent parsing: Parsing Jack code into an recursive deriveration tree, expressed in XML tags

11. Compiler II

The second part of the Jack compiler focuses on optimizing and finalizing the translation process from Jack to VM code.

  • Code Generation: Translating the deriviration tree into VM code
  • Advanced Code Generation: Handling complex language constructs and features
  • Comprehensive Testing: Extensive testing to ensure correctness and performance

12. Operating System

With the hardware and software infrastructure in place, we develop a simple operating system to manage the computer's resources and provide essential services.

  • Memory Management: Handling memory allocation and deallocation
  • Process Management: Managing program execution and multitasking
  • I/O Handling: Providing input and output functionalities
  • Mathematics library: Providing the mathematical functions for the OS
  • String library: Providing string handling and functionality
  • OS system initialisation and error handling: Performing all initialisations required by the OS and providing error messages to the user

nand2tetris's People

Contributors

blacknand avatar

Stargazers

fabi avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.