Git Product home page Git Product logo

nand2tetris's Introduction

Nand2Tetris

Nand2Tetris is a computer science course by the MIT Press. It takes you through the steps of building a computer starting with nothing more than simple NAND gates. It then guides you through the process of building an assembler, virtual machine, and compiler for an objected oriented programming language. This repo contains only my own work and excludes the extra course files.

Course Website

The Hardware

The hardware design used by the course is named HACK. Circuits are designed using a Hardware Description Language (HDL) with the .hdl extension. Machine code has the .hack extension.

Hardware Source Code

Computer specs

  • 16 bit
  • 32K RAM
  • 512x256 black & white screen
  • Keyboard
Chapter 1 - Boolean Logic NOT Gate
OR Gate
AND Gate
XOR Gate
Multiplexor
Demultiplexor

16 Bit NOT Gate
16 Bit OR Gate
16 Bit AND Gate
16 Bit Multiplexor
16 Bit Demultiplexor

4 Way Multiplexor
8 Way Multiplexor
4 Way Demultiplexor
8 Way Demultiplexor
Chapter 2 - Boolean Arithmetic Half Adder
Full Adder
16 Bit Adder
16 Bit Incrementer
ALU
Chapter 3 - Sequential Logic Bit
Program Counter
Register
RAM Chips
Chapter 4 - Machine Language Assembly program to toggle screen color
Assembly program to multiple two integers
Chapter 5 - Computer Architecture CPU
Memory
Computer

The Jack Programming Language

The target language for the course's compiler is the Jack programming language, an object orient language that somewhat resembles Java. It supports strings, arrays, basic math, basic drawing, a keyboard, and direct memory access. The Jack standard library is, of course, written in Jack.

Jack Standard Library Source Code

The Compilation Process

The compilation process again resembles Java by being split into 3 parts; a compiler, a virtual machine, and an assembler. The compiler converts an OOP Jack program into a platform agnostic virtual machine language program. The virtual machine then translates the VM program into a hardware specific HACK program. Finally, the assembler converts the HACK program into machine code that is runnable by the HACK hardware described previously.

Jack Compiler

The Jack Compiler converts any Jack files it finds into a corresponding virtual machine file. The VM output is platform agnostic.

Virtual Machine

The VM Translator converts platform agnostic virtual machine code into HACK assembly code. To add support for a new hardware platform, you would modify the VM Translator and create a new assembler. Doing so would then allow you to use any language built on top of this VM implementation, in this case the Jack Compiler.

HACK Assembler

The assembler converts HACK assembly code into HACK machine code. This is a one to one conversion where each line of assembly code converts into exactly 16 bits of machine lanugage.

nand2tetris's People

Contributors

zmilla93 avatar

Stargazers

 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.