Coder Social home page Coder Social logo

vantamnguyen / nand2tetris Goto Github PK

View Code? Open in Web Editor NEW
32.0 2.0 13.0 2.07 MB

Nand2Tetris: Build a computer system from the ground up, from nand to tetris. Hardware and software.

Scilab 18.80% Assembly 56.20% HTML 9.31% Batchfile 0.79% Shell 1.07% Java 13.84%
nand2tetris virtual-machine hardware symbol-table boolean-logic boolean-algebra sequential-logic machine-language computer-architecture assembly-language

nand2tetris's Introduction

Nand2Tetris

Nand2Tetris: Build a computer system from the ground up, from nand to tetris (nand is the fundamental logic gate to build others gates), from hardware to software.

This github repository is place I store my taken notes and exercises when reading the book The Elements of Computing Systems: Building a Modern Computer from First Principles and learning the related courses on Coursera.org.

Thanks professor Noam Nisan and professor Shimon Shocken for writing a super cool book and creating excellent tools and teaching great courses.

What I hear, I forget; What I see, I remember; What I do, I understand
—Confucius, 551–479 BC

  • Truth table representation
  • Canonical representation
  • Logic gates
    • Nand(a, b)
    • Not(in)
    • And(a, b)
    • Or(a, b)
    • Xor(a, b)
    • Mux(a, b, sel) multiplexor choose one from many
    • DMux(in, sel)
  • Signed Binary Number: Most computer systems today use the method called 2's complement, aka radix complement. In 2's complement of n bits, x + (minus) x = 2 to the n. With radix complement we don't need to care about substraction operation. We can substract with add operation. That's super cool. So we only need Adders chip.
    radix

  • HalfAdder

  • Full Adder

  • ALU

  • Combinational vs Sequential Logic
    comb-vs-seq

  • Data Flip-Flop (DFF) contains a clock input, a gate's input and a gate's output. DFF behavior is out(t) = in(t-1) where t is the current clock cycle.

  • 1-bit Register (Bit) is a storage device. It can store(remember) a value over time. Its behavior is out(t) = out(t-1)
    dff

  • Memory
    ram

  • A Instruction
    a
  • C Instruction
    a
  • Central Processing Unit (CPU) of Hack Computer

    • CPU Abstraction
      abstraction
    • CPU Implementation
      implementation
  • Hack Architecture
    hack


assembler

  • Symbols

    • Label symbols (In the program above LOOP and END are label symbols) are used to mark the memory location of the next instruction in the program. Label symbols are used for control flow in the program.
    • Variable symbols (In the program above i and sum are variable symbols) are treated as variable. Variables are mapped to consecutive memory locations.
  • Symbols table: Since Hack instructions can contain symbols, the symbols must be resolved into actual addresses.

    Symbol Memory location
    i 16
    sum 17
    LOOP 4
    END 18

    The table above is the symbol table for the program above. Since in Hack system we allocate memory for variable from memory 16 so the memory location for variable i will be 16 and sum will be 17. To specify label LOOP and END we count the number of instructions in the program so that LOOP will be4 and END will be 18.

The compilation of high-level programming language into a low-level one focuses on 2 main issues: data translation and command translation

11.1 Data translation

  • Variables For variables we need to care about some of its properties

    • type: integer, char, boolean, array, object
    • kind: field, static, local, argument
    • scope: class level, subroutine level
  • Symbol table: A data structure to keep track all identifiers. Whenever a new identifier is encountered for the first time the compiler adds its description to symbol table. Whennever an identifies is encountered elsewhere in the source code the compiler looks it up in symbol table and get all information needed from symbol table. Symbol Table

  • Handling variable

  • Handling object

  • Handling array

11.2 Command translation

  • Handling expression

  • Handling flow of control

  • Memory management
    • Heap management

nand2tetris's People

Contributors

vantamnguyen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  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.