AgustinPardo / Nand2Tetris

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.

  • 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

About

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


Languages

Language:Hack 57.8%Language:Assembly 23.7%Language:Scilab 7.9%Language:Java 5.8%Language:HTML 3.9%Language:Shell 0.4%Language:Batchfile 0.3%