Giter Site home page Giter Site logo

lysandert / nand2tetris Goto Github PK

View Code? Open in Web Editor NEW
4.0 1.0 0.0 51.46 MB

An archive of projects implemented by my self in the course series [Nand2Tetris](https://www.nand2tetris.org/). (mainly in c++)

Scilab 5.27% Assembly 15.16% Hack 75.33% C++ 1.15% HTML 2.56% Batchfile 0.22% Shell 0.29% Makefile 0.02%
assembler compiler cpp hdl nand2tetris os vmtranslator

nand2tetris's Introduction

Nand2Tetris

An archive of projects implemented by my self in the course series Nand2Tetris.

Key words: Nand2Tetris, HDL, Hack, Assembler, VMTranslator, Compiler, Jack, OS


Table of Contents

Highlighted Projects:

0x05

-> Hack Computer

A simple Computer with a CPU (ALU, registers), a Memory (RAM, SCREEN, KEYBOARD), and a ROM (instruction memory) that can run Hack Machine Language.

  • The computer process a fetch-decode-execute cycle and can handle I/O operations.
  • No pipelining, no cache, no virtual memory since this is not a architecture course.
  • implemented using HDL. (score: 100/100)

0x06

-> HackAssembler

A simple Assembler for the Hack Computer that can translate Hack Assembly Language to Hack Machine Language.

  • The Hack Assembly Language supports symbolic labels, symbolic variables, symbolic arithmetic and logical operations, jump instructions, register assignment, and I/O operations.
  • implemented using C++. (score: 100/100)

Compile command:

$ g++ -Wall -O2 -std=gnu++17 HackAssembler.cpp -o HackAssembler 

Usage:

$ ./HackAssembler <fileName.asm>

0x07 & 0x08

-> VMTranslator

A VM-to-Hack Translator that can translate VM Language to Hack Assembly Language.

Consist of a parser and a code generator.

  • The VM Language supports arithmetic and logical operations, memory access, program flow, function calling, and function return using stack frames.
  • implemented using C++. (score: 200/200)

Compile command:

$ make
# can clean the .o files & the VMTranslator file using:
$ make clean

Usage:

$ ./VMTranslator <fileName.vm>
# or
$ ./VMTranslator <dirName>

0x0A & 0x0B

-> JackCompiler

A Jack-to-VM Compiler that can translate Jack Language to VM Language.

  • Jack is a high level language that supports class (constructor, method, function), variable (static, field, argument, local), types (int, char, boolean, class), statements (let, if, while, do, return), expressions (term, unaryOp, binaryOp) and so on.
  • Implemented using C++. (score: 200/200)
# structure 
JackCompiler
│
├── JackAnalyzer
│   │
│   ├── Tokenizer
│   │
|   └── CompilationEngine
|
└── VMWriter

Debugging

  1. add -g option when compiling the code.
  2. use the following command to trigger the debugger:
# on x86_64
$ gdb <executable file> <core dump file>
# or on arm64 (mac m1)
$ lldb <executable file> <core dump file>

Testing

use the .sh scripts in tools to test your code.

# e.g.
$ ./tools/HardwareSimulator.sh

If your code is right, it will output "End of script - Comparison ended successfully".

Or you can use the following command to compare the difference between two files:

$ diff file1 file2

this command will compare the difference between file1 and file2. If there is no difference, it will not output anything.

for example in project00:

$ diff Mux16.out Mux16.cmp -b 

the -b option will ignore the blank space. You can also use -B to ignore the blank line.

Certificate

&part1

&[part2]

nand2tetris's People

Contributors

lysandert avatar

Stargazers

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