├── .gitignore ├── LICENSE ├── README.md ├── docs ├── .gitbook.yaml ├── README.md └── SUMMARY.md ├── projects ├── 10 │ ├── ArrayTest │ │ ├── Main.jack │ │ ├── Main.xml │ │ ├── MainT.xml │ │ └── output │ │ │ └── Main.xml │ ├── ExpressionlessSquare │ │ ├── Main.jack │ │ ├── Main.xml │ │ ├── MainT.xml │ │ ├── Square.jack │ │ ├── Square.xml │ │ ├── SquareGame.jack │ │ ├── SquareGame.xml │ │ ├── SquareGameT.xml │ │ ├── SquareT.xml │ │ └── output │ │ │ ├── Main.xml │ │ │ ├── Square.xml │ │ │ └── SquareGame.xml │ ├── JackAnalyzer.jar │ ├── JackAnalyzer │ │ ├── .classpath │ │ ├── .project │ │ ├── META-INF │ │ │ └── MANIFEST.MF │ │ └── org │ │ │ └── reion │ │ │ ├── CompilationEngine.java │ │ │ ├── JackAnalyzer.java │ │ │ ├── JackTokenizer.java │ │ │ └── XmlUtils.java │ └── Square │ │ ├── Main.jack │ │ ├── Main.xml │ │ ├── MainT.xml │ │ ├── Square.jack │ │ ├── Square.xml │ │ ├── SquareGame.jack │ │ ├── SquareGame.xml │ │ ├── SquareGameT.xml │ │ ├── SquareT.xml │ │ └── output │ │ ├── Main.xml │ │ ├── Square.xml │ │ └── SquareGame.xml ├── 11 │ ├── Average │ │ ├── Main.jack │ │ └── output │ │ │ └── Main.vm │ ├── ComplexArrays │ │ ├── Main.jack │ │ └── output │ │ │ └── Main.vm │ ├── ConvertToBin │ │ ├── Main.jack │ │ └── output │ │ │ └── Main.vm │ ├── JackCompiler.jar │ ├── JackCompiler │ │ ├── META-INF │ │ │ └── MANIFEST.MF │ │ └── org │ │ │ └── reion │ │ │ ├── CompilationEngine.java │ │ │ ├── JackCompiler.java │ │ │ ├── JackTokenizer.java │ │ │ ├── SymbolTabel.java │ │ │ └── VMWriter.java │ ├── Pong │ │ ├── Ball.jack │ │ ├── Bat.jack │ │ ├── Main.jack │ │ ├── PongGame.jack │ │ └── output │ │ │ ├── Ball.vm │ │ │ ├── Bat.vm │ │ │ ├── Main.vm │ │ │ └── PongGame.vm │ ├── Seven │ │ ├── Main.jack │ │ └── output │ │ │ └── Main.vm │ └── Square │ │ ├── Main.jack │ │ ├── Square.jack │ │ ├── SquareGame.jack │ │ └── output │ │ ├── Main.vm │ │ ├── Square.vm │ │ └── SquareGame.vm ├── 12 │ ├── Array.jack │ ├── ArrayTest │ │ ├── ArrayTest.cmp │ │ ├── ArrayTest.tst │ │ └── Main.jack │ ├── Keyboard.jack │ ├── KeyboardTest │ │ ├── KeyboardTestOutput.gif │ │ └── Main.jack │ ├── Math.jack │ ├── MathTest │ │ ├── Main.jack │ │ ├── MathTest.cmp │ │ └── MathTest.tst │ ├── Memory.jack │ ├── MemoryTest │ │ ├── Main.jack │ │ ├── MemoryTest.cmp │ │ └── MemoryTest.tst │ ├── Output.jack │ ├── OutputTest │ │ ├── Main.jack │ │ └── OutputTestOutput.gif │ ├── Screen.jack │ ├── ScreenTest │ │ ├── Main.jack │ │ └── ScreenTestOutput.gif │ ├── String.jack │ ├── StringTest │ │ ├── Main.jack │ │ └── StringTestOutput.gif │ ├── Sys.jack │ └── SysTest │ │ └── Main.jack ├── 13 │ └── more fun to go.txt ├── 00 │ └── Xor.hdl ├── 01 │ ├── And.cmp │ ├── And.hdl │ ├── And.out │ ├── And.tst │ ├── And16.cmp │ ├── And16.hdl │ ├── And16.out │ ├── And16.tst │ ├── DMux.cmp │ ├── DMux.hdl │ ├── DMux.out │ ├── DMux.tst │ ├── DMux4Way.cmp │ ├── DMux4Way.hdl │ ├── DMux4Way.out │ ├── DMux4Way.tst │ ├── DMux8Way.cmp │ ├── DMux8Way.hdl │ ├── DMux8Way.out │ ├── DMux8Way.tst │ ├── Mux.cmp │ ├── Mux.hdl │ ├── Mux.out │ ├── Mux.tst │ ├── Mux16.cmp │ ├── Mux16.hdl │ ├── Mux16.out │ ├── Mux16.tst │ ├── Mux4Way16.cmp │ ├── Mux4Way16.hdl │ ├── Mux4Way16.out │ ├── Mux4Way16.tst │ ├── Mux8Way16.cmp │ ├── Mux8Way16.hdl │ ├── Mux8Way16.out │ ├── Mux8Way16.tst │ ├── Not.cmp │ ├── Not.hdl │ ├── Not.out │ ├── Not.tst │ ├── Not16.cmp │ ├── Not16.hdl │ ├── Not16.out │ ├── Not16.tst │ ├── Or.cmp │ ├── Or.hdl │ ├── Or.out │ ├── Or.tst │ ├── Or16.cmp │ ├── Or16.hdl │ ├── Or16.out │ ├── Or16.tst │ ├── Or8Way.cmp │ ├── Or8Way.hdl │ ├── Or8Way.out │ ├── Or8Way.tst │ ├── Xor.cmp │ ├── Xor.hdl │ ├── Xor.out │ └── Xor.tst ├── 02 │ ├── ALU-nostat.cmp │ ├── ALU-nostat.tst │ ├── ALU.cmp │ ├── ALU.hdl │ ├── ALU.out │ ├── ALU.tst │ ├── Add16.cmp │ ├── Add16.hdl │ ├── Add16.out │ ├── Add16.tst │ ├── FullAdder.cmp │ ├── FullAdder.hdl │ ├── FullAdder.out │ ├── FullAdder.tst │ ├── HalfAdder.cmp │ ├── HalfAdder.hdl │ ├── HalfAdder.out │ ├── HalfAdder.tst │ ├── Inc16.cmp │ ├── Inc16.hdl │ ├── Inc16.out │ ├── Inc16.tst │ └── Or16Way.hdl ├── 03 │ ├── a │ │ ├── Bit.cmp │ │ ├── Bit.hdl │ │ ├── Bit.out │ │ ├── Bit.tst │ │ ├── PC.cmp │ │ ├── PC.hdl │ │ ├── PC.out │ │ ├── PC.tst │ │ ├── RAM64.cmp │ │ ├── RAM64.hdl │ │ ├── RAM64.out │ │ ├── RAM64.tst │ │ ├── RAM8.cmp │ │ ├── RAM8.hdl │ │ ├── RAM8.out │ │ ├── RAM8.tst │ │ ├── Register.cmp │ │ ├── Register.hdl │ │ ├── Register.out │ │ └── Register.tst │ └── b │ │ ├── RAM16K.cmp │ │ ├── RAM16K.hdl │ │ ├── RAM16K.out │ │ ├── RAM16K.tst │ │ ├── RAM4K.cmp │ │ ├── RAM4K.hdl │ │ ├── RAM4K.out │ │ ├── RAM4K.tst │ │ ├── RAM512.cmp │ │ ├── RAM512.hdl │ │ ├── RAM512.out │ │ └── RAM512.tst ├── 04 │ ├── fill │ │ ├── Fill.asm │ │ ├── Fill.hack │ │ └── Fill.tst │ └── mult │ │ ├── Mult.asm │ │ ├── Mult.cmp │ │ ├── Mult.hack │ │ ├── Mult.out │ │ └── Mult.tst ├── 05 │ ├── Add.hack │ ├── CPU-external.cmp │ ├── CPU-external.out │ ├── CPU-external.tst │ ├── CPU.cmp │ ├── CPU.hdl │ ├── CPU.out │ ├── CPU.tst │ ├── Computer.hdl │ ├── ComputerAdd-external.cmp │ ├── ComputerAdd-external.out │ ├── ComputerAdd-external.tst │ ├── ComputerAdd.cmp │ ├── ComputerAdd.out │ ├── ComputerAdd.tst │ ├── ComputerMax-external.cmp │ ├── ComputerMax-external.out │ ├── ComputerMax-external.tst │ ├── ComputerMax.cmp │ ├── ComputerMax.tst │ ├── ComputerRect-external.cmp │ ├── ComputerRect-external.out │ ├── ComputerRect-external.tst │ ├── ComputerRect.cmp │ ├── ComputerRect.out │ ├── ComputerRect.tst │ ├── Max.hack │ ├── Memory.cmp │ ├── Memory.hdl │ ├── Memory.out │ ├── Memory.tst │ ├── Or16Way.hdl │ └── Rect.hack ├── 06 │ ├── Assembler.jar │ ├── Assembler │ │ ├── .classpath │ │ ├── .project │ │ ├── META-INF │ │ │ └── MANIFEST.MF │ │ └── org │ │ │ └── reion │ │ │ ├── Assembler.java │ │ │ ├── Code.java │ │ │ ├── Parser.java │ │ │ └── SymbolTable.java │ ├── add │ │ ├── Add.asm │ │ └── Add.hack │ ├── max │ │ ├── Max.asm │ │ ├── Max.hack │ │ ├── MaxL.asm │ │ └── MaxL.hack │ ├── pong │ │ ├── Pong.asm │ │ ├── Pong.hack │ │ ├── PongL.asm │ │ └── PongL.hack │ └── rect │ │ ├── Rect.asm │ │ ├── Rect.hack │ │ ├── RectL.asm │ │ └── RectL.hack ├── 07 │ ├── MemoryAccess │ │ ├── BasicTest │ │ │ ├── BasicTest.asm │ │ │ ├── BasicTest.cmp │ │ │ ├── BasicTest.out │ │ │ ├── BasicTest.tst │ │ │ ├── BasicTest.vm │ │ │ └── BasicTestVME.tst │ │ ├── PointerTest │ │ │ ├── PointerTest.asm │ │ │ ├── PointerTest.cmp │ │ │ ├── PointerTest.out │ │ │ ├── PointerTest.tst │ │ │ ├── PointerTest.vm │ │ │ └── PointerTestVME.tst │ │ └── StaticTest │ │ │ ├── StaticTest.asm │ │ │ ├── StaticTest.cmp │ │ │ ├── StaticTest.out │ │ │ ├── StaticTest.tst │ │ │ ├── StaticTest.vm │ │ │ └── StaticTestVME.tst │ ├── StackArithmetic │ │ ├── SimpleAdd │ │ │ ├── SimpleAdd.asm │ │ │ ├── SimpleAdd.cmp │ │ │ ├── SimpleAdd.out │ │ │ ├── SimpleAdd.tst │ │ │ ├── SimpleAdd.vm │ │ │ └── SimpleAddVME.tst │ │ └── StackTest │ │ │ ├── StackTest.asm │ │ │ ├── StackTest.cmp │ │ │ ├── StackTest.out │ │ │ ├── StackTest.tst │ │ │ ├── StackTest.vm │ │ │ └── StackTestVME.tst │ ├── VMTranslator.jar │ └── VMTranslator │ │ ├── .classpath │ │ ├── .project │ │ ├── META-INF │ │ └── MANIFEST.MF │ │ └── org │ │ └── reion │ │ ├── CodeWriter.java │ │ ├── Parser.java │ │ └── VMTranslator.java ├── 08 │ ├── FunctionCalls │ │ ├── FibonacciElement │ │ │ ├── FibonacciElement.asm │ │ │ ├── FibonacciElement.cmp │ │ │ ├── FibonacciElement.out │ │ │ ├── FibonacciElement.tst │ │ │ ├── FibonacciElementVME.tst │ │ │ ├── Main.vm │ │ │ └── Sys.vm │ │ ├── NestedCall │ │ │ ├── NestedCall.asm │ │ │ ├── NestedCall.cmp │ │ │ ├── NestedCall.html │ │ │ ├── NestedCall.out │ │ │ ├── NestedCall.tst │ │ │ ├── NestedCallStack.html │ │ │ ├── NestedCallVME.tst │ │ │ └── Sys.vm │ │ ├── SimpleFunction │ │ │ ├── SimpleFunction.asm │ │ │ ├── SimpleFunction.cmp │ │ │ ├── SimpleFunction.out │ │ │ ├── SimpleFunction.tst │ │ │ ├── SimpleFunction.vm │ │ │ └── SimpleFunctionVME.tst │ │ └── StaticsTest │ │ │ ├── Class1.vm │ │ │ ├── Class2.vm │ │ │ ├── StaticsTest.asm │ │ │ ├── StaticsTest.cmp │ │ │ ├── StaticsTest.out │ │ │ ├── StaticsTest.tst │ │ │ ├── StaticsTestVME.tst │ │ │ └── Sys.vm │ ├── ProgramFlow │ │ ├── BasicLoop │ │ │ ├── BasicLoop.asm │ │ │ ├── BasicLoop.cmp │ │ │ ├── BasicLoop.out │ │ │ ├── BasicLoop.tst │ │ │ ├── BasicLoop.vm │ │ │ └── BasicLoopVME.tst │ │ └── FibonacciSeries │ │ │ ├── FibonacciSeries.asm │ │ │ ├── FibonacciSeries.cmp │ │ │ ├── FibonacciSeries.out │ │ │ ├── FibonacciSeries.tst │ │ │ ├── FibonacciSeries.vm │ │ │ └── FibonacciSeriesVME.tst │ ├── VMTranslator.jar │ └── VMTranslator │ │ ├── .classpath │ │ ├── .project │ │ ├── META-INF │ │ └── MANIFEST.MF │ │ └── org │ │ └── reion │ │ ├── CodeWriter.java │ │ ├── Parser.java │ │ └── VMTranslator.java └── 09 │ ├── CountdownTimer │ ├── Countdown.gif │ ├── CountdownTimer.jack │ ├── CountdownTimer.vm │ ├── Main.jack │ └── Main.vm │ ├── Hello │ ├── Hello.gif │ ├── Hello.jack │ ├── Hello.vm │ ├── Main.jack │ └── Main.vm │ ├── Jack OS API.pdf │ ├── RollingBall │ ├── Ball1.jack │ ├── Ball1.vm │ ├── Ball2.jack │ ├── Ball2.vm │ ├── Ball3.jack │ ├── Ball3.vm │ ├── Ball4.jack │ ├── Ball4.vm │ ├── Ball5.jack │ ├── Ball5.vm │ ├── Ball6.jack │ ├── Ball6.vm │ ├── Ball7.jack │ ├── Ball7.vm │ ├── Ball8.jack │ ├── Ball8.vm │ ├── Main.jack │ ├── Main.vm │ ├── RollingBall.gif │ ├── RollingBall.jack │ ├── RollingBall.vm │ ├── Shadow1.jack │ ├── Shadow1.vm │ ├── Shadow2.jack │ ├── Shadow2.vm │ ├── Shadow3.jack │ ├── Shadow3.vm │ ├── Shadow4.jack │ ├── Shadow4.vm │ ├── Shadow5.jack │ ├── Shadow5.vm │ ├── Shadow6.jack │ ├── Shadow6.vm │ ├── Shadow7.jack │ ├── Shadow7.vm │ ├── Shadow8.jack │ └── Shadow8.vm │ └── Square │ ├── Main.jack │ ├── Main.vm │ ├── Square.gif │ ├── Square.jack │ ├── Square.vm │ ├── SquareGame.jack │ └── SquareGame.vm ├── res ├── pdf.png ├── ppt.png └── youtube.png └── tools ├── Assembler.bat ├── Assembler.sh ├── CPUEmulator.bat ├── CPUEmulator.sh ├── HardwareSimulator.bat ├── HardwareSimulator.sh ├── JackCompiler.bat ├── JackCompiler.sh ├── OS ├── Array.vm ├── Keyboard.vm ├── Math.vm ├── Memory.vm ├── Output.vm ├── Screen.vm ├── String.vm └── Sys.vm ├── TextComparer.bat ├── TextComparer.sh ├── VMEmulator.bat ├── VMEmulator.sh ├── bin ├── CPU Emulator.dat ├── Virtual Machine Emulator.dat ├── classes │ ├── CPUEmulatorMain.class │ ├── HackAssemblerMain.class │ ├── HardwareSimulatorMain.class │ ├── TextComparer.class │ └── VMEmulatorMain.class ├── help │ ├── asmAbout.html │ ├── asmUsage.html │ ├── compiler.txt │ ├── cpuAbout.html │ ├── cpuUsage.html │ ├── hwAbout.html │ ├── hwUsage.html │ ├── vmAbout.html │ └── vmUsage.html ├── images │ ├── arrow2.gif │ ├── calculator2.gif │ ├── cancel.gif │ ├── chip.gif │ ├── clock2.gif │ ├── equal.gif │ ├── find.gif │ ├── hex.gif │ ├── keyboard.gif │ ├── ok.gif │ ├── ok2.gif │ ├── open.gif │ ├── open2.gif │ ├── opendoc.gif │ ├── redflag.gif │ ├── save.gif │ ├── scroll.gif │ ├── smallcancel.gif │ ├── smallequal.gif │ ├── smallminus.gif │ ├── smallnew.gif │ ├── smallok.gif │ ├── smallplus.gif │ ├── vcrfastforward.gif │ ├── vcrforward.gif │ ├── vcrrewind.gif │ └── vcrstop.gif ├── lib │ ├── AssemblerGUI.jar │ ├── Compilers.jar │ ├── Hack.jar │ ├── HackGUI.jar │ ├── Simulators.jar │ ├── SimulatorsGUI.jar │ └── TranslatorsGUI.jar └── scripts │ ├── defaultCPU.txt │ ├── defaultHW.txt │ └── defaultVM.txt ├── builtInChips ├── ALU.class ├── ALU.hdl ├── ARegister.class ├── ARegister.hdl ├── Add16.class ├── Add16.hdl ├── And.class ├── And.hdl ├── And16.hdl ├── Bit.class ├── Bit.hdl ├── DFF.class ├── DFF.hdl ├── DMux.class ├── DMux.hdl ├── DMux4Way.class ├── DMux4Way.hdl ├── DMux8Way.class ├── DMux8Way.hdl ├── DRegister.class ├── DRegister.hdl ├── FullAdder.class ├── FullAdder.hdl ├── HalfAdder.class ├── HalfAdder.hdl ├── Inc16.class ├── Inc16.hdl ├── Keyboard.class ├── Keyboard.hdl ├── Mux.class ├── Mux.hdl ├── Mux16.hdl ├── Mux4Way16.class ├── Mux4Way16.hdl ├── Mux8Way16.class ├── Mux8Way16.hdl ├── Nand.class ├── Nand.hdl ├── Not.class ├── Not.hdl ├── Not16.class ├── Not16.hdl ├── Or.class ├── Or.hdl ├── Or16.hdl ├── Or8Way.class ├── Or8Way.hdl ├── PC.class ├── PC.hdl ├── RAM.class ├── RAM16K.class ├── RAM16K.hdl ├── RAM4K.class ├── RAM4K.hdl ├── RAM512.class ├── RAM512.hdl ├── RAM64.class ├── RAM64.hdl ├── RAM8.class ├── RAM8.hdl ├── ROM32K.class ├── ROM32K.hdl ├── Register.class ├── Register.hdl ├── RegisterWithGUI.class ├── Screen.class ├── Screen.hdl ├── Xor.class └── Xor.hdl └── builtInVMCode ├── Array.class ├── JackOSClass.class ├── Keyboard.class ├── Math.class ├── Memory.class ├── Output.class ├── Screen.class ├── String.class └── Sys.class /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | .DS_Store 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![](https://img.shields.io/badge/license-GPL--3.0-blue.svg)](https://raw.githubusercontent.com/ReionChan/nand2tetris/master/LICENSE) 2 | 3 | nand2tetris 4 | ================================================ 5 | 6 | [*The Elements of Computing Systems : Building a Modern Computer from First Principles*](http://www.amazon.com/Elements-Computing-Systems-Building-Principles/dp/0262640686/ref=ed_oe_p "Buy")   7 | 8 | This repo contains 12 projects, each of which is the post-lesson assignment in the book mentioned above. For more information on each project, please click on the following link: 9 | 10 | [English](https://reionchan.github.io/2016/05/28/nand2tetris-en_US) 11 | 12 | ---- 13 | [《计算机系统要素-从零开始构建现代计算机》](http://www.amazon.com/Elements-Computing-Systems-Building-Principles/dp/0262640686/ref=ed_oe_p "购买") 14 | 15 | 此代码库包含12个项目,每个项目都来源于上面提及的这部书的每个章节的课后练习。 16 | 请点击下面链接来获取每个项目的详细信息: 17 | 18 | [中文](https://reionchan.github.io/2016/05/28/nand2tetris-zh_CN/) 19 | -------------------------------------------------------------------------------- /docs/.gitbook.yaml: -------------------------------------------------------------------------------- 1 | # Root directory to locate the content 2 | # Default is the root directory of the repository. 3 | root: docs/ 4 | 5 | # Files to use as SUMMARY/README. 6 | # (Relative to directory) 7 | structure: 8 | readme: README.md 9 | summary: SUMMARY.md 10 | 11 | # Redirect urls to specific files (relative to the directory) 12 | redirects: 13 | previous/page: new-folder/page.md -------------------------------------------------------------------------------- /docs/README.md: -------------------------------------------------------------------------------- 1 | [![](https://img.shields.io/badge/license-GPL--3.0-blue.svg)](https://raw.githubusercontent.com/ReionChan/nand2tetris/master/LICENSE) 2 | 3 | nand2tetris 4 | ================================================ 5 | 6 | [*The Elements of Computing Systems : Building a Modern Computer from First Principles*](http://www.amazon.com/Elements-Computing-Systems-Building-Principles/dp/0262640686/ref=ed_oe_p "Buy")   7 | 8 | This repo contains 12 projects, each of which is the post-lesson assignment in the book mentioned above. For more information on each project, please click on the following link: 9 | 10 | [English](https://reionchan.github.io/2016/05/28/nand2tetris-en_US) 11 | 12 | ---- 13 | [《计算机系统要素-从零开始构建现代计算机》](http://www.amazon.com/Elements-Computing-Systems-Building-Principles/dp/0262640686/ref=ed_oe_p "购买") 14 | 15 | 此代码库包含12个项目,每个项目都来源于上面提及的这部书的每个章节的课后练习。 16 | 请点击下面链接来获取每个项目的详细信息: 17 | 18 | [中文](https://reionchan.github.io/2016/05/28/nand2tetris-zh_CN/) 19 | -------------------------------------------------------------------------------- /docs/SUMMARY.md: -------------------------------------------------------------------------------- 1 | [![](https://img.shields.io/badge/license-GPL--3.0-blue.svg)](https://raw.githubusercontent.com/ReionChan/nand2tetris/master/LICENSE) 2 | 3 | nand2tetris 4 | ================================================ 5 | 6 | [*The Elements of Computing Systems : Building a Modern Computer from First Principles*](http://www.amazon.com/Elements-Computing-Systems-Building-Principles/dp/0262640686/ref=ed_oe_p "Buy")   7 | 8 | This repo contains 12 projects, each of which is the post-lesson assignment in the book mentioned above. For more information on each project, please click on the following link: 9 | 10 | [English](https://reionchan.github.io/2016/05/28/nand2tetris-en_US) 11 | 12 | ---- 13 | [《计算机系统要素-从零开始构建现代计算机》](http://www.amazon.com/Elements-Computing-Systems-Building-Principles/dp/0262640686/ref=ed_oe_p "购买") 14 | 15 | 此代码库包含12个项目,每个项目都来源于上面提及的这部书的每个章节的课后练习。 16 | 请点击下面链接来获取每个项目的详细信息: 17 | 18 | [中文](https://reionchan.github.io/2016/05/28/nand2tetris-zh_CN/) 19 | -------------------------------------------------------------------------------- /projects/00/Xor.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | 5 | /** 6 | * Exclusive-or gate: out = !(a == b). 7 | */ 8 | 9 | CHIP Xor { 10 | 11 | IN a, b; 12 | OUT out; 13 | 14 | PARTS: 15 | Nand (a=a, b=b, out= AnandB); 16 | Or (a=a, b=b, out= AorB); 17 | And (a=AnandB, b=AorB, out=out); 18 | } 19 | -------------------------------------------------------------------------------- /projects/01/And.cmp: -------------------------------------------------------------------------------- 1 | | a | b | out | 2 | | 0 | 0 | 0 | 3 | | 0 | 1 | 0 | 4 | | 1 | 0 | 0 | 5 | | 1 | 1 | 1 | 6 | -------------------------------------------------------------------------------- /projects/01/And.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/01/And.hdl 5 | 6 | /** 7 | * And gate: 8 | * out = 1 if (a == 1 and b == 1) 9 | * 0 otherwise 10 | */ 11 | 12 | CHIP And { 13 | IN a, b; 14 | OUT out; 15 | 16 | PARTS: 17 | // Put your code here: 18 | Nand(a=a, b=b, out=notand); 19 | Not(in=notand, out=out); 20 | } 21 | -------------------------------------------------------------------------------- /projects/01/And.out: -------------------------------------------------------------------------------- 1 | | a | b | out | 2 | | 0 | 0 | 0 | 3 | | 0 | 1 | 0 | 4 | | 1 | 0 | 0 | 5 | | 1 | 1 | 1 | 6 | -------------------------------------------------------------------------------- /projects/01/And.tst: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/01/And.tst 5 | 6 | load And.hdl, 7 | output-file And.out, 8 | compare-to And.cmp, 9 | output-list a%B3.1.3 b%B3.1.3 out%B3.1.3; 10 | 11 | set a 0, 12 | set b 0, 13 | eval, 14 | output; 15 | 16 | set a 0, 17 | set b 1, 18 | eval, 19 | output; 20 | 21 | set a 1, 22 | set b 0, 23 | eval, 24 | output; 25 | 26 | set a 1, 27 | set b 1, 28 | eval, 29 | output; 30 | -------------------------------------------------------------------------------- /projects/01/And16.cmp: -------------------------------------------------------------------------------- 1 | | a | b | out | 2 | | 0000000000000000 | 0000000000000000 | 0000000000000000 | 3 | | 0000000000000000 | 1111111111111111 | 0000000000000000 | 4 | | 1111111111111111 | 1111111111111111 | 1111111111111111 | 5 | | 1010101010101010 | 0101010101010101 | 0000000000000000 | 6 | | 0011110011000011 | 0000111111110000 | 0000110011000000 | 7 | | 0001001000110100 | 1001100001110110 | 0001000000110100 | 8 | -------------------------------------------------------------------------------- /projects/01/And16.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/01/And16.hdl 5 | 6 | /** 7 | * 16-bit bitwise And: 8 | * for i = 0..15: out[i] = (a[i] and b[i]) 9 | */ 10 | 11 | CHIP And16 { 12 | IN a[16], b[16]; 13 | OUT out[16]; 14 | 15 | PARTS: 16 | // Put your code here: 17 | And(a=a[0], b=b[0], out=out[0]); 18 | And(a=a[1], b=b[1], out=out[1]); 19 | And(a=a[2], b=b[2], out=out[2]); 20 | And(a=a[3], b=b[3], out=out[3]); 21 | And(a=a[4], b=b[4], out=out[4]); 22 | And(a=a[5], b=b[5], out=out[5]); 23 | And(a=a[6], b=b[6], out=out[6]); 24 | And(a=a[7], b=b[7], out=out[7]); 25 | And(a=a[8], b=b[8], out=out[8]); 26 | And(a=a[9], b=b[9], out=out[9]); 27 | And(a=a[10], b=b[10], out=out[10]); 28 | And(a=a[11], b=b[11], out=out[11]); 29 | And(a=a[12], b=b[12], out=out[12]); 30 | And(a=a[13], b=b[13], out=out[13]); 31 | And(a=a[14], b=b[14], out=out[14]); 32 | And(a=a[15], b=b[15], out=out[15]); 33 | } 34 | -------------------------------------------------------------------------------- /projects/01/And16.out: -------------------------------------------------------------------------------- 1 | | a | b | out | 2 | | 0000000000000000 | 0000000000000000 | 0000000000000000 | 3 | | 0000000000000000 | 1111111111111111 | 0000000000000000 | 4 | | 1111111111111111 | 1111111111111111 | 1111111111111111 | 5 | | 1010101010101010 | 0101010101010101 | 0000000000000000 | 6 | | 0011110011000011 | 0000111111110000 | 0000110011000000 | 7 | | 0001001000110100 | 1001100001110110 | 0001000000110100 | 8 | -------------------------------------------------------------------------------- /projects/01/And16.tst: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/01/And16.tst 5 | 6 | load And16.hdl, 7 | output-file And16.out, 8 | compare-to And16.cmp, 9 | output-list a%B1.16.1 b%B1.16.1 out%B1.16.1; 10 | 11 | set a %B0000000000000000, 12 | set b %B0000000000000000, 13 | eval, 14 | output; 15 | 16 | set a %B0000000000000000, 17 | set b %B1111111111111111, 18 | eval, 19 | output; 20 | 21 | set a %B1111111111111111, 22 | set b %B1111111111111111, 23 | eval, 24 | output; 25 | 26 | set a %B1010101010101010, 27 | set b %B0101010101010101, 28 | eval, 29 | output; 30 | 31 | set a %B0011110011000011, 32 | set b %B0000111111110000, 33 | eval, 34 | output; 35 | 36 | set a %B0001001000110100, 37 | set b %B1001100001110110, 38 | eval, 39 | output; -------------------------------------------------------------------------------- /projects/01/DMux.cmp: -------------------------------------------------------------------------------- 1 | | in | sel | a | b | 2 | | 0 | 0 | 0 | 0 | 3 | | 0 | 1 | 0 | 0 | 4 | | 1 | 0 | 1 | 0 | 5 | | 1 | 1 | 0 | 1 | 6 | -------------------------------------------------------------------------------- /projects/01/DMux.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/01/DMux.hdl 5 | 6 | /** 7 | * Demultiplexor: 8 | * {a, b} = {in, 0} if sel == 0 9 | * {0, in} if sel == 1 10 | */ 11 | 12 | CHIP DMux { 13 | IN in, sel; 14 | OUT a, b; 15 | 16 | PARTS: 17 | // Put your code here: 18 | Not(in=sel, out=nsel); 19 | And(a=nsel, b=in, out=a); 20 | And(a=sel, b=in, out=b); 21 | } 22 | -------------------------------------------------------------------------------- /projects/01/DMux.out: -------------------------------------------------------------------------------- 1 | | in | sel | a | b | 2 | | 0 | 0 | 0 | 0 | 3 | | 0 | 1 | 0 | 0 | 4 | | 1 | 0 | 1 | 0 | 5 | | 1 | 1 | 0 | 1 | 6 | -------------------------------------------------------------------------------- /projects/01/DMux.tst: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/01/DMux.tst 5 | 6 | load DMux.hdl, 7 | output-file DMux.out, 8 | compare-to DMux.cmp, 9 | output-list in%B3.1.3 sel%B3.1.3 a%B3.1.3 b%B3.1.3; 10 | 11 | set in 0, 12 | set sel 0, 13 | eval, 14 | output; 15 | 16 | set sel 1, 17 | eval, 18 | output; 19 | 20 | set in 1, 21 | set sel 0, 22 | eval, 23 | output; 24 | 25 | set sel 1, 26 | eval, 27 | output; 28 | -------------------------------------------------------------------------------- /projects/01/DMux4Way.cmp: -------------------------------------------------------------------------------- 1 | | in | sel | a | b | c | d | 2 | | 0 | 00 | 0 | 0 | 0 | 0 | 3 | | 0 | 01 | 0 | 0 | 0 | 0 | 4 | | 0 | 10 | 0 | 0 | 0 | 0 | 5 | | 0 | 11 | 0 | 0 | 0 | 0 | 6 | | 1 | 00 | 1 | 0 | 0 | 0 | 7 | | 1 | 01 | 0 | 1 | 0 | 0 | 8 | | 1 | 10 | 0 | 0 | 1 | 0 | 9 | | 1 | 11 | 0 | 0 | 0 | 1 | 10 | -------------------------------------------------------------------------------- /projects/01/DMux4Way.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/01/DMux4Way.hdl 5 | 6 | /** 7 | * 4-way demultiplexor: 8 | * {a, b, c, d} = {in, 0, 0, 0} if sel == 00 9 | * {0, in, 0, 0} if sel == 01 10 | * {0, 0, in, 0} if sel == 10 11 | * {0, 0, 0, in} if sel == 11 12 | */ 13 | 14 | CHIP DMux4Way { 15 | IN in, sel[2]; 16 | OUT a, b, c, d; 17 | 18 | PARTS: 19 | // Put your code here: 20 | DMux(in=in, sel=sel[0], a=selac, b=selbd); 21 | DMux(in=selac, sel=sel[1], a=a, b=c); 22 | DMux(in=selbd, sel=sel[1], a=b, b=d); 23 | 24 | } 25 | -------------------------------------------------------------------------------- /projects/01/DMux4Way.out: -------------------------------------------------------------------------------- 1 | | in | sel | a | b | c | d | 2 | | 0 | 00 | 0 | 0 | 0 | 0 | 3 | | 0 | 01 | 0 | 0 | 0 | 0 | 4 | | 0 | 10 | 0 | 0 | 0 | 0 | 5 | | 0 | 11 | 0 | 0 | 0 | 0 | 6 | | 1 | 00 | 1 | 0 | 0 | 0 | 7 | | 1 | 01 | 0 | 1 | 0 | 0 | 8 | | 1 | 10 | 0 | 0 | 1 | 0 | 9 | | 1 | 11 | 0 | 0 | 0 | 1 | 10 | -------------------------------------------------------------------------------- /projects/01/DMux4Way.tst: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/01/DMux4Way.tst 5 | 6 | load DMux4Way.hdl, 7 | output-file DMux4Way.out, 8 | compare-to DMux4Way.cmp, 9 | output-list in%B2.1.2 sel%B2.2.2 a%B2.1.2 b%B2.1.2 c%B2.1.2 d%B2.1.2; 10 | 11 | set in 0, 12 | set sel %B00, 13 | eval, 14 | output; 15 | 16 | set sel %B01, 17 | eval, 18 | output; 19 | 20 | set sel %B10, 21 | eval, 22 | output; 23 | 24 | set sel %B11, 25 | eval, 26 | output; 27 | 28 | set in 1, 29 | set sel %B00, 30 | eval, 31 | output; 32 | 33 | set sel %B01, 34 | eval, 35 | output; 36 | 37 | set sel %B10, 38 | eval, 39 | output; 40 | 41 | set sel %B11, 42 | eval, 43 | output; 44 | -------------------------------------------------------------------------------- /projects/01/DMux8Way.cmp: -------------------------------------------------------------------------------- 1 | | in | sel | a | b | c | d | e | f | g | h | 2 | | 0 | 000 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 3 | | 0 | 001 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 4 | | 0 | 010 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 5 | | 0 | 011 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 6 | | 0 | 100 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 7 | | 0 | 101 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 8 | | 0 | 110 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 9 | | 0 | 111 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 10 | | 1 | 000 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 11 | | 1 | 001 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 12 | | 1 | 010 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 13 | | 1 | 011 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 14 | | 1 | 100 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 15 | | 1 | 101 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 16 | | 1 | 110 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 17 | | 1 | 111 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 18 | -------------------------------------------------------------------------------- /projects/01/DMux8Way.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/01/DMux8Way.hdl 5 | 6 | /** 7 | * 8-way demultiplexor: 8 | * {a, b, c, d, e, f, g, h} = {in, 0, 0, 0, 0, 0, 0, 0} if sel == 000 9 | * {0, in, 0, 0, 0, 0, 0, 0} if sel == 001 10 | * etc. 11 | * {0, 0, 0, 0, 0, 0, 0, in} if sel == 111 12 | */ 13 | 14 | CHIP DMux8Way { 15 | IN in, sel[3]; 16 | OUT a, b, c, d, e, f, g, h; 17 | 18 | PARTS: 19 | // Put your code here: 20 | DMux(in=in, sel=sel[0], a=selaceg, b=selbdfh); 21 | DMux(in=selaceg, sel=sel[1], a=selae, b=selcg); 22 | DMux(in=selbdfh, sel=sel[1], a=selbf, b=seldh); 23 | 24 | DMux(in=selae, sel=sel[2], a=a, b=e); 25 | DMux(in=selcg, sel=sel[2], a=c, b=g); 26 | DMux(in=selbf, sel=sel[2], a=b, b=f); 27 | DMux(in=seldh, sel=sel[2], a=d, b=h); 28 | 29 | } 30 | -------------------------------------------------------------------------------- /projects/01/DMux8Way.out: -------------------------------------------------------------------------------- 1 | | in | sel | a | b | c | d | e | f | g | h | 2 | | 0 | 000 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 3 | | 0 | 001 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 4 | | 0 | 010 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 5 | | 0 | 011 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 6 | | 0 | 100 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 7 | | 0 | 101 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 8 | | 0 | 110 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 9 | | 0 | 111 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 10 | | 1 | 000 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 11 | | 1 | 001 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 12 | | 1 | 010 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 13 | | 1 | 011 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 14 | | 1 | 100 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 15 | | 1 | 101 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 16 | | 1 | 110 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 17 | | 1 | 111 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 18 | -------------------------------------------------------------------------------- /projects/01/DMux8Way.tst: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/01/DMux8Way.tst 5 | 6 | load DMux8Way.hdl, 7 | output-file DMux8Way.out, 8 | compare-to DMux8Way.cmp, 9 | output-list in%B2.1.2 sel%B2.3.2 a%B2.1.2 b%B2.1.2 c%B2.1.2 d%B2.1.2 e%B2.1.2 f%B2.1.2 g%B2.1.2 h%B2.1.2; 10 | 11 | set in 0, 12 | set sel %B000, 13 | eval, 14 | output; 15 | 16 | set sel %B001, 17 | eval, 18 | output; 19 | 20 | set sel %B010, 21 | eval, 22 | output; 23 | 24 | set sel %B011, 25 | eval, 26 | output; 27 | 28 | set sel %B100, 29 | eval, 30 | output; 31 | 32 | set sel %B101, 33 | eval, 34 | output; 35 | 36 | set sel %B110, 37 | eval, 38 | output; 39 | 40 | set sel %B111, 41 | eval, 42 | output; 43 | 44 | set in 1, 45 | set sel %B000, 46 | eval, 47 | output; 48 | 49 | set sel %B001, 50 | eval, 51 | output; 52 | 53 | set sel %B010, 54 | eval, 55 | output; 56 | 57 | set sel %B011, 58 | eval, 59 | output; 60 | 61 | set sel %B100, 62 | eval, 63 | output; 64 | 65 | set sel %B101, 66 | eval, 67 | output; 68 | 69 | set sel %B110, 70 | eval, 71 | output; 72 | 73 | set sel %B111, 74 | eval, 75 | output; 76 | -------------------------------------------------------------------------------- /projects/01/Mux.cmp: -------------------------------------------------------------------------------- 1 | | a | b | sel | out | 2 | | 0 | 0 | 0 | 0 | 3 | | 0 | 0 | 1 | 0 | 4 | | 0 | 1 | 0 | 0 | 5 | | 0 | 1 | 1 | 1 | 6 | | 1 | 0 | 0 | 1 | 7 | | 1 | 0 | 1 | 0 | 8 | | 1 | 1 | 0 | 1 | 9 | | 1 | 1 | 1 | 1 | 10 | -------------------------------------------------------------------------------- /projects/01/Mux.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/01/Mux.hdl 5 | 6 | /** 7 | * Multiplexor: 8 | * out = a if sel == 0 9 | * b otherwise 10 | */ 11 | 12 | CHIP Mux { 13 | IN a, b, sel; 14 | OUT out; 15 | 16 | PARTS: 17 | // Put your code here: 18 | Not(in=sel, out=notsel); 19 | And(a=notsel, b=a, out=ansa); 20 | And(a=sel, b=b, out=asb); 21 | Or(a=ansa, b=asb, out=out); 22 | } 23 | -------------------------------------------------------------------------------- /projects/01/Mux.out: -------------------------------------------------------------------------------- 1 | | a | b | sel | out | 2 | | 0 | 0 | 0 | 0 | 3 | | 0 | 0 | 1 | 0 | 4 | | 0 | 1 | 0 | 0 | 5 | | 0 | 1 | 1 | 1 | 6 | | 1 | 0 | 0 | 1 | 7 | | 1 | 0 | 1 | 0 | 8 | | 1 | 1 | 0 | 1 | 9 | | 1 | 1 | 1 | 1 | 10 | -------------------------------------------------------------------------------- /projects/01/Mux.tst: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/01/Mux.tst 5 | 6 | load Mux.hdl, 7 | output-file Mux.out, 8 | compare-to Mux.cmp, 9 | output-list a%B3.1.3 b%B3.1.3 sel%B3.1.3 out%B3.1.3; 10 | 11 | set a 0, 12 | set b 0, 13 | set sel 0, 14 | eval, 15 | output; 16 | 17 | set sel 1, 18 | eval, 19 | output; 20 | 21 | set a 0, 22 | set b 1, 23 | set sel 0, 24 | eval, 25 | output; 26 | 27 | set sel 1, 28 | eval, 29 | output; 30 | 31 | set a 1, 32 | set b 0, 33 | set sel 0, 34 | eval, 35 | output; 36 | 37 | set sel 1, 38 | eval, 39 | output; 40 | 41 | set a 1, 42 | set b 1, 43 | set sel 0, 44 | eval, 45 | output; 46 | 47 | set sel 1, 48 | eval, 49 | output; 50 | -------------------------------------------------------------------------------- /projects/01/Mux16.cmp: -------------------------------------------------------------------------------- 1 | | a | b | sel | out | 2 | | 0000000000000000 | 0000000000000000 | 0 | 0000000000000000 | 3 | | 0000000000000000 | 0000000000000000 | 1 | 0000000000000000 | 4 | | 0000000000000000 | 0001001000110100 | 0 | 0000000000000000 | 5 | | 0000000000000000 | 0001001000110100 | 1 | 0001001000110100 | 6 | | 1001100001110110 | 0000000000000000 | 0 | 1001100001110110 | 7 | | 1001100001110110 | 0000000000000000 | 1 | 0000000000000000 | 8 | | 1010101010101010 | 0101010101010101 | 0 | 1010101010101010 | 9 | | 1010101010101010 | 0101010101010101 | 1 | 0101010101010101 | 10 | -------------------------------------------------------------------------------- /projects/01/Mux16.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/01/Mux16.hdl 5 | 6 | /** 7 | * 16-bit multiplexor: 8 | * for i = 0..15 out[i] = a[i] if sel == 0 9 | * b[i] if sel == 1 10 | */ 11 | 12 | CHIP Mux16 { 13 | IN a[16], b[16], sel; 14 | OUT out[16]; 15 | 16 | PARTS: 17 | // Put your code here: 18 | Mux(a=a[0], b=b[0], sel=sel, out=out[0]); 19 | Mux(a=a[1], b=b[1], sel=sel, out=out[1]); 20 | Mux(a=a[2], b=b[2], sel=sel, out=out[2]); 21 | Mux(a=a[3], b=b[3], sel=sel, out=out[3]); 22 | Mux(a=a[4], b=b[4], sel=sel, out=out[4]); 23 | Mux(a=a[5], b=b[5], sel=sel, out=out[5]); 24 | Mux(a=a[6], b=b[6], sel=sel, out=out[6]); 25 | Mux(a=a[7], b=b[7], sel=sel, out=out[7]); 26 | Mux(a=a[8], b=b[8], sel=sel, out=out[8]); 27 | Mux(a=a[9], b=b[9], sel=sel, out=out[9]); 28 | Mux(a=a[10], b=b[10], sel=sel, out=out[10]); 29 | Mux(a=a[11], b=b[11], sel=sel, out=out[11]); 30 | Mux(a=a[12], b=b[12], sel=sel, out=out[12]); 31 | Mux(a=a[13], b=b[13], sel=sel, out=out[13]); 32 | Mux(a=a[14], b=b[14], sel=sel, out=out[14]); 33 | Mux(a=a[15], b=b[15], sel=sel, out=out[15]); 34 | } 35 | -------------------------------------------------------------------------------- /projects/01/Mux16.out: -------------------------------------------------------------------------------- 1 | | a | b | sel | out | 2 | | 0000000000000000 | 0000000000000000 | 0 | 0000000000000000 | 3 | | 0000000000000000 | 0000000000000000 | 1 | 0000000000000000 | 4 | | 0000000000000000 | 0001001000110100 | 0 | 0000000000000000 | 5 | | 0000000000000000 | 0001001000110100 | 1 | 0001001000110100 | 6 | | 1001100001110110 | 0000000000000000 | 0 | 1001100001110110 | 7 | | 1001100001110110 | 0000000000000000 | 1 | 0000000000000000 | 8 | | 1010101010101010 | 0101010101010101 | 0 | 1010101010101010 | 9 | | 1010101010101010 | 0101010101010101 | 1 | 0101010101010101 | 10 | -------------------------------------------------------------------------------- /projects/01/Mux16.tst: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/01/Mux16.tst 5 | 6 | load Mux16.hdl, 7 | output-file Mux16.out, 8 | compare-to Mux16.cmp, 9 | output-list a%B1.16.1 b%B1.16.1 sel%D2.1.2 out%B1.16.1; 10 | 11 | set a 0, 12 | set b 0, 13 | set sel 0, 14 | eval, 15 | output; 16 | 17 | set sel 1, 18 | eval, 19 | output; 20 | 21 | set a %B0000000000000000, 22 | set b %B0001001000110100, 23 | set sel 0, 24 | eval, 25 | output; 26 | 27 | set sel 1, 28 | eval, 29 | output; 30 | 31 | set a %B1001100001110110, 32 | set b %B0000000000000000, 33 | set sel 0, 34 | eval, 35 | output; 36 | 37 | set sel 1, 38 | eval, 39 | output; 40 | 41 | set a %B1010101010101010, 42 | set b %B0101010101010101, 43 | set sel 0, 44 | eval, 45 | output; 46 | 47 | set sel 1, 48 | eval, 49 | output; -------------------------------------------------------------------------------- /projects/01/Mux4Way16.cmp: -------------------------------------------------------------------------------- 1 | | a | b | c | d | sel | out | 2 | | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 00 | 0000000000000000 | 3 | | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 01 | 0000000000000000 | 4 | | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 10 | 0000000000000000 | 5 | | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 11 | 0000000000000000 | 6 | | 0001001000110100 | 1001100001110110 | 1010101010101010 | 0101010101010101 | 00 | 0001001000110100 | 7 | | 0001001000110100 | 1001100001110110 | 1010101010101010 | 0101010101010101 | 01 | 1001100001110110 | 8 | | 0001001000110100 | 1001100001110110 | 1010101010101010 | 0101010101010101 | 10 | 1010101010101010 | 9 | | 0001001000110100 | 1001100001110110 | 1010101010101010 | 0101010101010101 | 11 | 0101010101010101 | 10 | -------------------------------------------------------------------------------- /projects/01/Mux4Way16.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/01/Mux4Way16.hdl 5 | 6 | /** 7 | * 4-way 16-bit multiplexor: 8 | * out = a if sel == 00 9 | * b if sel == 01 10 | * c if sel == 10 11 | * d if sel == 11 12 | */ 13 | 14 | CHIP Mux4Way16 { 15 | IN a[16], b[16], c[16], d[16], sel[2]; 16 | OUT out[16]; 17 | 18 | PARTS: 19 | // Put your code here: 20 | Or(a=sel[0], b=sel[1], out=ors); 21 | And(a=sel[0], b=sel[1], out=ands); 22 | Mux16(a=a, b=b, sel=ors, out=abmux); 23 | Mux16(a=c, b=d, sel=ands, out=cdmux); 24 | Mux16(a=abmux, b=cdmux, sel=sel[1], out=out); 25 | } 26 | -------------------------------------------------------------------------------- /projects/01/Mux4Way16.out: -------------------------------------------------------------------------------- 1 | | a | b | c | d | sel | out | 2 | | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 00 | 0000000000000000 | 3 | | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 01 | 0000000000000000 | 4 | | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 10 | 0000000000000000 | 5 | | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 11 | 0000000000000000 | 6 | | 0001001000110100 | 1001100001110110 | 1010101010101010 | 0101010101010101 | 00 | 0001001000110100 | 7 | | 0001001000110100 | 1001100001110110 | 1010101010101010 | 0101010101010101 | 01 | 1001100001110110 | 8 | | 0001001000110100 | 1001100001110110 | 1010101010101010 | 0101010101010101 | 10 | 1010101010101010 | 9 | | 0001001000110100 | 1001100001110110 | 1010101010101010 | 0101010101010101 | 11 | 0101010101010101 | 10 | -------------------------------------------------------------------------------- /projects/01/Mux4Way16.tst: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/01/Mux4Way16.tst 5 | 6 | load Mux4Way16.hdl, 7 | output-file Mux4Way16.out, 8 | compare-to Mux4Way16.cmp, 9 | output-list a%B1.16.1 b%B1.16.1 c%B1.16.1 d%B1.16.1 sel%B2.2.2 out%B1.16.1; 10 | 11 | set a 0, 12 | set b 0, 13 | set c 0, 14 | set d 0, 15 | set sel 0, 16 | eval, 17 | output; 18 | 19 | set sel 1, 20 | eval, 21 | output; 22 | 23 | set sel 2, 24 | eval, 25 | output; 26 | 27 | set sel 3, 28 | eval, 29 | output; 30 | 31 | set a %B0001001000110100, 32 | set b %B1001100001110110, 33 | set c %B1010101010101010, 34 | set d %B0101010101010101, 35 | set sel 0, 36 | eval, 37 | output; 38 | 39 | set sel 1, 40 | eval, 41 | output; 42 | 43 | set sel 2, 44 | eval, 45 | output; 46 | 47 | set sel 3, 48 | eval, 49 | output; 50 | -------------------------------------------------------------------------------- /projects/01/Mux8Way16.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/01/Mux8Way16.hdl 5 | 6 | /** 7 | * 8-way 16-bit multiplexor: 8 | * out = a if sel == 000 9 | * b if sel == 001 10 | * etc. 11 | * h if sel == 111 12 | */ 13 | 14 | CHIP Mux8Way16 { 15 | IN a[16], b[16], c[16], d[16], 16 | e[16], f[16], g[16], h[16], 17 | sel[3]; 18 | OUT out[16]; 19 | 20 | PARTS: 21 | // Put your code here: 22 | Mux16(a=a, b=b, sel=sel[0], out=out1); 23 | Mux16(a=c, b=d, sel=sel[0], out=out2); 24 | Mux16(a=e, b=f, sel=sel[0], out=out3); 25 | Mux16(a=g, b=h, sel=sel[0], out=out4); 26 | 27 | Mux16(a=out1, b=out2, sel=sel[1], out=out21); 28 | Mux16(a=out3, b=out4, sel=sel[1], out=out22); 29 | 30 | Mux16(a=out21, b=out22, sel=sel[2], out=out); 31 | 32 | 33 | } 34 | -------------------------------------------------------------------------------- /projects/01/Not.cmp: -------------------------------------------------------------------------------- 1 | | in | out | 2 | | 0 | 1 | 3 | | 1 | 0 | 4 | -------------------------------------------------------------------------------- /projects/01/Not.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/01/Not.hdl 5 | 6 | /** 7 | * Not gate: 8 | * out = not in 9 | */ 10 | 11 | CHIP Not { 12 | IN in; 13 | OUT out; 14 | 15 | PARTS: 16 | // Put your code here: 17 | Nand(a=in, b=in, out=out); 18 | } 19 | -------------------------------------------------------------------------------- /projects/01/Not.out: -------------------------------------------------------------------------------- 1 | | in | out | 2 | | 0 | 1 | 3 | | 1 | 0 | 4 | -------------------------------------------------------------------------------- /projects/01/Not.tst: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/01/Not.tst 5 | 6 | load Not.hdl, 7 | output-file Not.out, 8 | compare-to Not.cmp, 9 | output-list in%B3.1.3 out%B3.1.3; 10 | 11 | set in 0, 12 | eval, 13 | output; 14 | 15 | set in 1, 16 | eval, 17 | output; 18 | -------------------------------------------------------------------------------- /projects/01/Not16.cmp: -------------------------------------------------------------------------------- 1 | | in | out | 2 | | 0000000000000000 | 1111111111111111 | 3 | | 1111111111111111 | 0000000000000000 | 4 | | 1010101010101010 | 0101010101010101 | 5 | | 0011110011000011 | 1100001100111100 | 6 | | 0001001000110100 | 1110110111001011 | 7 | -------------------------------------------------------------------------------- /projects/01/Not16.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/01/Not16.hdl 5 | 6 | /** 7 | * 16-bit Not: 8 | * for i=0..15: out[i] = not in[i] 9 | */ 10 | 11 | CHIP Not16 { 12 | IN in[16]; 13 | OUT out[16]; 14 | 15 | PARTS: 16 | // Put your code here: 17 | Not(in=in[0], out=out[0]); 18 | Not(in=in[1], out=out[1]); 19 | Not(in=in[2], out=out[2]); 20 | Not(in=in[3], out=out[3]); 21 | Not(in=in[4], out=out[4]); 22 | Not(in=in[5], out=out[5]); 23 | Not(in=in[6], out=out[6]); 24 | Not(in=in[7], out=out[7]); 25 | Not(in=in[8], out=out[8]); 26 | Not(in=in[9], out=out[9]); 27 | Not(in=in[10], out=out[10]); 28 | Not(in=in[11], out=out[11]); 29 | Not(in=in[12], out=out[12]); 30 | Not(in=in[13], out=out[13]); 31 | Not(in=in[14], out=out[14]); 32 | Not(in=in[15], out=out[15]); 33 | } 34 | -------------------------------------------------------------------------------- /projects/01/Not16.out: -------------------------------------------------------------------------------- 1 | | in | out | 2 | | 0000000000000000 | 1111111111111111 | 3 | | 1111111111111111 | 0000000000000000 | 4 | | 1010101010101010 | 0101010101010101 | 5 | | 0011110011000011 | 1100001100111100 | 6 | | 0001001000110100 | 1110110111001011 | 7 | -------------------------------------------------------------------------------- /projects/01/Not16.tst: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/01/Not16.tst 5 | 6 | load Not16.hdl, 7 | output-file Not16.out, 8 | compare-to Not16.cmp, 9 | output-list in%B1.16.1 out%B1.16.1; 10 | 11 | set in %B0000000000000000, 12 | eval, 13 | output; 14 | 15 | set in %B1111111111111111, 16 | eval, 17 | output; 18 | 19 | set in %B1010101010101010, 20 | eval, 21 | output; 22 | 23 | set in %B0011110011000011, 24 | eval, 25 | output; 26 | 27 | set in %B0001001000110100, 28 | eval, 29 | output; -------------------------------------------------------------------------------- /projects/01/Or.cmp: -------------------------------------------------------------------------------- 1 | | a | b | out | 2 | | 0 | 0 | 0 | 3 | | 0 | 1 | 1 | 4 | | 1 | 0 | 1 | 5 | | 1 | 1 | 1 | 6 | -------------------------------------------------------------------------------- /projects/01/Or.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/01/Or.hdl 5 | 6 | /** 7 | * Or gate: 8 | * out = 1 if (a == 1 or b == 1) 9 | * 0 otherwise 10 | */ 11 | 12 | CHIP Or { 13 | IN a, b; 14 | OUT out; 15 | 16 | PARTS: 17 | // Put your code here: 18 | Nand(a=a, b=a, out=nanda); 19 | Nand(a=b, b=b, out=nandb); 20 | Nand(a=nanda, b=nandb, out=out); 21 | } 22 | -------------------------------------------------------------------------------- /projects/01/Or.out: -------------------------------------------------------------------------------- 1 | | a | b | out | 2 | | 0 | 0 | 0 | 3 | | 0 | 1 | 1 | 4 | | 1 | 0 | 1 | 5 | | 1 | 1 | 1 | 6 | -------------------------------------------------------------------------------- /projects/01/Or.tst: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/01/Or.tst 5 | 6 | load Or.hdl, 7 | output-file Or.out, 8 | compare-to Or.cmp, 9 | output-list a%B3.1.3 b%B3.1.3 out%B3.1.3; 10 | 11 | set a 0, 12 | set b 0, 13 | eval, 14 | output; 15 | 16 | set a 0, 17 | set b 1, 18 | eval, 19 | output; 20 | 21 | set a 1, 22 | set b 0, 23 | eval, 24 | output; 25 | 26 | set a 1, 27 | set b 1, 28 | eval, 29 | output; 30 | -------------------------------------------------------------------------------- /projects/01/Or16.cmp: -------------------------------------------------------------------------------- 1 | | a | b | out | 2 | | 0000000000000000 | 0000000000000000 | 0000000000000000 | 3 | | 0000000000000000 | 1111111111111111 | 1111111111111111 | 4 | | 1111111111111111 | 1111111111111111 | 1111111111111111 | 5 | | 1010101010101010 | 0101010101010101 | 1111111111111111 | 6 | | 0011110011000011 | 0000111111110000 | 0011111111110011 | 7 | | 0001001000110100 | 1001100001110110 | 1001101001110110 | 8 | -------------------------------------------------------------------------------- /projects/01/Or16.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/01/Or16.hdl 5 | 6 | /** 7 | * 16-bit bitwise Or: 8 | * for i = 0..15 out[i] = (a[i] or b[i]) 9 | */ 10 | 11 | CHIP Or16 { 12 | IN a[16], b[16]; 13 | OUT out[16]; 14 | 15 | PARTS: 16 | // Put your code here: 17 | Or(a=a[0], b=b[0], out=out[0]); 18 | Or(a=a[1], b=b[1], out=out[1]); 19 | Or(a=a[2], b=b[2], out=out[2]); 20 | Or(a=a[3], b=b[3], out=out[3]); 21 | Or(a=a[4], b=b[4], out=out[4]); 22 | Or(a=a[5], b=b[5], out=out[5]); 23 | Or(a=a[6], b=b[6], out=out[6]); 24 | Or(a=a[7], b=b[7], out=out[7]); 25 | Or(a=a[8], b=b[8], out=out[8]); 26 | Or(a=a[9], b=b[9], out=out[9]); 27 | Or(a=a[10], b=b[10], out=out[10]); 28 | Or(a=a[11], b=b[11], out=out[11]); 29 | Or(a=a[12], b=b[12], out=out[12]); 30 | Or(a=a[13], b=b[13], out=out[13]); 31 | Or(a=a[14], b=b[14], out=out[14]); 32 | Or(a=a[15], b=b[15], out=out[15]); 33 | } 34 | -------------------------------------------------------------------------------- /projects/01/Or16.out: -------------------------------------------------------------------------------- 1 | | a | b | out | 2 | | 0000000000000000 | 0000000000000000 | 0000000000000000 | 3 | | 0000000000000000 | 1111111111111111 | 1111111111111111 | 4 | | 1111111111111111 | 1111111111111111 | 1111111111111111 | 5 | | 1010101010101010 | 0101010101010101 | 1111111111111111 | 6 | | 0011110011000011 | 0000111111110000 | 0011111111110011 | 7 | | 0001001000110100 | 1001100001110110 | 1001101001110110 | 8 | -------------------------------------------------------------------------------- /projects/01/Or16.tst: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/01/Or16.tst 5 | 6 | load Or16.hdl, 7 | output-file Or16.out, 8 | compare-to Or16.cmp, 9 | output-list a%B1.16.1 b%B1.16.1 out%B1.16.1; 10 | 11 | set a %B0000000000000000, 12 | set b %B0000000000000000, 13 | eval, 14 | output; 15 | 16 | set a %B0000000000000000, 17 | set b %B1111111111111111, 18 | eval, 19 | output; 20 | 21 | set a %B1111111111111111, 22 | set b %B1111111111111111, 23 | eval, 24 | output; 25 | 26 | set a %B1010101010101010, 27 | set b %B0101010101010101, 28 | eval, 29 | output; 30 | 31 | set a %B0011110011000011, 32 | set b %B0000111111110000, 33 | eval, 34 | output; 35 | 36 | set a %B0001001000110100, 37 | set b %B1001100001110110, 38 | eval, 39 | output; -------------------------------------------------------------------------------- /projects/01/Or8Way.cmp: -------------------------------------------------------------------------------- 1 | | in | out | 2 | | 00000000 | 0 | 3 | | 11111111 | 1 | 4 | | 00010000 | 1 | 5 | | 00000001 | 1 | 6 | | 00100110 | 1 | 7 | -------------------------------------------------------------------------------- /projects/01/Or8Way.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/01/Or8Way.hdl 5 | 6 | /** 7 | * 8-way Or: 8 | * out = (in[0] or in[1] or ... or in[7]) 9 | */ 10 | 11 | CHIP Or8Way { 12 | IN in[8]; 13 | OUT out; 14 | 15 | PARTS: 16 | // Put your code here: 17 | Or(a=in[0], b=in[1], out=or1); 18 | Or(a=or1, b=in[2], out=or2); 19 | Or(a=or2, b=in[3], out=or3); 20 | Or(a=or3, b=in[4], out=or4); 21 | Or(a=or4, b=in[5], out=or5); 22 | Or(a=or5, b=in[6], out=or6); 23 | Or(a=or6, b=in[7], out=out); 24 | 25 | } 26 | -------------------------------------------------------------------------------- /projects/01/Or8Way.out: -------------------------------------------------------------------------------- 1 | | in | out | 2 | | 00000000 | 0 | 3 | | 11111111 | 1 | 4 | | 00010000 | 1 | 5 | | 00000001 | 1 | 6 | | 00100110 | 1 | 7 | -------------------------------------------------------------------------------- /projects/01/Or8Way.tst: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/01/Or8Way.tst 5 | 6 | load Or8Way.hdl, 7 | output-file Or8Way.out, 8 | compare-to Or8Way.cmp, 9 | output-list in%B2.8.2 out%B2.1.2; 10 | 11 | set in %B00000000, 12 | eval, 13 | output; 14 | 15 | set in %B11111111, 16 | eval, 17 | output; 18 | 19 | set in %B00010000, 20 | eval, 21 | output; 22 | 23 | set in %B00000001, 24 | eval, 25 | output; 26 | 27 | set in %B00100110, 28 | eval, 29 | output; -------------------------------------------------------------------------------- /projects/01/Xor.cmp: -------------------------------------------------------------------------------- 1 | | a | b | out | 2 | | 0 | 0 | 0 | 3 | | 0 | 1 | 1 | 4 | | 1 | 0 | 1 | 5 | | 1 | 1 | 0 | 6 | -------------------------------------------------------------------------------- /projects/01/Xor.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/01/Xor.hdl 5 | 6 | /** 7 | * Exclusive-or gate: 8 | * out = not (a == b) 9 | */ 10 | 11 | CHIP Xor { 12 | IN a, b; 13 | OUT out; 14 | 15 | PARTS: 16 | // Put your code here: 17 | Not(in=a, out=nota); 18 | Not(in=b, out=notb); 19 | 20 | Or(a=a, b=notb, out=ora); 21 | Or(a=nota, b=b, out=orb); 22 | 23 | Nand(a=ora, b=orb, out=out); 24 | } 25 | -------------------------------------------------------------------------------- /projects/01/Xor.out: -------------------------------------------------------------------------------- 1 | | a | b | out | 2 | | 0 | 0 | 0 | 3 | | 0 | 1 | 1 | 4 | | 1 | 0 | 1 | 5 | | 1 | 1 | 0 | 6 | -------------------------------------------------------------------------------- /projects/01/Xor.tst: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/01/Xor.tst 5 | 6 | load Xor.hdl, 7 | output-file Xor.out, 8 | compare-to Xor.cmp, 9 | output-list a%B3.1.3 b%B3.1.3 out%B3.1.3; 10 | 11 | set a 0, 12 | set b 0, 13 | eval, 14 | output; 15 | 16 | set a 0, 17 | set b 1, 18 | eval, 19 | output; 20 | 21 | set a 1, 22 | set b 0, 23 | eval, 24 | output; 25 | 26 | set a 1, 27 | set b 1, 28 | eval, 29 | output; 30 | -------------------------------------------------------------------------------- /projects/02/Add16.cmp: -------------------------------------------------------------------------------- 1 | | a | b | out | 2 | | 0000000000000000 | 0000000000000000 | 0000000000000000 | 3 | | 0000000000000000 | 1111111111111111 | 1111111111111111 | 4 | | 1111111111111111 | 1111111111111111 | 1111111111111110 | 5 | | 1010101010101010 | 0101010101010101 | 1111111111111111 | 6 | | 0011110011000011 | 0000111111110000 | 0100110010110011 | 7 | | 0001001000110100 | 1001100001110110 | 1010101010101010 | 8 | -------------------------------------------------------------------------------- /projects/02/Add16.out: -------------------------------------------------------------------------------- 1 | | a | b | out | 2 | | 0000000000000000 | 0000000000000000 | 0000000000000000 | 3 | | 0000000000000000 | 1111111111111111 | 1111111111111111 | 4 | | 1111111111111111 | 1111111111111111 | 1111111111111110 | 5 | | 1010101010101010 | 0101010101010101 | 1111111111111111 | 6 | | 0011110011000011 | 0000111111110000 | 0100110010110011 | 7 | | 0001001000110100 | 1001100001110110 | 1010101010101010 | 8 | -------------------------------------------------------------------------------- /projects/02/Add16.tst: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/02/Add16.tst 5 | 6 | load Add16.hdl, 7 | output-file Add16.out, 8 | compare-to Add16.cmp, 9 | output-list a%B1.16.1 b%B1.16.1 out%B1.16.1; 10 | 11 | set a %B0000000000000000, 12 | set b %B0000000000000000, 13 | eval, 14 | output; 15 | 16 | set a %B0000000000000000, 17 | set b %B1111111111111111, 18 | eval, 19 | output; 20 | 21 | set a %B1111111111111111, 22 | set b %B1111111111111111, 23 | eval, 24 | output; 25 | 26 | set a %B1010101010101010, 27 | set b %B0101010101010101, 28 | eval, 29 | output; 30 | 31 | set a %B0011110011000011, 32 | set b %B0000111111110000, 33 | eval, 34 | output; 35 | 36 | set a %B0001001000110100, 37 | set b %B1001100001110110, 38 | eval, 39 | output; 40 | -------------------------------------------------------------------------------- /projects/02/FullAdder.cmp: -------------------------------------------------------------------------------- 1 | | a | b | c | sum | carry | 2 | | 0 | 0 | 0 | 0 | 0 | 3 | | 0 | 0 | 1 | 1 | 0 | 4 | | 0 | 1 | 0 | 1 | 0 | 5 | | 0 | 1 | 1 | 0 | 1 | 6 | | 1 | 0 | 0 | 1 | 0 | 7 | | 1 | 0 | 1 | 0 | 1 | 8 | | 1 | 1 | 0 | 0 | 1 | 9 | | 1 | 1 | 1 | 1 | 1 | 10 | -------------------------------------------------------------------------------- /projects/02/FullAdder.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/02/FullAdder.hdl 5 | 6 | /** 7 | * Computes the sum of three bits. 8 | */ 9 | 10 | CHIP FullAdder { 11 | IN a, b, c; // 1-bit inputs 12 | OUT sum, // Right bit of a + b + c 13 | carry; // Left bit of a + b + c 14 | 15 | PARTS: 16 | // Put you code here: 17 | HalfAdder(a=a, b=b, sum=sab, carry=cab); 18 | HalfAdder(a=sab, b=c, sum=sum, carry=cabc); 19 | Mux(a=cabc, b=true, sel=cab, out=carry); 20 | 21 | } 22 | -------------------------------------------------------------------------------- /projects/02/FullAdder.out: -------------------------------------------------------------------------------- 1 | | a | b | c | sum | carry | 2 | | 0 | 0 | 0 | 0 | 0 | 3 | | 0 | 0 | 1 | 1 | 0 | 4 | | 0 | 1 | 0 | 1 | 0 | 5 | | 0 | 1 | 1 | 0 | 1 | 6 | | 1 | 0 | 0 | 1 | 0 | 7 | | 1 | 0 | 1 | 0 | 1 | 8 | | 1 | 1 | 0 | 0 | 1 | 9 | | 1 | 1 | 1 | 1 | 1 | 10 | -------------------------------------------------------------------------------- /projects/02/FullAdder.tst: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/02/FullAdder.tst 5 | 6 | load FullAdder.hdl, 7 | output-file FullAdder.out, 8 | compare-to FullAdder.cmp, 9 | output-list a%B3.1.3 b%B3.1.3 c%B3.1.3 sum%B3.1.3 carry%B3.1.3; 10 | 11 | set a 0, 12 | set b 0, 13 | set c 0, 14 | eval, 15 | output; 16 | 17 | set c 1, 18 | eval, 19 | output; 20 | 21 | set b 1, 22 | set c 0, 23 | eval, 24 | output; 25 | 26 | set c 1, 27 | eval, 28 | output; 29 | 30 | set a 1, 31 | set b 0, 32 | set c 0, 33 | eval, 34 | output; 35 | 36 | set c 1, 37 | eval, 38 | output; 39 | 40 | set b 1, 41 | set c 0, 42 | eval, 43 | output; 44 | 45 | set c 1, 46 | eval, 47 | output; 48 | -------------------------------------------------------------------------------- /projects/02/HalfAdder.cmp: -------------------------------------------------------------------------------- 1 | | a | b | sum | carry | 2 | | 0 | 0 | 0 | 0 | 3 | | 0 | 1 | 1 | 0 | 4 | | 1 | 0 | 1 | 0 | 5 | | 1 | 1 | 0 | 1 | 6 | -------------------------------------------------------------------------------- /projects/02/HalfAdder.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/02/HalfAdder.hdl 5 | 6 | /** 7 | * Computes the sum of two bits. 8 | */ 9 | 10 | CHIP HalfAdder { 11 | IN a, b; // 1-bit inputs 12 | OUT sum, // Right bit of a + b 13 | carry; // Left bit of a + b 14 | 15 | PARTS: 16 | // Put you code here: 17 | Xor(a=a, b=b, out=sum); 18 | And(a=a, b=b, out=carry); 19 | } 20 | -------------------------------------------------------------------------------- /projects/02/HalfAdder.out: -------------------------------------------------------------------------------- 1 | | a | b | sum | carry | 2 | | 0 | 0 | 0 | 0 | 3 | | 0 | 1 | 1 | 0 | 4 | | 1 | 0 | 1 | 0 | 5 | | 1 | 1 | 0 | 1 | 6 | -------------------------------------------------------------------------------- /projects/02/HalfAdder.tst: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/02/HalfAdder.tst 5 | 6 | load HalfAdder.hdl, 7 | output-file HalfAdder.out, 8 | compare-to HalfAdder.cmp, 9 | output-list a%B3.1.3 b%B3.1.3 sum%B3.1.3 carry%B3.1.3; 10 | 11 | set a 0, 12 | set b 0, 13 | eval, 14 | output; 15 | 16 | set a 0, 17 | set b 1, 18 | eval, 19 | output; 20 | 21 | set a 1, 22 | set b 0, 23 | eval, 24 | output; 25 | 26 | set a 1, 27 | set b 1, 28 | eval, 29 | output; 30 | -------------------------------------------------------------------------------- /projects/02/Inc16.cmp: -------------------------------------------------------------------------------- 1 | | in | out | 2 | | 0000000000000000 | 0000000000000001 | 3 | | 1111111111111111 | 0000000000000000 | 4 | | 0000000000000101 | 0000000000000110 | 5 | | 1111111111111011 | 1111111111111100 | 6 | -------------------------------------------------------------------------------- /projects/02/Inc16.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/02/Inc16.hdl 5 | 6 | /** 7 | * 16-bit incrementer: 8 | * out = in + 1 (arithmetic addition) 9 | */ 10 | 11 | CHIP Inc16 { 12 | IN in[16]; 13 | OUT out[16]; 14 | 15 | PARTS: 16 | // Put you code here: 17 | Add16(a=in, b[0]=true, out=out); 18 | } 19 | -------------------------------------------------------------------------------- /projects/02/Inc16.out: -------------------------------------------------------------------------------- 1 | | in | out | 2 | | 0000000000000000 | 0000000000000001 | 3 | | 1111111111111111 | 0000000000000000 | 4 | | 0000000000000101 | 0000000000000110 | 5 | | 1111111111111011 | 1111111111111100 | 6 | -------------------------------------------------------------------------------- /projects/02/Inc16.tst: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/02/Inc16.tst 5 | 6 | load Inc16.hdl, 7 | output-file Inc16.out, 8 | compare-to Inc16.cmp, 9 | output-list in%B1.16.1 out%B1.16.1; 10 | 11 | set in %B0000000000000000, // in = 0 12 | eval, 13 | output; 14 | 15 | set in %B1111111111111111, // in = -1 16 | eval, 17 | output; 18 | 19 | set in %B0000000000000101, // in = 5 20 | eval, 21 | output; 22 | 23 | set in %B1111111111111011, // in = -5 24 | eval, 25 | output; 26 | -------------------------------------------------------------------------------- /projects/02/Or16Way.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/01/Or8Way.hdl 5 | 6 | /** 7 | * 16-way Or: 8 | * out = (in[0] or in[1] or ... or in[15]) 9 | */ 10 | 11 | CHIP Or16Way { 12 | IN in[16]; 13 | OUT out; 14 | 15 | PARTS: 16 | // Put your code here: 17 | Or(a=in[0], b=in[1], out=or1); 18 | Or(a=or1, b=in[2], out=or2); 19 | Or(a=or2, b=in[3], out=or3); 20 | Or(a=or3, b=in[4], out=or4); 21 | Or(a=or4, b=in[5], out=or5); 22 | Or(a=or5, b=in[6], out=or6); 23 | Or(a=or6, b=in[7], out=or7); 24 | Or(a=or7, b=in[8], out=or8); 25 | Or(a=or8, b=in[9], out=or9); 26 | Or(a=or9, b=in[10], out=or10); 27 | Or(a=or10, b=in[11], out=or11); 28 | Or(a=or11, b=in[12], out=or12); 29 | Or(a=or12, b=in[13], out=or13); 30 | Or(a=or13, b=in[14], out=or14); 31 | Or(a=or14, b=in[15], out=out); 32 | 33 | } 34 | -------------------------------------------------------------------------------- /projects/03/a/Bit.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/03/a/Bit.hdl 5 | 6 | /** 7 | * 1-bit register: 8 | * If load[t] == 1 then out[t+1] = in[t] 9 | * else out does not change (out[t+1] = out[t]) 10 | */ 11 | 12 | CHIP Bit { 13 | IN in, load; 14 | OUT out; 15 | 16 | PARTS: 17 | // Put your code here: 18 | Mux(a=outa, b=in, sel=load, out=outin); 19 | DFF(in=outin, out=outa, out=out); 20 | } 21 | -------------------------------------------------------------------------------- /projects/03/a/PC.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/03/a/PC.hdl 5 | 6 | /** 7 | * A 16-bit counter with load and reset control bits. 8 | * if (reset[t] == 1) out[t+1] = 0 9 | * else if (load[t] == 1) out[t+1] = in[t] 10 | * else if (inc[t] == 1) out[t+1] = out[t] + 1 (integer addition) 11 | * else out[t+1] = out[t] 12 | */ 13 | 14 | CHIP PC { 15 | IN in[16],load,inc,reset; 16 | OUT out[16]; 17 | 18 | PARTS: 19 | // Put your code herer: 20 | Mux16(a=in, b=false, sel=reset, out=rst); 21 | Or(a=load, b=reset, out=sw1); 22 | Mux16(a=loop, b=rst, sel=sw1, out=regin); 23 | Or(a=sw1, b=inc, out=regload); 24 | Register(in=regin, load=regload, out=regout, out=out); 25 | Inc16(in=regout, out=inc1); 26 | Mux16(a=regout, b=inc1, sel=inc, out=loop); 27 | } 28 | -------------------------------------------------------------------------------- /projects/03/a/RAM64.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/03/a/RAM64.hdl 5 | 6 | /** 7 | * Memory of 64 registers, each 16 bit-wide. Out holds the value 8 | * stored at the memory location specified by address. If load==1, then 9 | * the in value is loaded into the memory location specified by address 10 | * (the loaded value will be emitted to out from the next time step onward). 11 | */ 12 | 13 | CHIP RAM64 { 14 | IN in[16], load, address[6]; 15 | OUT out[16]; 16 | 17 | PARTS: 18 | // Put your code here: 19 | DMux8Way(in=load, sel=address[3..5], a=r1, b=r2, c=r3, d=r4, 20 | e=r5, f=r6, g=r7, h=r8); 21 | RAM8(in=in, load=r1, address=address[0..2], out=o1); 22 | RAM8(in=in, load=r2, address=address[0..2], out=o2); 23 | RAM8(in=in, load=r3, address=address[0..2], out=o3); 24 | RAM8(in=in, load=r4, address=address[0..2], out=o4); 25 | RAM8(in=in, load=r5, address=address[0..2], out=o5); 26 | RAM8(in=in, load=r6, address=address[0..2], out=o6); 27 | RAM8(in=in, load=r7, address=address[0..2], out=o7); 28 | RAM8(in=in, load=r8, address=address[0..2], out=o8); 29 | 30 | Mux8Way16(a=o1, b=o2, c=o3, d=o4, e=o5, f=o6, g=o7, h=o8, 31 | sel=address[3..5], out=out); 32 | } 33 | -------------------------------------------------------------------------------- /projects/03/a/RAM8.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/03/a/RAM8.hdl 5 | 6 | /** 7 | * Memory of 8 registers, each 16 bit-wide. Out holds the value 8 | * stored at the memory location specified by address. If load==1, then 9 | * the in value is loaded into the memory location specified by address 10 | * (the loaded value will be emitted to out from the next time step onward). 11 | */ 12 | 13 | CHIP RAM8 { 14 | IN in[16], load, address[3]; 15 | OUT out[16]; 16 | 17 | PARTS: 18 | // Put your code here: 19 | DMux8Way(in=load, sel=address, a=l0, b=l1, c=l2, d=l3, e=l4, f=l5, g=l6, h=l7); 20 | Register(in=in, load=l0, out=o1); 21 | Register(in=in, load=l1, out=o2); 22 | Register(in=in, load=l2, out=o3); 23 | Register(in=in, load=l3, out=o4); 24 | Register(in=in, load=l4, out=o5); 25 | Register(in=in, load=l5, out=o6); 26 | Register(in=in, load=l6, out=o7); 27 | Register(in=in, load=l7, out=o8); 28 | 29 | Mux8Way16(a=o1, b=o2, c=o3, d=o4, 30 | e=o5, f=o6, g=o7, h=o8, sel=address, out=out); 31 | } 32 | -------------------------------------------------------------------------------- /projects/03/a/Register.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/03/a/Register.hdl 5 | 6 | /** 7 | * 16-bit register: 8 | * If load[t] == 1 then out[t+1] = in[t] 9 | * else out does not change 10 | */ 11 | 12 | CHIP Register { 13 | IN in[16], load; 14 | OUT out[16]; 15 | 16 | PARTS: 17 | // Put your code here: 18 | Bit(in=in[0], load=load, out=out[0]); 19 | Bit(in=in[1], load=load, out=out[1]); 20 | Bit(in=in[2], load=load, out=out[2]); 21 | Bit(in=in[3], load=load, out=out[3]); 22 | Bit(in=in[4], load=load, out=out[4]); 23 | Bit(in=in[5], load=load, out=out[5]); 24 | Bit(in=in[6], load=load, out=out[6]); 25 | Bit(in=in[7], load=load, out=out[7]); 26 | Bit(in=in[8], load=load, out=out[8]); 27 | Bit(in=in[9], load=load, out=out[9]); 28 | Bit(in=in[10], load=load, out=out[10]); 29 | Bit(in=in[11], load=load, out=out[11]); 30 | Bit(in=in[12], load=load, out=out[12]); 31 | Bit(in=in[13], load=load, out=out[13]); 32 | Bit(in=in[14], load=load, out=out[14]); 33 | Bit(in=in[15], load=load, out=out[15]); 34 | } 35 | -------------------------------------------------------------------------------- /projects/03/b/RAM16K.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/03/b/RAM16K.hdl 5 | 6 | /** 7 | * Memory of 16K registers, each 16 bit-wide. Out holds the value 8 | * stored at the memory location specified by address. If load==1, then 9 | * the in value is loaded into the memory location specified by address 10 | * (the loaded value will be emitted to out from the next time step onward). 11 | */ 12 | 13 | CHIP RAM16K { 14 | IN in[16], load, address[14]; 15 | OUT out[16]; 16 | 17 | PARTS: 18 | // Put your code here: 19 | DMux4Way(in=load, sel=address[12..13], a=r1, b=r2, c=r3, d=r4); 20 | RAM4K(in=in, load=r1, address=address[0..11], out=o1); 21 | RAM4K(in=in, load=r2, address=address[0..11], out=o2); 22 | RAM4K(in=in, load=r3, address=address[0..11], out=o3); 23 | RAM4K(in=in, load=r4, address=address[0..11], out=o4); 24 | 25 | Mux4Way16(a=o1, b=o2, c=o3, d=o4, sel=address[12..13], out=out); 26 | } 27 | -------------------------------------------------------------------------------- /projects/04/fill/Fill.asm: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/04/Fill.asm 5 | 6 | // Runs an infinite loop that listens to the keyboard input. 7 | // When a key is pressed (any key), the program blackens the screen, 8 | // i.e. writes "black" in every pixel. When no key is pressed, the 9 | // program clears the screen, i.e. writes "white" in every pixel. 10 | 11 | // Put your code here. 12 | @i 13 | M=0 14 | 15 | (LOOP) 16 | @KBD 17 | D=M 18 | @BLACK 19 | D;JGT // key>0 JUMP BLACK 20 | @WHITE 21 | D;JEQ // key=0 JUMP WHITE 22 | 23 | (BLACK) 24 | @i 25 | D=M 26 | @8191 27 | D=D-A 28 | @LOOP 29 | D;JGT // if MAX Then do noting 30 | @i 31 | D=M 32 | @SCREEN 33 | A=A+D 34 | M=-1 35 | @i 36 | M=M+1 37 | @LOOP 38 | 0;JMP 39 | 40 | (WHITE) 41 | @i 42 | D=M 43 | @RESET 44 | D;JLT // if MIN Then do noting 45 | @i 46 | D=M 47 | @SCREEN 48 | A=A+D 49 | M=0 50 | @i 51 | M=M-1 52 | @LOOP 53 | 0;JMP 54 | 55 | (RESET) 56 | @i 57 | M=0 58 | @LOOP 59 | 0;JMP 60 | -------------------------------------------------------------------------------- /projects/04/fill/Fill.hack: -------------------------------------------------------------------------------- 1 | 0000000000010000 2 | 1110101010001000 3 | 0110000000000000 4 | 1111110000010000 5 | 0000000000001000 6 | 1110001100000001 7 | 0000000000010111 8 | 1110001100000010 9 | 0000000000010000 10 | 1111110000010000 11 | 0001111111111111 12 | 1110010011010000 13 | 0000000000000010 14 | 1110001100000001 15 | 0000000000010000 16 | 1111110000010000 17 | 0100000000000000 18 | 1110000010100000 19 | 1110111010001000 20 | 0000000000010000 21 | 1111110111001000 22 | 0000000000000010 23 | 1110101010000111 24 | 0000000000010000 25 | 1111110000010000 26 | 0000000000100100 27 | 1110001100000100 28 | 0000000000010000 29 | 1111110000010000 30 | 0100000000000000 31 | 1110000010100000 32 | 1110101010001000 33 | 0000000000010000 34 | 1111110010001000 35 | 0000000000000010 36 | 1110101010000111 37 | 0000000000010000 38 | 1110101010001000 39 | 0000000000000010 40 | 1110101010000111 41 | -------------------------------------------------------------------------------- /projects/04/fill/Fill.tst: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/04/fill/Fill.tst 5 | 6 | load Fill.hack; 7 | echo "First, make sure that 'No Animation' is selected. Then, select the Keyboard, click on any key, and check the screen."; 8 | 9 | repeat { 10 | ticktock; 11 | } 12 | -------------------------------------------------------------------------------- /projects/04/mult/Mult.asm: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/04/Mult.asm 5 | 6 | // Multiplies R0 and R1 and stores the result in R2. 7 | // (R0, R1, R2 refer to RAM[0], RAM[1], and RAM[2], respectively.) 8 | 9 | // Put your code here. 10 | // SET R2=0 11 | @R2 12 | M=0 13 | 14 | // RO R1 > 0 15 | @R0 16 | D=M 17 | @END 18 | D;JLE 19 | @R1 20 | D=M 21 | @END 22 | D;JLE 23 | 24 | // SET R3=R1 25 | @R1 26 | D=M 27 | @R3 28 | M=D 29 | 30 | // LOOP BODY 31 | (LOOP) 32 | @R0 33 | D=M 34 | @R2 35 | M=M+D 36 | @R3 37 | M=M-1 38 | @R3 39 | D=M 40 | // R3=0 JUMP END 41 | @END 42 | D;JEQ 43 | // R3>0 JUMP LOOP 44 | @LOOP 45 | D;JGT 46 | 47 | // END PROGRAM 48 | (END) 49 | @END 50 | 0;JMP 51 | 52 | -------------------------------------------------------------------------------- /projects/04/mult/Mult.cmp: -------------------------------------------------------------------------------- 1 | | RAM[0] | RAM[1] | RAM[2] | 2 | | 0 | 0 | 0 | 3 | | 1 | 0 | 0 | 4 | | 0 | 2 | 0 | 5 | | 3 | 1 | 3 | 6 | | 2 | 4 | 8 | 7 | | 6 | 7 | 42 | -------------------------------------------------------------------------------- /projects/04/mult/Mult.hack: -------------------------------------------------------------------------------- 1 | 0000000000000010 2 | 1110101010001000 3 | 0000000000000000 4 | 1111110000010000 5 | 0000000000011010 6 | 1110001100000110 7 | 0000000000000001 8 | 1111110000010000 9 | 0000000000011010 10 | 1110001100000110 11 | 0000000000000001 12 | 1111110000010000 13 | 0000000000000011 14 | 1110001100001000 15 | 0000000000000000 16 | 1111110000010000 17 | 0000000000000010 18 | 1111000010001000 19 | 0000000000000011 20 | 1111110010001000 21 | 0000000000000011 22 | 1111110000010000 23 | 0000000000011010 24 | 1110001100000010 25 | 0000000000001110 26 | 1110001100000001 27 | 0000000000011010 28 | 1110101010000111 29 | -------------------------------------------------------------------------------- /projects/04/mult/Mult.out: -------------------------------------------------------------------------------- 1 | | RAM[0] | RAM[1] | RAM[2] | 2 | | 0 | 0 | 0 | 3 | | 1 | 0 | 0 | 4 | | 0 | 2 | 0 | 5 | | 3 | 1 | 3 | 6 | | 2 | 4 | 8 | 7 | | 6 | 7 | 42 | 8 | -------------------------------------------------------------------------------- /projects/05/Add.hack: -------------------------------------------------------------------------------- 1 | 0000000000000010 2 | 1110110000010000 3 | 0000000000000011 4 | 1110000010010000 5 | 0000000000000000 6 | 1110001100001000 7 | -------------------------------------------------------------------------------- /projects/05/Computer.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/05/Computer.hdl 5 | 6 | /** 7 | * The HACK computer, including CPU, ROM and RAM. 8 | * When reset is 0, the program stored in the computer's ROM executes. 9 | * When reset is 1, the execution of the program restarts. 10 | * Thus, to start a program's execution, reset must be pushed "up" (1) 11 | * and "down" (0). From this point onward the user is at the mercy of 12 | * the software. In particular, depending on the program's code, the 13 | * screen may show some output and the user may be able to interact 14 | * with the computer via the keyboard. 15 | */ 16 | 17 | CHIP Computer { 18 | 19 | IN reset; 20 | 21 | PARTS: 22 | // Put your code here: 23 | ROM32K(address=nIns, out=cIns); 24 | CPU(inM=oM, instruction=cIns, reset=reset, outM=outM, 25 | writeM=wM, addressM=addM, pc=nIns); 26 | Memory(in=outM, load=wM, address=addM, out=oM); 27 | } 28 | -------------------------------------------------------------------------------- /projects/05/ComputerAdd-external.cmp: -------------------------------------------------------------------------------- 1 | | time |reset|RAM16K[0]|RAM16K[1]|RAM16K[2]| 2 | | 0 | 0 | 0 | 0 | 0 | 3 | | 1 | 0 | 0 | 0 | 0 | 4 | | 2 | 0 | 0 | 0 | 0 | 5 | | 3 | 0 | 0 | 0 | 0 | 6 | | 4 | 0 | 0 | 0 | 0 | 7 | | 5 | 0 | 0 | 0 | 0 | 8 | | 6 | 0 | 5 | 0 | 0 | 9 | | 7 | 1 | 0 | 0 | 0 | 10 | | 8 | 0 | 0 | 0 | 0 | 11 | | 9 | 0 | 0 | 0 | 0 | 12 | | 10 | 0 | 0 | 0 | 0 | 13 | | 11 | 0 | 0 | 0 | 0 | 14 | | 12 | 0 | 0 | 0 | 0 | 15 | | 13 | 0 | 5 | 0 | 0 | 16 | -------------------------------------------------------------------------------- /projects/05/ComputerAdd-external.out: -------------------------------------------------------------------------------- 1 | | time |reset|RAM16K[0]|RAM16K[1]|RAM16K[2]| 2 | | 0 | 0 | 0 | 0 | 0 | 3 | | 1 | 0 | 0 | 0 | 0 | 4 | | 2 | 0 | 0 | 0 | 0 | 5 | | 3 | 0 | 0 | 0 | 0 | 6 | | 4 | 0 | 0 | 0 | 0 | 7 | | 5 | 0 | 0 | 0 | 0 | 8 | | 6 | 0 | 5 | 0 | 0 | 9 | | 7 | 1 | 0 | 0 | 0 | 10 | | 8 | 0 | 0 | 0 | 0 | 11 | | 9 | 0 | 0 | 0 | 0 | 12 | | 10 | 0 | 0 | 0 | 0 | 13 | | 11 | 0 | 0 | 0 | 0 | 14 | | 12 | 0 | 0 | 0 | 0 | 15 | | 13 | 0 | 5 | 0 | 0 | 16 | -------------------------------------------------------------------------------- /projects/05/ComputerAdd-external.tst: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/05/ComputerAdd-external.tst 5 | 6 | load Computer.hdl, 7 | output-file ComputerAdd-external.out, 8 | compare-to ComputerAdd-external.cmp, 9 | output-list time%S1.4.1 reset%B2.1.2 RAM16K[0]%D1.7.1 RAM16K[1]%D1.7.1 RAM16K[2]%D1.7.1; 10 | 11 | // Load a program written in the Hack machine language. 12 | // The program adds the two constants 2 and 3 and writes the result in RAM[0]. 13 | ROM32K load Add.hack, 14 | output; 15 | 16 | // First run (at the beginning PC=0) 17 | repeat 6 { 18 | tick, tock, output; 19 | } 20 | 21 | // Reset the PC 22 | set reset 1, 23 | set RAM16K[0] 0, 24 | tick, tock, output; 25 | 26 | 27 | // Second run, to check that the PC was reset correctly. 28 | set reset 0, 29 | 30 | repeat 6 { 31 | tick, tock, output; 32 | } 33 | -------------------------------------------------------------------------------- /projects/05/ComputerAdd.cmp: -------------------------------------------------------------------------------- 1 | | time |reset|ARegister|DRegister|PC[]|RAM16K[0]|RAM16K[1]|RAM16K[2]| 2 | | 0 | 0 | 0 | 0 | 0| 0 | 0 | 0 | 3 | | 1 | 0 | 2 | 0 | 1| 0 | 0 | 0 | 4 | | 2 | 0 | 2 | 2 | 2| 0 | 0 | 0 | 5 | | 3 | 0 | 3 | 2 | 3| 0 | 0 | 0 | 6 | | 4 | 0 | 3 | 5 | 4| 0 | 0 | 0 | 7 | | 5 | 0 | 0 | 5 | 5| 0 | 0 | 0 | 8 | | 6 | 0 | 0 | 5 | 6| 5 | 0 | 0 | 9 | | 7 | 1 | 0 | 5 | 0| 0 | 0 | 0 | 10 | | 8 | 0 | 2 | 5 | 1| 0 | 0 | 0 | 11 | | 9 | 0 | 2 | 2 | 2| 0 | 0 | 0 | 12 | | 10 | 0 | 3 | 2 | 3| 0 | 0 | 0 | 13 | | 11 | 0 | 3 | 5 | 4| 0 | 0 | 0 | 14 | | 12 | 0 | 0 | 5 | 5| 0 | 0 | 0 | 15 | | 13 | 0 | 0 | 5 | 6| 5 | 0 | 0 | 16 | -------------------------------------------------------------------------------- /projects/05/ComputerAdd.out: -------------------------------------------------------------------------------- 1 | | time |reset|ARegister|DRegister|PC[]|RAM16K[0]|RAM16K[1]|RAM16K[2]| 2 | | 0 | 0 | 0 | 0 | 0| 0 | 0 | 0 | 3 | | 1 | 0 | 2 | 0 | 1| 0 | 0 | 0 | 4 | | 2 | 0 | 2 | 2 | 2| 0 | 0 | 0 | 5 | | 3 | 0 | 3 | 2 | 3| 0 | 0 | 0 | 6 | | 4 | 0 | 3 | 5 | 4| 0 | 0 | 0 | 7 | | 5 | 0 | 0 | 5 | 5| 0 | 0 | 0 | 8 | | 6 | 0 | 0 | 5 | 6| 5 | 0 | 0 | 9 | | 7 | 1 | 0 | 5 | 0| 0 | 0 | 0 | 10 | | 8 | 0 | 2 | 5 | 1| 0 | 0 | 0 | 11 | | 9 | 0 | 2 | 2 | 2| 0 | 0 | 0 | 12 | | 10 | 0 | 3 | 2 | 3| 0 | 0 | 0 | 13 | | 11 | 0 | 3 | 5 | 4| 0 | 0 | 0 | 14 | | 12 | 0 | 0 | 5 | 5| 0 | 0 | 0 | 15 | | 13 | 0 | 0 | 5 | 6| 5 | 0 | 0 | 16 | -------------------------------------------------------------------------------- /projects/05/ComputerAdd.tst: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/05/ComputerAdd.tst 5 | 6 | load Computer.hdl, 7 | output-file ComputerAdd.out, 8 | compare-to ComputerAdd.cmp, 9 | output-list time%S1.4.1 reset%B2.1.2 ARegister[0]%D1.7.1 DRegister[0]%D1.7.1 PC[]%D0.4.0 RAM16K[0]%D1.7.1 RAM16K[1]%D1.7.1 RAM16K[2]%D1.7.1; 10 | 11 | // Load a program written in the Hack machine language. 12 | // The program adds the two constants 2 and 3 and writes the result in RAM[0]. 13 | ROM32K load Add.hack, 14 | output; 15 | 16 | // First run (at the beginning PC=0) 17 | repeat 6 { 18 | tick, tock, output; 19 | } 20 | 21 | // Reset the PC 22 | set reset 1, 23 | set RAM16K[0] 0, 24 | tick, tock, output; 25 | 26 | 27 | // Second run, to check that the PC was reset correctly. 28 | set reset 0, 29 | 30 | repeat 6 { 31 | tick, tock, output; 32 | } 33 | -------------------------------------------------------------------------------- /projects/05/ComputerMax-external.out: -------------------------------------------------------------------------------- 1 | | time |reset|RAM16K[0]|RAM16K[1]|RAM16K[2]| 2 | | 0 | 0 | 3 | 5 | 0 | 3 | | 1 | 0 | 3 | 5 | 0 | 4 | | 2 | 0 | 3 | 5 | 0 | 5 | | 3 | 0 | 3 | 5 | 0 | 6 | | 4 | 0 | 3 | 5 | 0 | 7 | | 5 | 0 | 3 | 5 | 0 | 8 | | 6 | 0 | 3 | 5 | 0 | 9 | | 7 | 0 | 3 | 5 | 0 | 10 | | 8 | 0 | 3 | 5 | 0 | 11 | | 9 | 0 | 3 | 5 | 0 | 12 | | 10 | 0 | 3 | 5 | 0 | 13 | | 11 | 0 | 3 | 5 | 0 | 14 | | 12 | 0 | 3 | 5 | 5 | 15 | | 13 | 0 | 3 | 5 | 5 | 16 | | 14 | 0 | 3 | 5 | 5 | 17 | | 15 | 1 | 3 | 5 | 5 | 18 | | 15 | 0 | 23456 | 12345 | 5 | 19 | | 16 | 0 | 23456 | 12345 | 5 | 20 | | 17 | 0 | 23456 | 12345 | 5 | 21 | | 18 | 0 | 23456 | 12345 | 5 | 22 | | 19 | 0 | 23456 | 12345 | 5 | 23 | | 20 | 0 | 23456 | 12345 | 5 | 24 | | 21 | 0 | 23456 | 12345 | 5 | 25 | | 22 | 0 | 23456 | 12345 | 5 | 26 | | 23 | 0 | 23456 | 12345 | 5 | 27 | | 24 | 0 | 23456 | 12345 | 5 | 28 | | 25 | 0 | 23456 | 12345 | 23456 | 29 | -------------------------------------------------------------------------------- /projects/05/ComputerMax-external.tst: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/05/ComputerMax-external.tst 5 | 6 | load Computer.hdl, 7 | output-file ComputerMax-external.out, 8 | compare-to ComputerMax-external.cmp, 9 | output-list time%S1.4.1 reset%B2.1.2 RAM16K[0]%D1.7.1 RAM16K[1]%D1.7.1 RAM16K[2]%D1.7.1; 10 | 11 | // Load a program written in the Hack machine language. 12 | // The program computes the maximum of RAM[0] and RAM[1] 13 | // and writes the result in RAM[2]. 14 | ROM32K load Max.hack, 15 | 16 | // first run: compute max(3,5) 17 | set RAM16K[0] 3, 18 | set RAM16K[1] 5, 19 | output; 20 | 21 | repeat 14 { 22 | tick, tock, output; 23 | } 24 | 25 | // reset the PC 26 | set reset 1, 27 | tick, tock, output; 28 | 29 | // second run: compute max(23456,12345) 30 | set reset 0, 31 | set RAM16K[0] 23456, 32 | set RAM16K[1] 12345, 33 | output; 34 | 35 | // The run on these inputs needs less cycles (different branching) 36 | repeat 10 { 37 | tick, tock, output; 38 | } 39 | -------------------------------------------------------------------------------- /projects/05/ComputerMax.tst: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/05/ComputerMax.tst 5 | 6 | load Computer.hdl, 7 | output-file ComputerMax.out, 8 | compare-to ComputerMax.cmp, 9 | output-list time%S1.4.1 reset%B2.1.2 ARegister[]%D1.7.1 DRegister[]%D1.7.1 PC[]%D0.4.0 RAM16K[0]%D1.7.1 RAM16K[1]%D1.7.1 RAM16K[2]%D1.7.1; 10 | 11 | // Load a program written in the Hack machine language. 12 | // The program computes the maximum of RAM[0] and RAM[1] 13 | // and writes the result in RAM[2]. 14 | 15 | ROM32K load Max.hack, 16 | 17 | // first run: compute max(3,5) 18 | set RAM16K[0] 3, 19 | set RAM16K[1] 5, 20 | output; 21 | 22 | repeat 14 { 23 | tick, tock, output; 24 | } 25 | 26 | // reset the PC 27 | set reset 1, 28 | tick, tock, output; 29 | 30 | // second run: compute max(23456,12345) 31 | set reset 0, 32 | set RAM16K[0] 23456, 33 | set RAM16K[1] 12345, 34 | output; 35 | 36 | // The run on these inputs needs less cycles (different branching) 37 | repeat 10 { 38 | tick, tock, output; 39 | } 40 | -------------------------------------------------------------------------------- /projects/05/ComputerRect-external.cmp: -------------------------------------------------------------------------------- 1 | | time | 2 | | 0 | 3 | | 1 | 4 | | 2 | 5 | | 3 | 6 | | 4 | 7 | | 5 | 8 | | 6 | 9 | | 7 | 10 | | 8 | 11 | | 9 | 12 | | 10 | 13 | | 11 | 14 | | 12 | 15 | | 13 | 16 | | 14 | 17 | | 15 | 18 | | 16 | 19 | | 17 | 20 | | 18 | 21 | | 19 | 22 | | 20 | 23 | | 21 | 24 | | 22 | 25 | | 23 | 26 | | 24 | 27 | | 25 | 28 | | 26 | 29 | | 27 | 30 | | 28 | 31 | | 29 | 32 | | 30 | 33 | | 31 | 34 | | 32 | 35 | | 33 | 36 | | 34 | 37 | | 35 | 38 | | 36 | 39 | | 37 | 40 | | 38 | 41 | | 39 | 42 | | 40 | 43 | | 41 | 44 | | 42 | 45 | | 43 | 46 | | 44 | 47 | | 45 | 48 | | 46 | 49 | | 47 | 50 | | 48 | 51 | | 49 | 52 | | 50 | 53 | | 51 | 54 | | 52 | 55 | | 53 | 56 | | 54 | 57 | | 55 | 58 | | 56 | 59 | | 57 | 60 | | 58 | 61 | | 59 | 62 | | 60 | 63 | | 61 | 64 | | 62 | 65 | | 63 | 66 | -------------------------------------------------------------------------------- /projects/05/ComputerRect-external.out: -------------------------------------------------------------------------------- 1 | | time | 2 | | 0 | 3 | | 1 | 4 | | 2 | 5 | | 3 | 6 | | 4 | 7 | | 5 | 8 | | 6 | 9 | | 7 | 10 | | 8 | 11 | | 9 | 12 | | 10 | 13 | | 11 | 14 | | 12 | 15 | | 13 | 16 | | 14 | 17 | | 15 | 18 | | 16 | 19 | | 17 | 20 | | 18 | 21 | | 19 | 22 | | 20 | 23 | | 21 | 24 | | 22 | 25 | | 23 | 26 | | 24 | 27 | | 25 | 28 | | 26 | 29 | | 27 | 30 | | 28 | 31 | | 29 | 32 | | 30 | 33 | | 31 | 34 | | 32 | 35 | | 33 | 36 | | 34 | 37 | | 35 | 38 | | 36 | 39 | | 37 | 40 | | 38 | 41 | | 39 | 42 | | 40 | 43 | | 41 | 44 | | 42 | 45 | | 43 | 46 | | 44 | 47 | | 45 | 48 | | 46 | 49 | | 47 | 50 | | 48 | 51 | | 49 | 52 | | 50 | 53 | | 51 | 54 | | 52 | 55 | | 53 | 56 | | 54 | 57 | | 55 | 58 | | 56 | 59 | | 57 | 60 | | 58 | 61 | | 59 | 62 | | 60 | 63 | | 61 | 64 | | 62 | 65 | | 63 | 66 | -------------------------------------------------------------------------------- /projects/05/ComputerRect-external.tst: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/05/ComputerRect-external.tst 5 | 6 | load Computer.hdl, 7 | output-file ComputerRect-external.out, 8 | compare-to ComputerRect-external.cmp, 9 | output-list time%S1.4.1; 10 | 11 | // Load a program written in the Hack machine language. 12 | // The program draws a rectangle of width 16 pixels and 13 | // length RAM[0] at the top left of the screen. 14 | ROM32K load Rect.hack, 15 | 16 | echo "Before you run this script, select the 'Screen' option from the 'View' menu"; 17 | 18 | echo "A small rectangle should be drawn at the top left of the screen (the 'Screen' option of the 'View' menu should be selected.)"; 19 | 20 | // draw a rectangle 16 pixels wide and 4 pixels long 21 | set RAM16K[0] 4, 22 | output; 23 | 24 | repeat 63 { 25 | tick, tock, output; 26 | } 27 | -------------------------------------------------------------------------------- /projects/05/ComputerRect.tst: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/05/ComputerRect.tst 5 | 6 | load Computer.hdl, 7 | output-file ComputerRect.out, 8 | compare-to ComputerRect.cmp, 9 | output-list time%S1.4.1 ARegister[]%D1.7.1 DRegister[]%D1.7.1 PC[]%D0.4.0 RAM16K[0]%D1.7.1 RAM16K[1]%D1.7.1 RAM16K[2]%D1.7.1; 10 | 11 | // Load a program written in the Hack machine language. 12 | // The program draws a rectangle of width 16 pixels and 13 | // length RAM[0] at the top left of the screen. 14 | ROM32K load Rect.hack, 15 | 16 | echo "Before you run this script, select the 'Screen' option from the 'View' menu"; 17 | 18 | echo "A small rectangle should be drawn at the top left of the screen (the 'Screen' option of the 'View' menu should be selected.)"; 19 | 20 | // Draws a rectangle 16 pixels wide and 4 pixels long 21 | set RAM16K[0] 4, 22 | output; 23 | 24 | repeat 63 { 25 | tick, tock, output; 26 | } 27 | -------------------------------------------------------------------------------- /projects/05/Max.hack: -------------------------------------------------------------------------------- 1 | 0000000000000000 2 | 1111110000010000 3 | 0000000000000001 4 | 1111010011010000 5 | 0000000000001010 6 | 1110001100000001 7 | 0000000000000001 8 | 1111110000010000 9 | 0000000000001100 10 | 1110101010000111 11 | 0000000000000000 12 | 1111110000010000 13 | 0000000000000010 14 | 1110001100001000 15 | 0000000000001110 16 | 1110101010000111 17 | -------------------------------------------------------------------------------- /projects/05/Or16Way.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/01/Or16Way.hdl 5 | 6 | /** 7 | * 16-way Or: 8 | * out = (in[0] or in[1] or ... or in[15]) 9 | */ 10 | 11 | CHIP Or16Way { 12 | IN in[16]; 13 | OUT out; 14 | 15 | PARTS: 16 | // Put your code here: 17 | Or(a=in[0], b=in[1], out=or1); 18 | Or(a=or1, b=in[2], out=or2); 19 | Or(a=or2, b=in[3], out=or3); 20 | Or(a=or3, b=in[4], out=or4); 21 | Or(a=or4, b=in[5], out=or5); 22 | Or(a=or5, b=in[6], out=or6); 23 | Or(a=or6, b=in[7], out=or7); 24 | Or(a=or7, b=in[8], out=or8); 25 | Or(a=or8, b=in[9], out=or9); 26 | Or(a=or9, b=in[10], out=or10); 27 | Or(a=or10, b=in[11], out=or11); 28 | Or(a=or11, b=in[12], out=or12); 29 | Or(a=or12, b=in[13], out=or13); 30 | Or(a=or13, b=in[14], out=or14); 31 | Or(a=or14, b=in[15], out=out); 32 | 33 | } 34 | -------------------------------------------------------------------------------- /projects/05/Rect.hack: -------------------------------------------------------------------------------- 1 | 0000000000000000 2 | 1111110000010000 3 | 0000000000010111 4 | 1110001100000110 5 | 0000000000010000 6 | 1110001100001000 7 | 0100000000000000 8 | 1110110000010000 9 | 0000000000010001 10 | 1110001100001000 11 | 0000000000010001 12 | 1111110000100000 13 | 1110111010001000 14 | 0000000000010001 15 | 1111110000010000 16 | 0000000000100000 17 | 1110000010010000 18 | 0000000000010001 19 | 1110001100001000 20 | 0000000000010000 21 | 1111110010011000 22 | 0000000000001010 23 | 1110001100000001 24 | 0000000000010111 25 | 1110101010000111 26 | -------------------------------------------------------------------------------- /projects/06/Assembler.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/projects/06/Assembler.jar -------------------------------------------------------------------------------- /projects/06/Assembler/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /projects/06/Assembler/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | HackAssembler 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | -------------------------------------------------------------------------------- /projects/06/Assembler/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Main-Class: org.reion.Assembler 3 | 4 | -------------------------------------------------------------------------------- /projects/06/add/Add.asm: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/06/add/Add.asm 5 | 6 | // Computes R0 = 2 + 3 7 | 8 | @2 9 | D=A 10 | @3 11 | D=D+A 12 | @0 13 | M=D 14 | -------------------------------------------------------------------------------- /projects/06/add/Add.hack: -------------------------------------------------------------------------------- 1 | 0000000000000010 2 | 1110110000010000 3 | 0000000000000011 4 | 1110000010010000 5 | 0000000000000000 6 | 1110001100001000 7 | -------------------------------------------------------------------------------- /projects/06/max/Max.asm: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/06/max/Max.asm 5 | 6 | // Computes R2 = max(R0, R1) (R0,R1,R2 refer to RAM[0],RAM[1],RAM[2]) 7 | 8 | @R0 9 | D=M // D = first number 10 | @R1 11 | D=D-M // D = first number - second number 12 | @OUTPUT_FIRST 13 | D;JGT // if D>0 (first is greater) goto output_first 14 | @R1 15 | D=M // D = second number 16 | @OUTPUT_D 17 | 0;JMP // goto output_d 18 | (OUTPUT_FIRST) 19 | @R0 20 | D=M // D = first number 21 | (OUTPUT_D) 22 | @R2 23 | M=D // M[2] = D (greatest number) 24 | (INFINITE_LOOP) 25 | @INFINITE_LOOP 26 | 0;JMP // infinite loop 27 | -------------------------------------------------------------------------------- /projects/06/max/Max.hack: -------------------------------------------------------------------------------- 1 | 0000000000000000 2 | 1111110000010000 3 | 0000000000000001 4 | 1111010011010000 5 | 0000000000001010 6 | 1110001100000001 7 | 0000000000000001 8 | 1111110000010000 9 | 0000000000001100 10 | 1110101010000111 11 | 0000000000000000 12 | 1111110000010000 13 | 0000000000000010 14 | 1110001100001000 15 | 0000000000001110 16 | 1110101010000111 17 | -------------------------------------------------------------------------------- /projects/06/max/MaxL.asm: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/06/max/MaxL.asm 5 | 6 | // Symbol-less version of the Max.asm program. 7 | 8 | @0 9 | D=M 10 | @1 11 | D=D-M 12 | @10 13 | D;JGT 14 | @1 15 | D=M 16 | @12 17 | 0;JMP 18 | @0 19 | D=M 20 | @2 21 | M=D 22 | @14 23 | 0;JMP 24 | -------------------------------------------------------------------------------- /projects/06/max/MaxL.hack: -------------------------------------------------------------------------------- 1 | 0000000000000000 2 | 1111110000010000 3 | 0000000000000001 4 | 1111010011010000 5 | 0000000000001010 6 | 1110001100000001 7 | 0000000000000001 8 | 1111110000010000 9 | 0000000000001100 10 | 1110101010000111 11 | 0000000000000000 12 | 1111110000010000 13 | 0000000000000010 14 | 1110001100001000 15 | 0000000000001110 16 | 1110101010000111 17 | -------------------------------------------------------------------------------- /projects/06/rect/Rect.asm: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/06/rect/Rect.asm 5 | 6 | // Draws a rectangle at the top-left corner of the screen. 7 | // The rectangle is 16 pixels wide and R0 pixels high. 8 | 9 | @0 10 | D=M 11 | @INFINITE_LOOP 12 | D;JLE 13 | @counter 14 | M=D 15 | @SCREEN 16 | D=A 17 | @address 18 | M=D 19 | (LOOP) 20 | @address 21 | A=M 22 | M=-1 23 | @address 24 | D=M 25 | @32 26 | D=D+A 27 | @address 28 | M=D 29 | @counter 30 | MD=M-1 31 | @LOOP 32 | D;JGT 33 | (INFINITE_LOOP) 34 | @INFINITE_LOOP 35 | 0;JMP 36 | -------------------------------------------------------------------------------- /projects/06/rect/Rect.hack: -------------------------------------------------------------------------------- 1 | 0000000000000000 2 | 1111110000010000 3 | 0000000000010111 4 | 1110001100000110 5 | 0000000000010000 6 | 1110001100001000 7 | 0100000000000000 8 | 1110110000010000 9 | 0000000000010001 10 | 1110001100001000 11 | 0000000000010001 12 | 1111110000100000 13 | 1110111010001000 14 | 0000000000010001 15 | 1111110000010000 16 | 0000000000100000 17 | 1110000010010000 18 | 0000000000010001 19 | 1110001100001000 20 | 0000000000010000 21 | 1111110010011000 22 | 0000000000001010 23 | 1110001100000001 24 | 0000000000010111 25 | 1110101010000111 26 | -------------------------------------------------------------------------------- /projects/06/rect/RectL.asm: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/06/rect/RectL.asm 5 | 6 | // Symbol-less version of the Rect.asm program. 7 | 8 | @0 9 | D=M 10 | @23 11 | D;JLE 12 | @16 13 | M=D 14 | @16384 15 | D=A 16 | @17 17 | M=D 18 | @17 19 | A=M 20 | M=-1 21 | @17 22 | D=M 23 | @32 24 | D=D+A 25 | @17 26 | M=D 27 | @16 28 | MD=M-1 29 | @10 30 | D;JGT 31 | @23 32 | 0;JMP 33 | -------------------------------------------------------------------------------- /projects/06/rect/RectL.hack: -------------------------------------------------------------------------------- 1 | 0000000000000000 2 | 1111110000010000 3 | 0000000000010111 4 | 1110001100000110 5 | 0000000000010000 6 | 1110001100001000 7 | 0100000000000000 8 | 1110110000010000 9 | 0000000000010001 10 | 1110001100001000 11 | 0000000000010001 12 | 1111110000100000 13 | 1110111010001000 14 | 0000000000010001 15 | 1111110000010000 16 | 0000000000100000 17 | 1110000010010000 18 | 0000000000010001 19 | 1110001100001000 20 | 0000000000010000 21 | 1111110010011000 22 | 0000000000001010 23 | 1110001100000001 24 | 0000000000010111 25 | 1110101010000111 26 | -------------------------------------------------------------------------------- /projects/07/MemoryAccess/BasicTest/BasicTest.cmp: -------------------------------------------------------------------------------- 1 | |RAM[256]|RAM[300]|RAM[401]|RAM[402]|RAM[3006|RAM[3012|RAM[3015|RAM[11] | 2 | | 472 | 10 | 21 | 22 | 36 | 42 | 45 | 510 | 3 | -------------------------------------------------------------------------------- /projects/07/MemoryAccess/BasicTest/BasicTest.out: -------------------------------------------------------------------------------- 1 | |RAM[256]|RAM[300]|RAM[401]|RAM[402]|RAM[3006|RAM[3012|RAM[3015|RAM[11] | 2 | | 472 | 10 | 21 | 22 | 36 | 42 | 45 | 510 | 3 | -------------------------------------------------------------------------------- /projects/07/MemoryAccess/BasicTest/BasicTest.tst: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/07/MemoryAccess/BasicTest/BasicTest.tst 5 | 6 | load BasicTest.asm, 7 | output-file BasicTest.out, 8 | compare-to BasicTest.cmp, 9 | output-list RAM[256]%D1.6.1 RAM[300]%D1.6.1 RAM[401]%D1.6.1 10 | RAM[402]%D1.6.1 RAM[3006]%D1.6.1 RAM[3012]%D1.6.1 11 | RAM[3015]%D1.6.1 RAM[11]%D1.6.1; 12 | 13 | set RAM[0] 256, 14 | set RAM[1] 300, 15 | set RAM[2] 400, 16 | set RAM[3] 3000, 17 | set RAM[4] 3010, 18 | 19 | repeat 600 { 20 | ticktock; 21 | } 22 | 23 | output; 24 | -------------------------------------------------------------------------------- /projects/07/MemoryAccess/BasicTest/BasicTest.vm: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/07/MemoryAccess/BasicTest/BasicTest.vm 5 | 6 | // Executes pop & push commands using the virtual memory segments. 7 | push constant 10 8 | pop local 0 9 | push constant 21 10 | push constant 22 11 | pop argument 2 12 | pop argument 1 13 | push constant 36 14 | pop this 6 15 | push constant 42 16 | push constant 45 17 | pop that 5 18 | pop that 2 19 | push constant 510 20 | pop temp 6 21 | push local 0 22 | push that 5 23 | add 24 | push argument 1 25 | sub 26 | push this 6 27 | push this 6 28 | add 29 | sub 30 | push temp 6 31 | add 32 | -------------------------------------------------------------------------------- /projects/07/MemoryAccess/BasicTest/BasicTestVME.tst: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/07/MemoryAccess/BasicTest/BasicTestVME.tst 5 | 6 | load BasicTest.vm, 7 | output-file BasicTest.out, 8 | compare-to BasicTest.cmp, 9 | output-list RAM[256]%D1.6.1 RAM[300]%D1.6.1 RAM[401]%D1.6.1 10 | RAM[402]%D1.6.1 RAM[3006]%D1.6.1 RAM[3012]%D1.6.1 11 | RAM[3015]%D1.6.1 RAM[11]%D1.6.1; 12 | 13 | set sp 256, 14 | set local 300, 15 | set argument 400, 16 | set this 3000, 17 | set that 3010, 18 | 19 | repeat 25 { 20 | vmstep; 21 | } 22 | 23 | output; 24 | -------------------------------------------------------------------------------- /projects/07/MemoryAccess/PointerTest/PointerTest.cmp: -------------------------------------------------------------------------------- 1 | |RAM[256]| RAM[3] | RAM[4] |RAM[3032|RAM[3046| 2 | | 6084 | 3030 | 3040 | 32 | 46 | 3 | -------------------------------------------------------------------------------- /projects/07/MemoryAccess/PointerTest/PointerTest.out: -------------------------------------------------------------------------------- 1 | |RAM[256]| RAM[3] | RAM[4] |RAM[3032|RAM[3046| 2 | | 6084 | 3030 | 3040 | 32 | 46 | 3 | -------------------------------------------------------------------------------- /projects/07/MemoryAccess/PointerTest/PointerTest.tst: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/07/MemoryAccess/PointerTest/PointerTest.tst 5 | 6 | load PointerTest.asm, 7 | output-file PointerTest.out, 8 | compare-to PointerTest.cmp, 9 | output-list RAM[256]%D1.6.1 RAM[3]%D1.6.1 10 | RAM[4]%D1.6.1 RAM[3032]%D1.6.1 RAM[3046]%D1.6.1; 11 | 12 | set RAM[0] 256, 13 | 14 | repeat 450 { 15 | ticktock; 16 | } 17 | 18 | output; 19 | -------------------------------------------------------------------------------- /projects/07/MemoryAccess/PointerTest/PointerTest.vm: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/07/MemoryAccess/PointerTest/PointerTest.vm 5 | 6 | // Executes pop and push commands using the 7 | // pointer, this, and that segments. 8 | push constant 3030 9 | pop pointer 0 10 | push constant 3040 11 | pop pointer 1 12 | push constant 32 13 | pop this 2 14 | push constant 46 15 | pop that 6 16 | push pointer 0 17 | push pointer 1 18 | add 19 | push this 2 20 | sub 21 | push that 6 22 | add 23 | -------------------------------------------------------------------------------- /projects/07/MemoryAccess/PointerTest/PointerTestVME.tst: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/07/MemoryAccess/PointerTest/PointerTestVME.tst 5 | 6 | load PointerTest.vm, 7 | output-file PointerTest.out, 8 | compare-to PointerTest.cmp, 9 | output-list RAM[256]%D1.6.1 RAM[3]%D1.6.1 RAM[4]%D1.6.1 10 | RAM[3032]%D1.6.1 RAM[3046]%D1.6.1; 11 | 12 | set RAM[0] 256, 13 | 14 | repeat 15 { 15 | vmstep; 16 | } 17 | 18 | output; 19 | -------------------------------------------------------------------------------- /projects/07/MemoryAccess/StaticTest/StaticTest.asm: -------------------------------------------------------------------------------- 1 | // ******* HACK ASM FILE GENERATED BY VM COMPILER ******* 2 | // VM FILE: StaticTest.vm 3 | // COMPILER: JAVA_HACK_VM_COMPILER 4 | // GEN TIME: 15-9-19 上午12:53 5 | 6 | 7 | // 'push constant 111' (Line 0) 8 | @111 9 | D=A 10 | @SP 11 | A=M 12 | M=D 13 | @SP 14 | M=M+1 15 | // 'push constant 333' (Line 1) 16 | @333 17 | D=A 18 | @SP 19 | A=M 20 | M=D 21 | @SP 22 | M=M+1 23 | // 'push constant 888' (Line 2) 24 | @888 25 | D=A 26 | @SP 27 | A=M 28 | M=D 29 | @SP 30 | M=M+1 31 | // 'pop static 8' (Line 3) 32 | @SP 33 | AM=M-1 34 | D=M 35 | @R24 36 | M=D 37 | // 'pop static 3' (Line 4) 38 | @SP 39 | AM=M-1 40 | D=M 41 | @R19 42 | M=D 43 | // 'pop static 1' (Line 5) 44 | @SP 45 | AM=M-1 46 | D=M 47 | @R17 48 | M=D 49 | // 'push static 3' (Line 6) 50 | @R19 51 | D=M 52 | @SP 53 | A=M 54 | M=D 55 | @SP 56 | M=M+1 57 | // 'push static 1' (Line 7) 58 | @R17 59 | D=M 60 | @SP 61 | A=M 62 | M=D 63 | @SP 64 | M=M+1 65 | // 'sub' (Line 8) 66 | @SP 67 | AM=M-1 68 | D=M 69 | @SP 70 | AM=M-1 71 | M=M-D 72 | @SP 73 | M=M+1 74 | // 'push static 8' (Line 9) 75 | @R24 76 | D=M 77 | @SP 78 | A=M 79 | M=D 80 | @SP 81 | M=M+1 82 | // 'add' (Line 10) 83 | @SP 84 | AM=M-1 85 | D=M 86 | @SP 87 | AM=M-1 88 | M=D+M 89 | @SP 90 | M=M+1 91 | -------------------------------------------------------------------------------- /projects/07/MemoryAccess/StaticTest/StaticTest.cmp: -------------------------------------------------------------------------------- 1 | |RAM[256]| 2 | | 1110 | 3 | -------------------------------------------------------------------------------- /projects/07/MemoryAccess/StaticTest/StaticTest.out: -------------------------------------------------------------------------------- 1 | |RAM[256]| 2 | | 1110 | 3 | -------------------------------------------------------------------------------- /projects/07/MemoryAccess/StaticTest/StaticTest.tst: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/07/MemoryAccess/StaticTest/StaticTest.tst 5 | 6 | load StaticTest.asm, 7 | output-file StaticTest.out, 8 | compare-to StaticTest.cmp, 9 | output-list RAM[256]%D1.6.1; 10 | 11 | set RAM[0] 256, 12 | 13 | repeat 200 { 14 | ticktock; 15 | } 16 | 17 | output; 18 | -------------------------------------------------------------------------------- /projects/07/MemoryAccess/StaticTest/StaticTest.vm: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/07/MemoryAccess/StaticTest/StaticTest.vm 5 | 6 | // Executes pop and push commands using the static segment. 7 | push constant 111 8 | push constant 333 9 | push constant 888 10 | pop static 8 11 | pop static 3 12 | pop static 1 13 | push static 3 14 | push static 1 15 | sub 16 | push static 8 17 | add 18 | -------------------------------------------------------------------------------- /projects/07/MemoryAccess/StaticTest/StaticTestVME.tst: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/07/MemoryAccess/StaticTest/StaticTestVME.tst 5 | 6 | load StaticTest.vm, 7 | output-file StaticTest.out, 8 | compare-to StaticTest.cmp, 9 | output-list RAM[256]%D1.6.1; 10 | 11 | set sp 256, 12 | 13 | repeat 11 { 14 | vmstep; 15 | } 16 | 17 | output; 18 | -------------------------------------------------------------------------------- /projects/07/StackArithmetic/SimpleAdd/SimpleAdd.asm: -------------------------------------------------------------------------------- 1 | // ******* HACK ASM FILE GENERATED BY VM COMPILER ******* 2 | // VM FILE: SimpleAdd.vm 3 | // COMPILER: JAVA_HACK_VM_COMPILER 4 | // GEN TIME: 15-9-19 上午12:52 5 | 6 | 7 | // 'push constant 7' (Line 0) 8 | @7 9 | D=A 10 | @SP 11 | A=M 12 | M=D 13 | @SP 14 | M=M+1 15 | // 'push constant 8' (Line 1) 16 | @8 17 | D=A 18 | @SP 19 | A=M 20 | M=D 21 | @SP 22 | M=M+1 23 | // 'add' (Line 2) 24 | @SP 25 | AM=M-1 26 | D=M 27 | @SP 28 | AM=M-1 29 | M=D+M 30 | @SP 31 | M=M+1 32 | -------------------------------------------------------------------------------- /projects/07/StackArithmetic/SimpleAdd/SimpleAdd.cmp: -------------------------------------------------------------------------------- 1 | | RAM[0] | RAM[256] | 2 | | 257 | 15 | 3 | -------------------------------------------------------------------------------- /projects/07/StackArithmetic/SimpleAdd/SimpleAdd.out: -------------------------------------------------------------------------------- 1 | | RAM[0] | RAM[256] | 2 | | 257 | 15 | 3 | -------------------------------------------------------------------------------- /projects/07/StackArithmetic/SimpleAdd/SimpleAdd.tst: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/07/StackArithmetic/SimpleAdd/SimpleAdd.tst 5 | 6 | load SimpleAdd.asm, 7 | output-file SimpleAdd.out, 8 | compare-to SimpleAdd.cmp, 9 | output-list RAM[0]%D2.6.2 RAM[256]%D2.6.2; 10 | 11 | set RAM[0] 256, 12 | 13 | repeat 60 { 14 | ticktock; 15 | } 16 | 17 | output; 18 | -------------------------------------------------------------------------------- /projects/07/StackArithmetic/SimpleAdd/SimpleAdd.vm: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/07/StackArithmetic/SimpleAdd/SimpleAdd.vm 5 | 6 | // Pushes and adds two constants. 7 | push constant 7 8 | push constant 8 9 | add 10 | -------------------------------------------------------------------------------- /projects/07/StackArithmetic/SimpleAdd/SimpleAddVME.tst: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/07/StackArithmetic/SimpleAdd/SimpleAddVME.tst 5 | 6 | load SimpleAdd.vm, 7 | output-file SimpleAdd.out, 8 | compare-to SimpleAdd.cmp, 9 | output-list RAM[0]%D2.6.2 RAM[256]%D2.6.2; 10 | 11 | set RAM[0] 256, 12 | 13 | repeat 3 { 14 | vmstep; 15 | } 16 | 17 | output; 18 | -------------------------------------------------------------------------------- /projects/07/StackArithmetic/StackTest/StackTest.cmp: -------------------------------------------------------------------------------- 1 | | RAM[0] | RAM[256] | RAM[257] | RAM[258] | RAM[259] | RAM[260] | 2 | | 266 | -1 | 0 | 0 | 0 | -1 | 3 | | RAM[261] | RAM[262] | RAM[263] | RAM[264] | RAM[265] | 4 | | 0 | -1 | 0 | 0 | -91 | 5 | -------------------------------------------------------------------------------- /projects/07/StackArithmetic/StackTest/StackTest.out: -------------------------------------------------------------------------------- 1 | | RAM[0] | RAM[256] | RAM[257] | RAM[258] | RAM[259] | RAM[260] | 2 | | 266 | -1 | 0 | 0 | 0 | -1 | 3 | | RAM[261] | RAM[262] | RAM[263] | RAM[264] | RAM[265] | 4 | | 0 | -1 | 0 | 0 | -91 | 5 | -------------------------------------------------------------------------------- /projects/07/StackArithmetic/StackTest/StackTest.tst: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/07/StackArithmetic/StackTest/StackTest.tst 5 | 6 | load StackTest.asm, 7 | output-file StackTest.out, 8 | compare-to StackTest.cmp, 9 | output-list RAM[0]%D2.6.2 10 | RAM[256]%D2.6.2 RAM[257]%D2.6.2 RAM[258]%D2.6.2 RAM[259]%D2.6.2 RAM[260]%D2.6.2; 11 | 12 | set RAM[0] 256, 13 | 14 | repeat 1000 { 15 | ticktock; 16 | } 17 | 18 | output; 19 | output-list RAM[261]%D2.6.2 RAM[262]%D2.6.2 RAM[263]%D2.6.2 RAM[264]%D2.6.2 RAM[265]%D2.6.2; 20 | output; 21 | -------------------------------------------------------------------------------- /projects/07/StackArithmetic/StackTest/StackTest.vm: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/07/StackArithmetic/StackTest/StackTest.vm 5 | 6 | // Executes a sequence of arithmetic and logical operations 7 | // on the stack. 8 | push constant 17 9 | push constant 17 10 | eq 11 | push constant 17 12 | push constant 16 13 | eq 14 | push constant 16 15 | push constant 17 16 | eq 17 | push constant 892 18 | push constant 891 19 | lt 20 | push constant 891 21 | push constant 892 22 | lt 23 | push constant 891 24 | push constant 891 25 | lt 26 | push constant 32767 27 | push constant 32766 28 | gt 29 | push constant 32766 30 | push constant 32767 31 | gt 32 | push constant 32766 33 | push constant 32766 34 | gt 35 | push constant 57 36 | push constant 31 37 | push constant 53 38 | add 39 | push constant 112 40 | sub 41 | neg 42 | and 43 | push constant 82 44 | or 45 | not 46 | -------------------------------------------------------------------------------- /projects/07/StackArithmetic/StackTest/StackTestVME.tst: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/07/StackArithmetic/StackTest/StackTestVME.tst 5 | 6 | load StackTest.vm, 7 | output-file StackTest.out, 8 | compare-to StackTest.cmp, 9 | output-list RAM[0]%D2.6.2 10 | RAM[256]%D2.6.2 RAM[257]%D2.6.2 RAM[258]%D2.6.2 RAM[259]%D2.6.2 RAM[260]%D2.6.2; 11 | 12 | set RAM[0] 256, 13 | 14 | repeat 38 { 15 | vmstep; 16 | } 17 | 18 | output; 19 | output-list RAM[261]%D2.6.2 RAM[262]%D2.6.2 RAM[263]%D2.6.2 RAM[264]%D2.6.2 RAM[265]%D2.6.2; 20 | output; 21 | -------------------------------------------------------------------------------- /projects/07/VMTranslator.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/projects/07/VMTranslator.jar -------------------------------------------------------------------------------- /projects/07/VMTranslator/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /projects/07/VMTranslator/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | VMTranslator 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | -------------------------------------------------------------------------------- /projects/07/VMTranslator/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Main-Class: org.reion.VMTranslator 3 | 4 | -------------------------------------------------------------------------------- /projects/08/FunctionCalls/FibonacciElement/FibonacciElement.cmp: -------------------------------------------------------------------------------- 1 | | RAM[0] |RAM[261]| 2 | | 262 | 3 | 3 | -------------------------------------------------------------------------------- /projects/08/FunctionCalls/FibonacciElement/FibonacciElement.out: -------------------------------------------------------------------------------- 1 | | RAM[0] |RAM[261]| 2 | | 262 | 3 | 3 | -------------------------------------------------------------------------------- /projects/08/FunctionCalls/FibonacciElement/FibonacciElement.tst: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/08/FunctionCalls/FibonacciElement/FibonacciElement.tst 5 | 6 | // FibonacciElement.asm is the result of translating both Main.vm and Sys.vm. 7 | 8 | load FibonacciElement.asm, 9 | output-file FibonacciElement.out, 10 | compare-to FibonacciElement.cmp, 11 | output-list RAM[0]%D1.6.1 RAM[261]%D1.6.1; 12 | 13 | repeat 6000 { 14 | ticktock; 15 | } 16 | 17 | output; 18 | -------------------------------------------------------------------------------- /projects/08/FunctionCalls/FibonacciElement/FibonacciElementVME.tst: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/08/FunctionCalls/FibonacciElement/FibonacciElementVME.tst 5 | 6 | load, // Load all the VM files from the current directory 7 | output-file FibonacciElement.out, 8 | compare-to FibonacciElement.cmp, 9 | output-list RAM[0]%D1.6.1 RAM[261]%D1.6.1; 10 | 11 | set sp 261, 12 | 13 | repeat 110 { 14 | vmstep; 15 | } 16 | 17 | output; 18 | -------------------------------------------------------------------------------- /projects/08/FunctionCalls/FibonacciElement/Main.vm: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/08/FunctionCalls/FibonacciElement/Main.vm 5 | 6 | // Computes the n'th element of the Fibonacci series, recursively. 7 | // n is given in argument[0]. Called by the Sys.init function 8 | // (part of the Sys.vm file), which also pushes the argument[0] 9 | // parameter before this code starts running. 10 | 11 | function Main.fibonacci 0 12 | push argument 0 13 | push constant 2 14 | lt // check if n < 2 15 | if-goto IF_TRUE 16 | goto IF_FALSE 17 | label IF_TRUE // if n<2, return n 18 | push argument 0 19 | return 20 | label IF_FALSE // if n>=2, return fib(n-2)+fib(n-1) 21 | push argument 0 22 | push constant 2 23 | sub 24 | call Main.fibonacci 1 // compute fib(n-2) 25 | push argument 0 26 | push constant 1 27 | sub 28 | call Main.fibonacci 1 // compute fib(n-1) 29 | add // return fib(n-1) + fib(n-2) 30 | return 31 | -------------------------------------------------------------------------------- /projects/08/FunctionCalls/FibonacciElement/Sys.vm: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/08/FunctionCalls/FibonacciElement/Sys.vm 5 | 6 | // Pushes n onto the stack and calls the Main.fibonacii function, 7 | // which computes the n'th element of the Fibonacci series. 8 | // The Sys.init function is called "automatically" by the 9 | // bootstrap code. 10 | 11 | function Sys.init 0 12 | push constant 4 13 | call Main.fibonacci 1 // Compute the 4'th fibonacci element 14 | label WHILE 15 | goto WHILE // Loop infinitely 16 | -------------------------------------------------------------------------------- /projects/08/FunctionCalls/NestedCall/NestedCall.cmp: -------------------------------------------------------------------------------- 1 | | RAM[0] | RAM[1] | RAM[2] | RAM[5] | RAM[6] | 2 | | 261 | 261 | 256 | 135 | 246 | 3 | -------------------------------------------------------------------------------- /projects/08/FunctionCalls/NestedCall/NestedCall.out: -------------------------------------------------------------------------------- 1 | | RAM[0] | RAM[1] | RAM[2] | RAM[5] | RAM[6] | 2 | | 261 | 261 | 256 | 135 | 246 | 3 | -------------------------------------------------------------------------------- /projects/08/FunctionCalls/NestedCall/NestedCall.tst: -------------------------------------------------------------------------------- 1 | // Test file for NestedCall test. 2 | 3 | load NestedCall.asm, 4 | output-file NestedCall.out, 5 | compare-to NestedCall.cmp, 6 | output-list RAM[0]%D1.6.1 RAM[1]%D1.6.1 RAM[2]%D1.6.1 RAM[5]%D1.6.1 RAM[6]%D1.6.1; 7 | 8 | set RAM[0] 261, 9 | set RAM[1] 261, 10 | set RAM[2] 256, 11 | set RAM[3] -1, 12 | set RAM[4] -1, 13 | set RAM[256] 1234, // fake RIP 14 | set RAM[257] -1, 15 | set RAM[258] -1, 16 | set RAM[259] -1, 17 | set RAM[260] -1, 18 | 19 | repeat 1000 { 20 | ticktock; 21 | } 22 | 23 | output; 24 | -------------------------------------------------------------------------------- /projects/08/FunctionCalls/NestedCall/NestedCallVME.tst: -------------------------------------------------------------------------------- 1 | // Test file for NestedCall test. 2 | 3 | load Sys.vm, 4 | output-file NestedCall.out, 5 | compare-to NestedCall.cmp, 6 | output-list RAM[0]%D1.6.1 RAM[1]%D1.6.1 RAM[2]%D1.6.1 RAM[5]%D1.6.1 RAM[6]%D1.6.1; 7 | 8 | set RAM[0] 261, 9 | set RAM[1] 261, 10 | set RAM[2] 256, 11 | set RAM[3] -1, 12 | set RAM[4] -1, 13 | set RAM[256] 1234, // fake RIP 14 | set RAM[257] -1, 15 | set RAM[258] -1, 16 | set RAM[259] -1, 17 | set RAM[260] -1, 18 | 19 | set sp 261, 20 | set local 261, 21 | set argument 256, 22 | set this 3000, 23 | set that 4000; 24 | 25 | repeat 50 { 26 | vmstep; 27 | } 28 | output; 29 | -------------------------------------------------------------------------------- /projects/08/FunctionCalls/NestedCall/Sys.vm: -------------------------------------------------------------------------------- 1 | // Sys.vm for NestedCall test. 2 | // 3 | // Copyright (C) 2013 Mark A. Armbrust. 4 | // Permission granted for educational use. 5 | 6 | // Sys.init() calls Sys.main(), stores the return value in temp 1, 7 | // and enters an infinite loop. 8 | 9 | function Sys.init 0 10 | call Sys.main 0 11 | pop temp 1 12 | label LOOP 13 | goto LOOP 14 | 15 | // Sys.main() calls Sys.add12(123) and stores return value (135) in temp 0. 16 | // Returns 456. 17 | 18 | function Sys.main 0 19 | push constant 123 20 | call Sys.add12 1 21 | pop temp 0 22 | push constant 246 23 | return 24 | 25 | // Sys.add12(int x) returns x+12. 26 | // It allocates 3 words of local storage to test the deallocation of local 27 | // storage during the return. 28 | 29 | function Sys.add12 3 30 | push argument 0 31 | push constant 12 32 | add 33 | return 34 | -------------------------------------------------------------------------------- /projects/08/FunctionCalls/SimpleFunction/SimpleFunction.cmp: -------------------------------------------------------------------------------- 1 | | RAM[0] | RAM[1] | RAM[2] | RAM[3] | RAM[4] |RAM[310]| 2 | | 311 | 305 | 300 | 3010 | 4010 | 1196 | 3 | -------------------------------------------------------------------------------- /projects/08/FunctionCalls/SimpleFunction/SimpleFunction.out: -------------------------------------------------------------------------------- 1 | | RAM[0] | RAM[1] | RAM[2] | RAM[3] | RAM[4] |RAM[310]| 2 | | 311 | 305 | 300 | 3010 | 4010 | 1196 | 3 | -------------------------------------------------------------------------------- /projects/08/FunctionCalls/SimpleFunction/SimpleFunction.tst: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/08/FunctionCalls/SimpleFunction/SimpleFunction.tst 5 | 6 | load SimpleFunction.asm, 7 | output-file SimpleFunction.out, 8 | compare-to SimpleFunction.cmp, 9 | output-list RAM[0]%D1.6.1 RAM[1]%D1.6.1 RAM[2]%D1.6.1 10 | RAM[3]%D1.6.1 RAM[4]%D1.6.1 RAM[310]%D1.6.1; 11 | 12 | set RAM[0] 317, 13 | set RAM[1] 317, 14 | set RAM[2] 310, 15 | set RAM[3] 3000, 16 | set RAM[4] 4000, 17 | set RAM[310] 1234, 18 | set RAM[311] 37, 19 | set RAM[312] 1000, 20 | set RAM[313] 305, 21 | set RAM[314] 300, 22 | set RAM[315] 3010, 23 | set RAM[316] 4010, 24 | 25 | repeat 300 { 26 | ticktock; 27 | } 28 | 29 | output; 30 | -------------------------------------------------------------------------------- /projects/08/FunctionCalls/SimpleFunction/SimpleFunction.vm: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/08/FunctionCalls/SimpleFunction/SimpleFunction.vm 5 | 6 | // Performs a simple calculation and returns the result. 7 | function SimpleFunction.test 2 8 | push local 0 9 | push local 1 10 | add 11 | not 12 | push argument 0 13 | add 14 | push argument 1 15 | sub 16 | return 17 | -------------------------------------------------------------------------------- /projects/08/FunctionCalls/SimpleFunction/SimpleFunctionVME.tst: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/08/FunctionCalls/SimpleFunction/SimpleFunctionVME.tst 5 | 6 | load SimpleFunction.vm, 7 | output-file SimpleFunction.out, 8 | compare-to SimpleFunction.cmp, 9 | output-list RAM[0]%D1.6.1 RAM[1]%D1.6.1 RAM[2]%D1.6.1 10 | RAM[3]%D1.6.1 RAM[4]%D1.6.1 RAM[310]%D1.6.1; 11 | 12 | set sp 317, 13 | set local 317, 14 | set argument 310, 15 | set this 3000, 16 | set that 4000, 17 | set argument[0] 1234, 18 | set argument[1] 37, 19 | set argument[2] 9, 20 | set argument[3] 305, 21 | set argument[4] 300, 22 | set argument[5] 3010, 23 | set argument[6] 4010, 24 | 25 | repeat 10 { 26 | vmstep; 27 | } 28 | 29 | output; 30 | -------------------------------------------------------------------------------- /projects/08/FunctionCalls/StaticsTest/Class1.vm: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/08/FunctionCalls/StaticsTest/Class1.vm 5 | 6 | // Stores two supplied arguments in static[0] and static[1]. 7 | function Class1.set 0 8 | push argument 0 9 | pop static 0 10 | push argument 1 11 | pop static 1 12 | push constant 0 13 | return 14 | 15 | // Returns static[0] - static[1]. 16 | function Class1.get 0 17 | push static 0 18 | push static 1 19 | sub 20 | return 21 | -------------------------------------------------------------------------------- /projects/08/FunctionCalls/StaticsTest/Class2.vm: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/08/FunctionCalls/StaticsTest/Class2.vm 5 | 6 | // Stores two supplied arguments in static[0] and static[1]. 7 | function Class2.set 0 8 | push argument 0 9 | pop static 0 10 | push argument 1 11 | pop static 1 12 | push constant 0 13 | return 14 | 15 | // Returns static[0] - static[1]. 16 | function Class2.get 0 17 | push static 0 18 | push static 1 19 | sub 20 | return 21 | -------------------------------------------------------------------------------- /projects/08/FunctionCalls/StaticsTest/StaticsTest.cmp: -------------------------------------------------------------------------------- 1 | | RAM[0] |RAM[261]|RAM[262]| 2 | | 263 | -2 | 8 | 3 | -------------------------------------------------------------------------------- /projects/08/FunctionCalls/StaticsTest/StaticsTest.out: -------------------------------------------------------------------------------- 1 | | RAM[0] |RAM[261]|RAM[262]| 2 | | 263 | -2 | 8 | 3 | -------------------------------------------------------------------------------- /projects/08/FunctionCalls/StaticsTest/StaticsTest.tst: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/08/FunctionCalls/StaticsTest/StaticsTest.tst 5 | 6 | load StaticsTest.asm, 7 | output-file StaticsTest.out, 8 | compare-to StaticsTest.cmp, 9 | output-list RAM[0]%D1.6.1 RAM[261]%D1.6.1 RAM[262]%D1.6.1; 10 | 11 | set RAM[0] 256, 12 | 13 | repeat 2500 { 14 | ticktock; 15 | } 16 | 17 | output; 18 | -------------------------------------------------------------------------------- /projects/08/FunctionCalls/StaticsTest/StaticsTestVME.tst: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/08/FunctionCalls/StaticsTest/StaticsTestVME.tst 5 | 6 | load, // Load all the VM files from the current directory. 7 | output-file StaticsTest.out, 8 | compare-to StaticsTest.cmp, 9 | output-list RAM[0]%D1.6.1 RAM[261]%D1.6.1 RAM[262]%D1.6.1; 10 | 11 | set sp 261, 12 | 13 | repeat 36 { 14 | vmstep; 15 | } 16 | 17 | output; 18 | -------------------------------------------------------------------------------- /projects/08/FunctionCalls/StaticsTest/Sys.vm: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/08/FunctionCalls/StaticsTest/Sys.vm 5 | 6 | // Tests that different functions, stored in two different 7 | // class files, manipulate the static segment correctly. 8 | function Sys.init 0 9 | push constant 6 10 | push constant 8 11 | call Class1.set 2 12 | pop temp 0 // Dumps the return value 13 | push constant 23 14 | push constant 15 15 | call Class2.set 2 16 | pop temp 0 // Dumps the return value 17 | call Class1.get 0 18 | call Class2.get 0 19 | label WHILE 20 | goto WHILE 21 | -------------------------------------------------------------------------------- /projects/08/ProgramFlow/BasicLoop/BasicLoop.cmp: -------------------------------------------------------------------------------- 1 | | RAM[0] |RAM[256]| 2 | | 257 | 6 | 3 | -------------------------------------------------------------------------------- /projects/08/ProgramFlow/BasicLoop/BasicLoop.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/projects/08/ProgramFlow/BasicLoop/BasicLoop.out -------------------------------------------------------------------------------- /projects/08/ProgramFlow/BasicLoop/BasicLoop.tst: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/08/ProgramFlow/BasicLoop/BasicLoop.tst 5 | 6 | load BasicLoop.asm, 7 | output-file BasicLoop.out, 8 | compare-to BasicLoop.cmp, 9 | output-list RAM[0]%D1.6.1 RAM[256]%D1.6.1; 10 | 11 | set RAM[0] 256, 12 | set RAM[1] 300, 13 | set RAM[2] 400, 14 | set RAM[400] 3, 15 | 16 | repeat 600 { 17 | ticktock; 18 | } 19 | 20 | output; 21 | -------------------------------------------------------------------------------- /projects/08/ProgramFlow/BasicLoop/BasicLoop.vm: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/08/ProgramFlow/BasicLoop/BasicLoop.vm 5 | 6 | // Computes the sum 1 + 2 + ... + argument[0] and pushes the 7 | // result onto the stack. Argument[0] is initialized by the test 8 | // script before this code starts running. 9 | push constant 0 10 | pop local 0 // initialize sum = 0 11 | label LOOP_START 12 | push argument 0 13 | push local 0 14 | add 15 | pop local 0 // sum = sum + counter 16 | push argument 0 17 | push constant 1 18 | sub 19 | pop argument 0 // counter-- 20 | push argument 0 21 | if-goto LOOP_START // If counter > 0, goto LOOP_START 22 | push local 0 23 | -------------------------------------------------------------------------------- /projects/08/ProgramFlow/BasicLoop/BasicLoopVME.tst: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/08/ProgramFlow/BasicLoop/BasicLoopVME.tst 5 | 6 | load BasicLoop.vm, 7 | output-file BasicLoop.out, 8 | compare-to BasicLoop.cmp, 9 | output-list RAM[0]%D1.6.1 RAM[256]%D1.6.1; 10 | 11 | set sp 256, 12 | set local 300, 13 | set argument 400, 14 | set argument[0] 3, 15 | 16 | repeat 33 { 17 | vmstep; 18 | } 19 | 20 | output; 21 | -------------------------------------------------------------------------------- /projects/08/ProgramFlow/FibonacciSeries/FibonacciSeries.cmp: -------------------------------------------------------------------------------- 1 | |RAM[3000]|RAM[3001]|RAM[3002]|RAM[3003]|RAM[3004]|RAM[3005]| 2 | | 0 | 1 | 1 | 2 | 3 | 5 | 3 | -------------------------------------------------------------------------------- /projects/08/ProgramFlow/FibonacciSeries/FibonacciSeries.out: -------------------------------------------------------------------------------- 1 | |RAM[3000]|RAM[3001]|RAM[3002]|RAM[3003]|RAM[3004]|RAM[3005]| 2 | | 0 | 1 | 1 | 2 | 3 | 5 | 3 | -------------------------------------------------------------------------------- /projects/08/ProgramFlow/FibonacciSeries/FibonacciSeries.tst: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/08/ProgramFlow/FibonacciSeries/FibonacciSeries.tst 5 | 6 | load FibonacciSeries.asm, 7 | output-file FibonacciSeries.out, 8 | compare-to FibonacciSeries.cmp, 9 | output-list RAM[3000]%D1.6.2 RAM[3001]%D1.6.2 RAM[3002]%D1.6.2 10 | RAM[3003]%D1.6.2 RAM[3004]%D1.6.2 RAM[3005]%D1.6.2; 11 | 12 | set RAM[0] 256, 13 | set RAM[1] 300, 14 | set RAM[2] 400, 15 | set RAM[400] 6, 16 | set RAM[401] 3000, 17 | 18 | repeat 1100 { 19 | ticktock; 20 | } 21 | 22 | output; 23 | -------------------------------------------------------------------------------- /projects/08/ProgramFlow/FibonacciSeries/FibonacciSeriesVME.tst: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/08/ProgramFlow/FibonacciSeries/FibonacciSeriesVME.tst 5 | 6 | load FibonacciSeries.vm, 7 | output-file FibonacciSeries.out, 8 | compare-to FibonacciSeries.cmp, 9 | output-list RAM[3000]%D1.6.2 RAM[3001]%D1.6.2 RAM[3002]%D1.6.2 10 | RAM[3003]%D1.6.2 RAM[3004]%D1.6.2 RAM[3005]%D1.6.2; 11 | 12 | set sp 256, 13 | set local 300, 14 | set argument 400, 15 | set argument[0] 6, 16 | set argument[1] 3000, 17 | 18 | repeat 73 { 19 | vmstep; 20 | } 21 | 22 | output; 23 | -------------------------------------------------------------------------------- /projects/08/VMTranslator.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/projects/08/VMTranslator.jar -------------------------------------------------------------------------------- /projects/08/VMTranslator/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /projects/08/VMTranslator/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | VMTranslator 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | -------------------------------------------------------------------------------- /projects/08/VMTranslator/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Main-Class: org.reion.VMTranslator 3 | 4 | -------------------------------------------------------------------------------- /projects/09/CountdownTimer/Countdown.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/projects/09/CountdownTimer/Countdown.gif -------------------------------------------------------------------------------- /projects/09/Hello/Hello.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/projects/09/Hello/Hello.gif -------------------------------------------------------------------------------- /projects/09/Hello/Hello.vm: -------------------------------------------------------------------------------- 1 | function Hello.new 0 2 | push constant 1 3 | call Memory.alloc 1 4 | pop pointer 0 5 | push argument 0 6 | pop this 0 7 | push pointer 0 8 | return 9 | function Hello.sayHi 0 10 | push argument 0 11 | pop pointer 0 12 | push constant 6 13 | call String.new 1 14 | push constant 72 15 | call String.appendChar 2 16 | push constant 101 17 | call String.appendChar 2 18 | push constant 108 19 | call String.appendChar 2 20 | push constant 108 21 | call String.appendChar 2 22 | push constant 111 23 | call String.appendChar 2 24 | push constant 44 25 | call String.appendChar 2 26 | call Output.printString 1 27 | pop temp 0 28 | push this 0 29 | call Output.printString 1 30 | pop temp 0 31 | push constant 1 32 | call String.new 1 33 | push constant 33 34 | call String.appendChar 2 35 | call Output.printString 1 36 | pop temp 0 37 | push constant 0 38 | return 39 | function Hello.dispose 0 40 | push argument 0 41 | pop pointer 0 42 | push pointer 0 43 | call Memory.deAlloc 1 44 | pop temp 0 45 | push constant 0 46 | return 47 | -------------------------------------------------------------------------------- /projects/09/Jack OS API.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/projects/09/Jack OS API.pdf -------------------------------------------------------------------------------- /projects/09/RollingBall/Main.vm: -------------------------------------------------------------------------------- 1 | function Main.main 1 2 | call RollingBall.new 0 3 | pop local 0 4 | push local 0 5 | call RollingBall.rolling 1 6 | pop temp 0 7 | push local 0 8 | call RollingBall.dispose 1 9 | pop temp 0 10 | push constant 0 11 | return 12 | -------------------------------------------------------------------------------- /projects/09/RollingBall/RollingBall.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/projects/09/RollingBall/RollingBall.gif -------------------------------------------------------------------------------- /projects/09/Square/Main.jack: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/09/Square/Main.jack 5 | 6 | /** 7 | * The Main class initializes a new Square Dance game and starts it. 8 | */ 9 | class Main { 10 | 11 | /** Initializes a new game and starts it. */ 12 | function void main() { 13 | var SquareGame game; 14 | 15 | let game = SquareGame.new(); 16 | do game.run(); 17 | do game.dispose(); 18 | 19 | return; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /projects/09/Square/Main.vm: -------------------------------------------------------------------------------- 1 | function Main.main 1 2 | call SquareGame.new 0 3 | pop local 0 4 | push local 0 5 | call SquareGame.run 1 6 | pop temp 0 7 | push local 0 8 | call SquareGame.dispose 1 9 | pop temp 0 10 | push constant 0 11 | return 12 | -------------------------------------------------------------------------------- /projects/09/Square/Square.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/projects/09/Square/Square.gif -------------------------------------------------------------------------------- /projects/10/ArrayTest/Main.jack: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/10/ArrayTest/Main.jack 5 | 6 | /** Computes the average of a sequence of integers. */ 7 | class Main { 8 | function void main() { 9 | var Array a; 10 | var int length; 11 | var int i, sum; 12 | 13 | let length = Keyboard.readInt("HOW MANY NUMBERS? "); 14 | let a = Array.new(length); 15 | let i = 0; 16 | 17 | while (i < length) { 18 | let a[i] = Keyboard.readInt("ENTER THE NEXT NUMBER: "); 19 | let i = i + 1; 20 | } 21 | 22 | let i = 0; 23 | let sum = 0; 24 | 25 | while (i < length) { 26 | let sum = sum + a[i]; 27 | let i = i + 1; 28 | } 29 | 30 | do Output.printString("THE AVERAGE IS: "); 31 | do Output.printInt(sum / length); 32 | do Output.println(); 33 | 34 | return; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /projects/10/ExpressionlessSquare/Main.jack: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/10/ExpressionlessSquare/Main.jack 5 | 6 | // Expressionless version of Main.jack. 7 | 8 | /** 9 | * The Main class initializes a new Square Dance game and starts it. 10 | */ 11 | class Main { 12 | 13 | // Initializes the square game and starts it. 14 | function void main() { 15 | var SquareGame game; 16 | 17 | let game = game; 18 | do game.run(); 19 | do game.dispose(); 20 | 21 | return; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /projects/10/ExpressionlessSquare/MainT.xml: -------------------------------------------------------------------------------- 1 | 2 | class 3 | Main 4 | { 5 | function 6 | void 7 | main 8 | ( 9 | ) 10 | { 11 | var 12 | SquareGame 13 | game 14 | ; 15 | let 16 | game 17 | = 18 | game 19 | ; 20 | do 21 | game 22 | . 23 | run 24 | ( 25 | ) 26 | ; 27 | do 28 | game 29 | . 30 | dispose 31 | ( 32 | ) 33 | ; 34 | return 35 | ; 36 | } 37 | } 38 | 39 | -------------------------------------------------------------------------------- /projects/10/JackAnalyzer.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/projects/10/JackAnalyzer.jar -------------------------------------------------------------------------------- /projects/10/JackAnalyzer/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /projects/10/JackAnalyzer/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | JackAnalyzer 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | -------------------------------------------------------------------------------- /projects/10/JackAnalyzer/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Main-Class: org.reion.JackAnalyzer 3 | 4 | -------------------------------------------------------------------------------- /projects/10/Square/Main.jack: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/09/Square/Main.jack 5 | 6 | /** 7 | * The Main class initializes a new Square Dance game and starts it. 8 | */ 9 | class Main { 10 | 11 | /** Initializes a new game and starts it. */ 12 | function void main() { 13 | var SquareGame game; 14 | 15 | let game = SquareGame.new(); 16 | do game.run(); 17 | do game.dispose(); 18 | 19 | return; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /projects/10/Square/MainT.xml: -------------------------------------------------------------------------------- 1 | 2 | class 3 | Main 4 | { 5 | function 6 | void 7 | main 8 | ( 9 | ) 10 | { 11 | var 12 | SquareGame 13 | game 14 | ; 15 | let 16 | game 17 | = 18 | SquareGame 19 | . 20 | new 21 | ( 22 | ) 23 | ; 24 | do 25 | game 26 | . 27 | run 28 | ( 29 | ) 30 | ; 31 | do 32 | game 33 | . 34 | dispose 35 | ( 36 | ) 37 | ; 38 | return 39 | ; 40 | } 41 | } 42 | 43 | -------------------------------------------------------------------------------- /projects/11/Average/Main.jack: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/11/Average/Main.jack 5 | 6 | /** Computes the average of a sequence of integers */ 7 | class Main { 8 | function void main() { 9 | var Array a; 10 | var int length; 11 | var int i, sum; 12 | 13 | let length = Keyboard.readInt("How many numbers? "); 14 | let a = Array.new(length); 15 | let i = 0; 16 | 17 | while (i < length) { 18 | let a[i] = Keyboard.readInt("Enter the next number: "); 19 | let i = i + 1; 20 | } 21 | 22 | let i = 0; 23 | let sum = 0; 24 | 25 | while (i < length) { 26 | let sum = sum + a[i]; 27 | let i = i + 1; 28 | } 29 | 30 | do Output.printString("The average is: "); 31 | do Output.printInt(sum / length); 32 | do Output.println(); 33 | 34 | return; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /projects/11/JackCompiler.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/projects/11/JackCompiler.jar -------------------------------------------------------------------------------- /projects/11/JackCompiler/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Main-Class: org.reion.JackCompiler 3 | 4 | -------------------------------------------------------------------------------- /projects/11/Pong/Main.jack: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/11/Pong/Main.jack 5 | 6 | /** 7 | * The main class of the Pong game. 8 | */ 9 | class Main { 10 | 11 | /** Initializes the Pong game and starts it. */ 12 | function void main() { 13 | var PongGame game; 14 | 15 | do PongGame.newInstance(); 16 | let game = PongGame.getInstance(); 17 | do game.run(); 18 | do game.dispose(); 19 | 20 | return; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /projects/11/Pong/output/Main.vm: -------------------------------------------------------------------------------- 1 | function Main.main 1 2 | call PongGame.newInstance 0 3 | pop temp 0 4 | call PongGame.getInstance 0 5 | pop local 0 6 | push local 0 7 | call PongGame.run 1 8 | pop temp 0 9 | push local 0 10 | call PongGame.dispose 1 11 | pop temp 0 12 | push constant 0 13 | return 14 | -------------------------------------------------------------------------------- /projects/11/Seven/Main.jack: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/11/Seven/Main.jack 5 | 6 | /** 7 | * Computes the value of 1 + (2 * 3) and prints the result 8 | * at the top-left of the screen. 9 | */ 10 | class Main { 11 | 12 | function void main() { 13 | do Output.printInt(1 + (2 * 3)); 14 | return; 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /projects/11/Seven/output/Main.vm: -------------------------------------------------------------------------------- 1 | function Main.main 0 2 | push constant 1 3 | push constant 2 4 | push constant 3 5 | call Math.multiply 2 6 | add 7 | call Output.printInt 1 8 | pop temp 0 9 | push constant 0 10 | return 11 | -------------------------------------------------------------------------------- /projects/11/Square/Main.jack: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/09/Square/Main.jack 5 | 6 | /** 7 | * The Main class initializes a new Square Dance game and starts it. 8 | */ 9 | class Main { 10 | 11 | /** Initializes a new game and starts it. */ 12 | function void main() { 13 | var SquareGame game; 14 | 15 | let game = SquareGame.new(); 16 | do game.run(); 17 | do game.dispose(); 18 | 19 | return; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /projects/11/Square/output/Main.vm: -------------------------------------------------------------------------------- 1 | function Main.main 1 2 | call SquareGame.new 0 3 | pop local 0 4 | push local 0 5 | call SquareGame.run 1 6 | pop temp 0 7 | push local 0 8 | call SquareGame.dispose 1 9 | pop temp 0 10 | push constant 0 11 | return 12 | -------------------------------------------------------------------------------- /projects/12/Array.jack: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/12/Array.jack 5 | 6 | /** 7 | * Represents an array. Can be used to hold any type of object. 8 | */ 9 | class Array { 10 | 11 | /** Constructs a new Array of the given size. */ 12 | function Array new(int size) { 13 | } 14 | 15 | /** De-allocates the array and frees its space. */ 16 | method void dispose() { 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /projects/12/ArrayTest/ArrayTest.cmp: -------------------------------------------------------------------------------- 1 | |RAM[8000]|RAM[8001]|RAM[8002]|RAM[8003]| 2 | | 222 | 122 | 100 | 10 | 3 | -------------------------------------------------------------------------------- /projects/12/ArrayTest/ArrayTest.tst: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/12/ArrayTest/ArrayTest.tst 5 | 6 | load, 7 | output-file ArrayTest.out, 8 | compare-to ArrayTest.cmp, 9 | output-list RAM[8000]%D2.6.1 RAM[8001]%D2.6.1 RAM[8002]%D2.6.1 RAM[8003]%D2.6.1; 10 | 11 | repeat 1000000 { 12 | vmstep; 13 | } 14 | 15 | output; 16 | -------------------------------------------------------------------------------- /projects/12/ArrayTest/Main.jack: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/12/ArrayTest/Main.jack 5 | 6 | /** Test program for the OS Array class. */ 7 | class Main { 8 | 9 | /** Performs several Array manipulations. */ 10 | function void main() { 11 | var Array r; // stores test results 12 | var Array a, b, c; 13 | 14 | let r = 8000; 15 | 16 | let a = Array.new(3); 17 | let a[2] = 222; 18 | let r[0] = a[2]; // RAM[8000] = 222 19 | 20 | let b = Array.new(3); 21 | let b[1] = a[2] - 100; 22 | let r[1] = b[1]; // RAM[8001] = 122 23 | 24 | let c = Array.new(500); 25 | let c[499] = a[2] - b[1]; 26 | let r[2] = c[499]; // RAM[8002] = 100 27 | 28 | do a.dispose(); 29 | do b.dispose(); 30 | 31 | let b = Array.new(3); 32 | let b[0] = c[499] - 90; 33 | let r[3] = b[0]; // RAM[8003] = 10 34 | 35 | do c.dispose(); 36 | do b.dispose(); 37 | 38 | return; 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /projects/12/KeyboardTest/KeyboardTestOutput.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/projects/12/KeyboardTest/KeyboardTestOutput.gif -------------------------------------------------------------------------------- /projects/12/Math.jack: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/12/Math.jack 5 | 6 | /** 7 | * A basic math library. 8 | */ 9 | class Math { 10 | 11 | /** Initializes the library. */ 12 | function void init() { 13 | } 14 | 15 | /** Returns the absolute value of x. */ 16 | function int abs(int x) { 17 | } 18 | 19 | /** Returns the product of x and y. */ 20 | function int multiply(int x, int y) { 21 | } 22 | 23 | /** Returns the integer part of x/y. */ 24 | function int divide(int x, int y) { 25 | } 26 | 27 | /** Returns the integer part of the square root of x. */ 28 | function int sqrt(int x) { 29 | } 30 | 31 | /** Returns the greater number. */ 32 | function int max(int a, int b) { 33 | } 34 | 35 | /** Returns the smaller number. */ 36 | function int min(int a, int b) { 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /projects/12/MathTest/MathTest.cmp: -------------------------------------------------------------------------------- 1 | |RAM[8000]|RAM[8001]|RAM[8002]|RAM[8003]|RAM[8004]|RAM[8005]|RAM[8006]|RAM[8007]|RAM[8008]|RAM[8009]|RAM[8010]|RAM[8011]|RAM[8012]|RAM[8013]| 2 | | 6 | -180 | -18000 | -18000 | 0 | 3 | -3000 | 0 | 3 | 181 | 123 | 123 | 27 | 32767 | 3 | -------------------------------------------------------------------------------- /projects/12/MathTest/MathTest.tst: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/12/MathTest/MathTest.tst 5 | 6 | load, 7 | output-file MathTest.out, 8 | compare-to MathTest.cmp, 9 | output-list RAM[8000]%D2.6.1 RAM[8001]%D2.6.1 RAM[8002]%D2.6.1 RAM[8003]%D2.6.1 RAM[8004]%D2.6.1 RAM[8005]%D2.6.1 RAM[8006]%D2.6.1 RAM[8007]%D2.6.1 RAM[8008]%D2.6.1 RAM[8009]%D2.6.1 RAM[8010]%D2.6.1 RAM[8011]%D2.6.1 RAM[8012]%D2.6.1 RAM[8013]%D2.6.1; 10 | 11 | repeat 1000000 { 12 | vmstep; 13 | } 14 | 15 | output; 16 | -------------------------------------------------------------------------------- /projects/12/Memory.jack: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/12/Memory.jack 5 | 6 | /** 7 | * Memory operations library. 8 | */ 9 | class Memory { 10 | 11 | /** Initializes memory parameters. */ 12 | function void init() { 13 | } 14 | 15 | /** Returns the value of the main memory at the given address. */ 16 | function int peek(int address) { 17 | } 18 | 19 | /** Sets the value of the main memory at this address 20 | * to the given value. */ 21 | function void poke(int address, int value) { 22 | } 23 | 24 | /** finds and allocates from the heap a memory block of the 25 | * specified size and returns a reference to its base address. */ 26 | function int alloc(int size) { 27 | } 28 | 29 | /** De-allocates the given object and frees its space. */ 30 | function void deAlloc(int object) { 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /projects/12/MemoryTest/MemoryTest.cmp: -------------------------------------------------------------------------------- 1 | |RAM[8000]|RAM[8001]|RAM[8002]|RAM[8003]|RAM[8004]|RAM[8005]| 2 | | 333 | 334 | 222 | 122 | 100 | 10 | 3 | -------------------------------------------------------------------------------- /projects/12/MemoryTest/MemoryTest.tst: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/12/MemoryTest/MemoryTest.tst 5 | 6 | load, 7 | output-file MemoryTest.out, 8 | compare-to MemoryTest.cmp, 9 | output-list RAM[8000]%D2.6.1 RAM[8001]%D2.6.1 RAM[8002]%D2.6.1 RAM[8003]%D2.6.1 RAM[8004]%D2.6.1 RAM[8005]%D2.6.1; 10 | 11 | repeat 1000000 { 12 | vmstep; 13 | } 14 | 15 | output; 16 | -------------------------------------------------------------------------------- /projects/12/Output.jack: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/projects/12/Output.jack -------------------------------------------------------------------------------- /projects/12/OutputTest/OutputTestOutput.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/projects/12/OutputTest/OutputTestOutput.gif -------------------------------------------------------------------------------- /projects/12/Screen.jack: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/12/Screen.jack 5 | 6 | /** 7 | * Graphic screen library. 8 | */ 9 | class Screen { 10 | 11 | /** Initializes the Screen. */ 12 | function void init() { 13 | } 14 | 15 | /** Erases the whole screen. */ 16 | function void clearScreen() { 17 | } 18 | 19 | /** Sets the color to be used in further draw commands 20 | * where white = false, black = true. */ 21 | function void setColor(boolean b) { 22 | } 23 | 24 | /** Draws the (x, y) pixel. */ 25 | function void drawPixel(int x, int y) { 26 | } 27 | 28 | /** Draws a line from (x1, y1) to (x2, y2). */ 29 | function void drawLine(int x1, int y1, int x2, int y2) { 30 | } 31 | 32 | /** Draws a filled rectangle where the top left corner 33 | * is (x1, y1) and the bottom right corner is (x2, y2). */ 34 | function void drawRectangle(int x1, int y1, int x2, int y2) { 35 | } 36 | 37 | /** Draws a filled circle of radius r around (cx, cy). */ 38 | function void drawCircle(int cx, int cy, int r) { 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /projects/12/ScreenTest/ScreenTestOutput.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/projects/12/ScreenTest/ScreenTestOutput.gif -------------------------------------------------------------------------------- /projects/12/StringTest/StringTestOutput.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/projects/12/StringTest/StringTestOutput.gif -------------------------------------------------------------------------------- /projects/12/Sys.jack: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/12/Sys.jack 5 | 6 | /** 7 | * A library of basic system services. 8 | */ 9 | class Sys { 10 | 11 | /** Performs all the initializations required by the OS. */ 12 | function void init() { 13 | } 14 | 15 | /** Halts execution. */ 16 | function void halt() { 17 | } 18 | 19 | /** Waits approximately duration milliseconds and then returns. */ 20 | function void wait(int duration) { 21 | } 22 | 23 | /** Prints the given error code in the form "ERR", and halts. */ 24 | function void error(int errorCode) { 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /projects/12/SysTest/Main.jack: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: projects/12/SysTest/Main.jack 5 | 6 | /** Test program for the OS Sys class. */ 7 | class Main { 8 | 9 | /** tests the wait method of the Sys class. */ 10 | function void main() { 11 | var char key; 12 | 13 | do Output.printString("Wait test:"); 14 | do Output.println(); 15 | do Output.printString("Press any key. After 2 seconds, another message will be printed:"); 16 | 17 | while (key = 0) { 18 | let key = Keyboard.keyPressed(); 19 | } 20 | while (~(key = 0)) { 21 | let key = Keyboard.keyPressed(); 22 | } 23 | 24 | do Sys.wait(2000); 25 | 26 | do Output.println(); 27 | do Output.printString("Time is up. Make sure that 2 seconds had passed."); 28 | 29 | return; 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /projects/13/more fun to go.txt: -------------------------------------------------------------------------------- 1 | See Chapter 13 in the book. It's your call! 2 | 3 | And, if you've developed something cool, and you wish to share it with others, please let us know about it. We'll put a link to it from the nand2tetris site. 4 | 5 | We hope that you enjoyed the ride! 6 | 7 | -- Noam and Shimon 8 | 9 | www.nand2tetris.org -------------------------------------------------------------------------------- /res/pdf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/res/pdf.png -------------------------------------------------------------------------------- /res/ppt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/res/ppt.png -------------------------------------------------------------------------------- /res/youtube.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/res/youtube.png -------------------------------------------------------------------------------- /tools/Assembler.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | rem $Id: Assembler.bat,v 1.2 2014/05/10 00:52:43 marka Exp $ 4 | rem mark.armbrust@pobox.com 5 | 6 | setlocal 7 | if not "%2"=="" goto :USAGE 8 | if "%~1"=="/?" ( 9 | :USAGE 10 | echo Usage: 11 | echo Assembler Starts the assembler in interactive mode. 12 | echo Assembler FILE[.asm] Assembles FILE.asm to FILE.hack. 13 | exit -b 14 | ) 15 | if not "%~1"=="" ( 16 | set "_arg1=%~f1" 17 | ) 18 | pushd "%~dp0" 19 | if "%~1"=="" ( 20 | start javaw -classpath "%CLASSPATH%;bin/classes;bin/lib/Hack.jar;bin/lib/HackGUI.jar;bin/lib/Compilers.jar;bin/lib/AssemblerGUI.jar;bin/lib/TranslatorsGUI.jar" ^ 21 | HackAssemblerMain 22 | ) else ( 23 | echo Assembling "%_arg1%" 24 | java -classpath "%CLASSPATH%;bin/classes;bin/lib/Hack.jar;bin/lib/HackGUI.jar;bin/lib/Compilers.jar;bin/lib/AssemblerGUI.jar;bin/lib/TranslatorsGUI.jar" ^ 25 | HackAssemblerMain "%_arg1%" 26 | ) 27 | popd 28 | -------------------------------------------------------------------------------- /tools/Assembler.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # $Id: Assembler.sh,v 1.1 2014/06/17 21:14:01 marka Exp $ 4 | # mark.armbrust@pobox.com 5 | 6 | # User's CDPATH can interfere with cd in this script 7 | unset CDPATH 8 | # Get the true name of this script 9 | script="`test -L "$0" && readlink -n "$0" || echo "$0"`" 10 | dir="$PWD" 11 | cd "`dirname "$script"`" 12 | if [ \( $# -gt 1 \) -o \( "$1" = "-h" \) -o \( "$1" = "--help" \) ] 13 | then 14 | echo "Usage:" 15 | echo " `basename "$0"` Starts the assembler in interactive mode." 16 | echo " `basename "$0"` FILE[.asm] Assembles FILE.asm to FILE.hack." 17 | elif [ $# -eq 0 ] 18 | then 19 | # Run assembler in interactive mode 20 | java -classpath "${CLASSPATH}:bin/classes:bin/lib/Hack.jar:bin/lib/HackGUI.jar:bin/lib/Compilers.jar:bin/lib/AssemblerGUI.jar:bin/lib/TranslatorsGUI.jar" HackAssemblerMain & 21 | else 22 | # Convert arg1 to an absolute path and run assembler with arg1. 23 | if [ `echo "$1" | sed -e "s/\(.\).*/\1/"` = / ] 24 | then 25 | arg1="$1" 26 | else 27 | arg1="${dir}/$1" 28 | fi 29 | echo Assembling "$arg1" 30 | java -classpath "${CLASSPATH}:bin/classes:bin/lib/Hack.jar:bin/lib/HackGUI.jar:bin/lib/Compilers.jar:bin/lib/AssemblerGUI.jar:bin/lib/TranslatorsGUI.jar" HackAssemblerMain "$arg1" 31 | fi 32 | 33 | -------------------------------------------------------------------------------- /tools/CPUEmulator.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | rem $Id: CPUEmulator.bat,v 1.3 2014/05/10 00:52:43 marka Exp $ 4 | rem mark.armbrust@pobox.com 5 | 6 | setlocal 7 | if not "%2"=="" goto :USAGE 8 | if "%~1"=="/?" ( 9 | :USAGE 10 | echo Usage: 11 | echo CPUEmulator Starts the CPU Emulator in interactive mode. 12 | echo CPUEmulator FILE.tst Starts the CPU Emulator and runs the FILE.tst 13 | echo test script. The success/failure message 14 | echo is printed to the command console. 15 | exit -b 16 | ) 17 | if not "%~1"=="" ( 18 | set "_arg1=%~f1" 19 | ) 20 | pushd "%~dp0" 21 | if "%~1"=="" ( 22 | start javaw -classpath "%CLASSPATH%;bin/classes;bin/lib/Hack.jar;bin/lib/HackGUI.jar;bin/lib/Simulators.jar;bin/lib/SimulatorsGUI.jar;bin/lib/Compilers.jar" ^ 23 | CPUEmulatorMain 24 | ) else ( 25 | rem echo Running "%_arg1%" 26 | java -classpath "%CLASSPATH%;bin/classes;bin/lib/Hack.jar;bin/lib/HackGUI.jar;bin/lib/Simulators.jar;bin/lib/SimulatorsGUI.jar;bin/lib/Compilers.jar" ^ 27 | CPUEmulatorMain "%_arg1%" 28 | ) 29 | popd 30 | -------------------------------------------------------------------------------- /tools/HardwareSimulator.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | rem $Id: HardwareSimulator.bat,v 1.3 2014/05/10 00:52:43 marka Exp $ 4 | rem mark.armbrust@pobox.com 5 | 6 | setlocal 7 | if not "%2"=="" goto :USAGE 8 | if "%~1"=="/?" ( 9 | :USAGE 10 | echo Usage: 11 | echo HardwareSimulator Starts the Hardware Simulator in 12 | echo interactive mode. 13 | echo HardwareSimulator FILE.tst Starts the Hardware Simulator and runs the 14 | echo FILE.tst test script. The success/failure 15 | echo message is printed to the command console. 16 | exit -b 17 | ) 18 | if not "%~1"=="" ( 19 | set "_arg1=%~f1" 20 | ) 21 | pushd "%~dp0" 22 | if "%~1"=="" ( 23 | start javaw -classpath "%CLASSPATH%;.;bin/classes;bin/lib/Hack.jar;bin/lib/HackGUI.jar;bin/lib/Simulators.jar;bin/lib/SimulatorsGUI.jar;bin/lib/Compilers.jar" ^ 24 | HardwareSimulatorMain 25 | ) else ( 26 | rem echo Running "%_arg1%" 27 | java -classpath "%CLASSPATH%;.;bin/classes;bin/lib/Hack.jar;bin/lib/HackGUI.jar;bin/lib/Simulators.jar;bin/lib/SimulatorsGUI.jar;bin/lib/Compilers.jar" ^ 28 | HardwareSimulatorMain "%_arg1%" 29 | ) 30 | popd 31 | -------------------------------------------------------------------------------- /tools/JackCompiler.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | rem $Id: JackCompiler.bat,v 1.2 2014/05/10 00:52:43 marka Exp $ 4 | rem mark.armbrust@pobox.com 5 | 6 | setlocal 7 | if not "%2"=="" goto :USAGE 8 | if "%~1"=="/?" ( 9 | :USAGE 10 | echo Usage: 11 | echo JackCompiler Compiles all .jack files in the current 12 | echo working directory. 13 | echo JackCompiler DIRECTORY Compiles all .jack files in DIRECTORY. 14 | echo JackCompiler FILE.jack Compiles FILE.jack to FILE.vm. 15 | exit -b 16 | ) 17 | if not "%~1"=="" ( 18 | set "_arg1=%~f1" 19 | ) else ( 20 | set "_arg1=%CD%" 21 | ) 22 | pushd "%~dp0" 23 | echo Compiling "%_arg1%" 24 | java -classpath "%CLASSPATH%;bin/classes;bin/lib/Hack.jar;bin/lib/Compilers.jar" ^ 25 | Hack.Compiler.JackCompiler "%_arg1%" 26 | popd 27 | -------------------------------------------------------------------------------- /tools/JackCompiler.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # $Id: JackCompiler.sh,v 1.1 2014/06/17 21:14:01 marka Exp $ 4 | # mark.armbrust@pobox.com 5 | 6 | # User's CDPATH can interfere with cd in this script 7 | unset CDPATH 8 | # Get the true name of this script 9 | script="`test -L "$0" && readlink -n "$0" || echo "$0"`" 10 | dir="$PWD" 11 | cd "`dirname "$script"`" 12 | if [ \( $# -gt 1 \) -o \( "$1" = "-h" \) -o \( "$1" = "--help" \) ] 13 | then 14 | echo "Usage:" 15 | echo " `basename "$0"` Compiles all .jack files in the current" 16 | echo " working directory." 17 | echo " `basename "$0"` DIRECTORY Compiles all .jack files in DIRECTORY." 18 | echo " `basename "$0"` FILE.jack Compiles FILE.jack to FILE.vm." 19 | else 20 | if [ $# -eq 0 ] 21 | then 22 | # Use current directory as arg1 23 | arg1="$dir" 24 | else 25 | # Convert arg1 to an absolute path 26 | if [ `echo "$1" | sed -e "s/\(.\).*/\1/"` = / ] 27 | then 28 | arg1="$1" 29 | else 30 | arg1="$dir/$1" 31 | fi 32 | fi 33 | echo Compiling "$arg1" 34 | java -classpath "${CLASSPATH}:bin/classes:bin/lib/Hack.jar:bin/lib/Compilers.jar" Hack.Compiler.JackCompiler "$arg1" 35 | fi 36 | -------------------------------------------------------------------------------- /tools/OS/Array.vm: -------------------------------------------------------------------------------- 1 | function Array.new 0 2 | push argument 0 3 | push constant 0 4 | gt 5 | not 6 | if-goto IF_TRUE0 7 | goto IF_FALSE0 8 | label IF_TRUE0 9 | push constant 2 10 | call Sys.error 1 11 | pop temp 0 12 | label IF_FALSE0 13 | push argument 0 14 | call Memory.alloc 1 15 | return 16 | function Array.dispose 0 17 | push argument 0 18 | pop pointer 0 19 | push pointer 0 20 | call Memory.deAlloc 1 21 | pop temp 0 22 | push constant 0 23 | return 24 | -------------------------------------------------------------------------------- /tools/TextComparer.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | rem $Id: TextComparer.bat,v 1.2 2014/05/10 00:52:43 marka Exp $ 4 | rem mark.armbrust@pobox.com 5 | 6 | setlocal 7 | if not "%3"=="" goto :USAGE 8 | if "%1"=="/?" goto :USAGE 9 | if not "%~1"=="" ( 10 | set "_arg1=%~f1" 11 | ) 12 | if not "%~2"=="" ( 13 | set "_arg2=%~f2" 14 | ) 15 | pushd "%~dp0" 16 | if NOT "%~1"=="" ( 17 | if NOT "%~2"=="" ( 18 | java -classpath "%CLASSPATH%;bin/classes" TextComparer ^ 19 | "%_arg1%" "%_arg2%" 20 | popd 21 | exit /B 22 | ) 23 | ) 24 | :USAGE 25 | echo Usage: 26 | echo TextComparer FILE1 FILE2 Compares FILE1 and FILE2. The success 27 | echo message or the first miscompared line 28 | echo is printed to the command console. 29 | popd 30 | -------------------------------------------------------------------------------- /tools/TextComparer.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # $Id: TextComparer.sh,v 1.1 2014/06/17 21:14:01 marka Exp $ 4 | # mark.armbrust@pobox.com 5 | 6 | # User's CDPATH can interfere with cd in this script 7 | unset CDPATH 8 | # Get the true name of this script 9 | script="`test -L "$0" && readlink -n "$0" || echo "$0"`" 10 | dir="$PWD" 11 | cd "`dirname "$script"`" 12 | if [ \( $# -ne 2 \) -o \( "$1" = "-h" \) -o \( "$1" = "--help" \) ] 13 | then 14 | # print usage 15 | echo "Usage:" 16 | echo " `basename "$0"` FILE1 FILE2 Compares FILE1 and FILE2. The success" 17 | echo " message or the first miscompared line" 18 | echo " is printed to the command console." 19 | else 20 | # Convert arg1 to an absolute path 21 | if [ `echo "$1" | sed -e "s/\(.\).*/\1/"` = / ] 22 | then 23 | arg1="$1" 24 | else 25 | arg1="$dir/$1" 26 | fi 27 | # Convert arg2 to an absolute path 28 | if [ `echo "$2" | sed -e "s/\(.\).*/\1/"` = / ] 29 | then 30 | arg2="$2" 31 | else 32 | arg2="$dir/$2" 33 | fi 34 | # echo Comparing "$arg1" "$arg2" 35 | java -classpath "${CLASSPATH}:bin/classes" TextComparer "$arg1" "$arg2" 36 | fi 37 | -------------------------------------------------------------------------------- /tools/VMEmulator.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | rem $Id: VMEmulator.bat,v 1.3 2014/05/10 00:51:55 marka Exp $ 4 | rem mark.armbrust@pobox.com 5 | 6 | setlocal 7 | if not "%2"=="" goto :USAGE 8 | if "%~1"=="/?" ( 9 | :USAGE 10 | echo Usage: 11 | echo VMEmulator Starts the VM Emulator in interactive mode. 12 | echo VMEmulator FILE.tst Starts the VM Emulator and runs the FILE.tst test 13 | echo script. The success/failure message is 14 | echo printed to the command console. 15 | exit -b 16 | ) 17 | if not "%~1"=="" ( 18 | set "_arg1=%~f1" 19 | ) 20 | pushd "%~dp0" 21 | if "%~1"=="" ( 22 | start javaw -classpath "%CLASSPATH%;.;bin/classes;bin/lib/Hack.jar;bin/lib/HackGUI.jar;bin/lib/Simulators.jar;bin/lib/SimulatorsGUI.jar;bin/lib/Compilers.jar" ^ 23 | VMEmulatorMain 24 | ) else ( 25 | rem echo Running "%_arg1%" 26 | java -classpath "%CLASSPATH%;.;bin/classes;bin/lib/Hack.jar;bin/lib/HackGUI.jar;bin/lib/Simulators.jar;bin/lib/SimulatorsGUI.jar;bin/lib/Compilers.jar" ^ 27 | VMEmulatorMain "%_arg1%" 28 | ) 29 | popd 30 | -------------------------------------------------------------------------------- /tools/bin/CPU Emulator.dat: -------------------------------------------------------------------------------- 1 | /Users/Reion/nand2tetris/projects/09/Hello 2 | -------------------------------------------------------------------------------- /tools/bin/Virtual Machine Emulator.dat: -------------------------------------------------------------------------------- 1 | /Users/Reion/Desktop/nand2tetris/projects/09/RollingBall/output 2 | -------------------------------------------------------------------------------- /tools/bin/classes/CPUEmulatorMain.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/tools/bin/classes/CPUEmulatorMain.class -------------------------------------------------------------------------------- /tools/bin/classes/HackAssemblerMain.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/tools/bin/classes/HackAssemblerMain.class -------------------------------------------------------------------------------- /tools/bin/classes/HardwareSimulatorMain.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/tools/bin/classes/HardwareSimulatorMain.class -------------------------------------------------------------------------------- /tools/bin/classes/TextComparer.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/tools/bin/classes/TextComparer.class -------------------------------------------------------------------------------- /tools/bin/classes/VMEmulatorMain.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/tools/bin/classes/VMEmulatorMain.class -------------------------------------------------------------------------------- /tools/bin/help/compiler.txt: -------------------------------------------------------------------------------- 1 | Jack Compiler, Version 2.5 2 | 3 | This program is part of www.nand2tetris.org 4 | and the book "The Elements of Computing Systems" 5 | by Nisan and Schocken, MIT Press. 6 | 7 | Software Architects: Yaron Ukrainitz and Yannai A. Gonczarowski 8 | 9 | Usage instruction and tips can be found in the relevant book chapters. 10 | -------------------------------------------------------------------------------- /tools/bin/images/arrow2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/tools/bin/images/arrow2.gif -------------------------------------------------------------------------------- /tools/bin/images/calculator2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/tools/bin/images/calculator2.gif -------------------------------------------------------------------------------- /tools/bin/images/cancel.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/tools/bin/images/cancel.gif -------------------------------------------------------------------------------- /tools/bin/images/chip.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/tools/bin/images/chip.gif -------------------------------------------------------------------------------- /tools/bin/images/clock2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/tools/bin/images/clock2.gif -------------------------------------------------------------------------------- /tools/bin/images/equal.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/tools/bin/images/equal.gif -------------------------------------------------------------------------------- /tools/bin/images/find.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/tools/bin/images/find.gif -------------------------------------------------------------------------------- /tools/bin/images/hex.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/tools/bin/images/hex.gif -------------------------------------------------------------------------------- /tools/bin/images/keyboard.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/tools/bin/images/keyboard.gif -------------------------------------------------------------------------------- /tools/bin/images/ok.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/tools/bin/images/ok.gif -------------------------------------------------------------------------------- /tools/bin/images/ok2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/tools/bin/images/ok2.gif -------------------------------------------------------------------------------- /tools/bin/images/open.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/tools/bin/images/open.gif -------------------------------------------------------------------------------- /tools/bin/images/open2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/tools/bin/images/open2.gif -------------------------------------------------------------------------------- /tools/bin/images/opendoc.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/tools/bin/images/opendoc.gif -------------------------------------------------------------------------------- /tools/bin/images/redflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/tools/bin/images/redflag.gif -------------------------------------------------------------------------------- /tools/bin/images/save.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/tools/bin/images/save.gif -------------------------------------------------------------------------------- /tools/bin/images/scroll.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/tools/bin/images/scroll.gif -------------------------------------------------------------------------------- /tools/bin/images/smallcancel.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/tools/bin/images/smallcancel.gif -------------------------------------------------------------------------------- /tools/bin/images/smallequal.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/tools/bin/images/smallequal.gif -------------------------------------------------------------------------------- /tools/bin/images/smallminus.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/tools/bin/images/smallminus.gif -------------------------------------------------------------------------------- /tools/bin/images/smallnew.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/tools/bin/images/smallnew.gif -------------------------------------------------------------------------------- /tools/bin/images/smallok.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/tools/bin/images/smallok.gif -------------------------------------------------------------------------------- /tools/bin/images/smallplus.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/tools/bin/images/smallplus.gif -------------------------------------------------------------------------------- /tools/bin/images/vcrfastforward.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/tools/bin/images/vcrfastforward.gif -------------------------------------------------------------------------------- /tools/bin/images/vcrforward.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/tools/bin/images/vcrforward.gif -------------------------------------------------------------------------------- /tools/bin/images/vcrrewind.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/tools/bin/images/vcrrewind.gif -------------------------------------------------------------------------------- /tools/bin/images/vcrstop.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/tools/bin/images/vcrstop.gif -------------------------------------------------------------------------------- /tools/bin/lib/AssemblerGUI.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/tools/bin/lib/AssemblerGUI.jar -------------------------------------------------------------------------------- /tools/bin/lib/Compilers.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/tools/bin/lib/Compilers.jar -------------------------------------------------------------------------------- /tools/bin/lib/Hack.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/tools/bin/lib/Hack.jar -------------------------------------------------------------------------------- /tools/bin/lib/HackGUI.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/tools/bin/lib/HackGUI.jar -------------------------------------------------------------------------------- /tools/bin/lib/Simulators.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/tools/bin/lib/Simulators.jar -------------------------------------------------------------------------------- /tools/bin/lib/SimulatorsGUI.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/tools/bin/lib/SimulatorsGUI.jar -------------------------------------------------------------------------------- /tools/bin/lib/TranslatorsGUI.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/tools/bin/lib/TranslatorsGUI.jar -------------------------------------------------------------------------------- /tools/bin/scripts/defaultCPU.txt: -------------------------------------------------------------------------------- 1 | repeat { 2 | ticktock; 3 | } -------------------------------------------------------------------------------- /tools/bin/scripts/defaultHW.txt: -------------------------------------------------------------------------------- 1 | repeat { 2 | tick, 3 | tock; 4 | } -------------------------------------------------------------------------------- /tools/bin/scripts/defaultVM.txt: -------------------------------------------------------------------------------- 1 | repeat { 2 | vmstep; 3 | } -------------------------------------------------------------------------------- /tools/builtInChips/ALU.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/tools/builtInChips/ALU.class -------------------------------------------------------------------------------- /tools/builtInChips/ALU.hdl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/tools/builtInChips/ALU.hdl -------------------------------------------------------------------------------- /tools/builtInChips/ARegister.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/tools/builtInChips/ARegister.class -------------------------------------------------------------------------------- /tools/builtInChips/ARegister.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: tools/builtIn/ARegister.hdl 5 | 6 | /** 7 | * A 16-Bit register called "A Register". 8 | * If load[t-1]=1 then out[t] = in[t-1] 9 | * else out does not change (out[t] = out[t-1]) 10 | * 11 | * This built-in chip implementation has the side effect of 12 | * providing a GUI representation of a 16-bit register 13 | * called "A register" (typically used to store an address). 14 | */ 15 | 16 | CHIP ARegister { 17 | 18 | IN in[16], load; 19 | OUT out[16]; 20 | 21 | BUILTIN ARegister; 22 | CLOCKED in, load; 23 | } 24 | 25 | -------------------------------------------------------------------------------- /tools/builtInChips/Add16.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/tools/builtInChips/Add16.class -------------------------------------------------------------------------------- /tools/builtInChips/Add16.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: tools/builtIn/Add16.hdl 5 | 6 | /* 7 | * Adds two 16-bit values. 8 | * The most significant carry bit is ignored. 9 | */ 10 | 11 | CHIP Add16 { 12 | 13 | IN a[16], b[16]; 14 | OUT out[16]; 15 | 16 | BUILTIN Add16; 17 | } 18 | 19 | -------------------------------------------------------------------------------- /tools/builtInChips/And.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/tools/builtInChips/And.class -------------------------------------------------------------------------------- /tools/builtInChips/And.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: tools/builtIn/And.hdl 5 | 6 | /** 7 | * And gate: out = 1 if {a == 1 and b == 1}, 0 otherwise 8 | */ 9 | 10 | CHIP And { 11 | 12 | IN a, b; 13 | OUT out; 14 | 15 | BUILTIN And; 16 | } 17 | -------------------------------------------------------------------------------- /tools/builtInChips/And16.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: tools/builtIn/And16.hdl 5 | 6 | /** 7 | * 16-bit-wise And gate: for i = 0..15: out[i] = a[i] and b[i] 8 | */ 9 | 10 | CHIP And16 { 11 | 12 | IN a[16], b[16]; 13 | OUT out[16]; 14 | 15 | BUILTIN And; 16 | } 17 | 18 | -------------------------------------------------------------------------------- /tools/builtInChips/Bit.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/tools/builtInChips/Bit.class -------------------------------------------------------------------------------- /tools/builtInChips/Bit.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: tools/builtIn/Bit.hdl 5 | 6 | /** 7 | * 1-bit register. 8 | * If load[t] == 1 then out[t+1] = in[t] 9 | * else out[t+1] = out[t] (no change) 10 | */ 11 | 12 | CHIP Bit { 13 | 14 | IN in, load; 15 | OUT out; 16 | 17 | BUILTIN Bit; 18 | CLOCKED in, load; 19 | } 20 | -------------------------------------------------------------------------------- /tools/builtInChips/DFF.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/tools/builtInChips/DFF.class -------------------------------------------------------------------------------- /tools/builtInChips/DFF.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: tools/builtIn/DFF.hdl 5 | 6 | /** 7 | * Data Flip-flop: out(t) = in(t-1) 8 | * where t is the current time unit, or clock cycle. 9 | */ 10 | 11 | CHIP DFF { 12 | 13 | IN in; 14 | OUT out; 15 | 16 | BUILTIN DFF; 17 | CLOCKED in; 18 | } 19 | -------------------------------------------------------------------------------- /tools/builtInChips/DMux.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/tools/builtInChips/DMux.class -------------------------------------------------------------------------------- /tools/builtInChips/DMux.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: tools/builtIn/DMux.hdl 5 | 6 | /** 7 | * Dmultiplexor. 8 | * {a,b} = {in,0} if sel == 0 9 | * {0,in} if sel == 1 10 | */ 11 | 12 | 13 | CHIP DMux { 14 | 15 | IN in, sel; 16 | OUT a, b; 17 | 18 | BUILTIN DMux; 19 | } 20 | 21 | -------------------------------------------------------------------------------- /tools/builtInChips/DMux4Way.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/tools/builtInChips/DMux4Way.class -------------------------------------------------------------------------------- /tools/builtInChips/DMux4Way.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: tools/builtIn/DMux4Way.hdl 5 | 6 | /** 7 | * 4-way demultiplexor. 8 | * {a,b,c,d} = {in,0,0,0} if sel == 00 9 | * {0,in,0,0} if sel == 01 10 | * {0,0,in,0} if sel == 10 11 | * {0,0,0,in} if sel == 11 12 | */ 13 | 14 | 15 | CHIP DMux4Way { 16 | 17 | IN in, sel[2]; 18 | OUT a, b, c, d; 19 | 20 | BUILTIN DMux4Way; 21 | } 22 | 23 | -------------------------------------------------------------------------------- /tools/builtInChips/DMux8Way.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/tools/builtInChips/DMux8Way.class -------------------------------------------------------------------------------- /tools/builtInChips/DMux8Way.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: tools/builtIn/DMux8Way.hdl 5 | 6 | /** 7 | * 8-way demultiplexor. 8 | * {a,b,c,d,e,f,g,h} = {in,0,0,0,0,0,0,0} if sel == 000 9 | * {0,in,0,0,0,0,0,0} if sel == 001 10 | * etc. 11 | * {0,0,0,0,0,0,0,in} if sel == 111 12 | */ 13 | 14 | 15 | CHIP DMux8Way { 16 | 17 | IN in, sel[3]; 18 | OUT a, b, c, d, e, f, g, h; 19 | 20 | BUILTIN DMux8Way; 21 | } 22 | 23 | -------------------------------------------------------------------------------- /tools/builtInChips/DRegister.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/tools/builtInChips/DRegister.class -------------------------------------------------------------------------------- /tools/builtInChips/DRegister.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of the materials accompanying the book 2 | // "The Elements of Computing Systems" by Nisan and Schocken, 3 | // MIT Press. Book site: www.idc.ac.il/tecs 4 | // File name: tools/builtIn/DRegister.hdl 5 | 6 | /** 7 | * A 16-Bit register called "D Register". 8 | * If load[t-1]=1 then out[t] = in[t-1] 9 | * else out does not change (out[t] = out[t-1]) 10 | * 11 | * This built-in chip implementation has the side effect of 12 | * providing a GUI representation of a 16-bit register 13 | * called "D register" (typically used to store data). 14 | */ 15 | 16 | CHIP DRegister { 17 | 18 | IN in[16], load; 19 | OUT out[16]; 20 | 21 | BUILTIN DRegister; 22 | CLOCKED in, load; 23 | } 24 | 25 | -------------------------------------------------------------------------------- /tools/builtInChips/FullAdder.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/tools/builtInChips/FullAdder.class -------------------------------------------------------------------------------- /tools/builtInChips/FullAdder.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: tools/builtIn/FullAdder.hdl 5 | 6 | /** 7 | * Full adder. Computes sum, the least significant bit of 8 | * a + b + c, and carry, the most significant bit of a + b + c. 9 | */ 10 | 11 | CHIP FullAdder { 12 | 13 | IN a, b, c; 14 | OUT sum, // LSB of a + b + c 15 | carry; // MSB of a + b + c 16 | 17 | BUILTIN FullAdder; 18 | } 19 | 20 | -------------------------------------------------------------------------------- /tools/builtInChips/HalfAdder.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/tools/builtInChips/HalfAdder.class -------------------------------------------------------------------------------- /tools/builtInChips/HalfAdder.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: tools/builtIn/HalfAdder.hdl 5 | 6 | /** 7 | * Half adder. Computes sum, the least significnat bit of a + b, 8 | * and carry, the most significnat bit of a + b. 9 | */ 10 | 11 | CHIP HalfAdder { 12 | 13 | IN a, b; 14 | OUT sum, // LSB of a + b 15 | carry; // MSB of a + b 16 | 17 | BUILTIN HalfAdder; 18 | } 19 | -------------------------------------------------------------------------------- /tools/builtInChips/Inc16.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/tools/builtInChips/Inc16.class -------------------------------------------------------------------------------- /tools/builtInChips/Inc16.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: tools/builtIn/Inc16.hdl 5 | 6 | /** 7 | * 16-bit incrementer. out = in + 1 (16-bit addition). 8 | * Overflow is neither detected nor handled. 9 | */ 10 | 11 | CHIP Inc16 { 12 | 13 | IN in[16]; 14 | OUT out[16]; 15 | 16 | BUILTIN Inc16; 17 | } 18 | 19 | -------------------------------------------------------------------------------- /tools/builtInChips/Keyboard.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/tools/builtInChips/Keyboard.class -------------------------------------------------------------------------------- /tools/builtInChips/Keyboard.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: tools/builtIn/Keyboard.hdl 5 | 6 | /** 7 | * The keyboard (memory map). 8 | * Outputs the code of the currently pressed key. 9 | * 10 | * The built-in chip implementation has two side effects supplied 11 | * by the simulator. First, the keyboard memory map is continuously 12 | * being refreshed from the physical keyboard unit. Second, it 13 | * displays a keyboard icon and data entry GUI. 14 | */ 15 | 16 | CHIP Keyboard { 17 | 18 | OUT out[16]; // The ASCII code of the pressed key, 19 | // or 0 if no key is currently pressed, 20 | // or one the special codes listed in Figure 5.5. 21 | 22 | BUILTIN Keyboard; 23 | } 24 | -------------------------------------------------------------------------------- /tools/builtInChips/Mux.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/tools/builtInChips/Mux.class -------------------------------------------------------------------------------- /tools/builtInChips/Mux.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: tools/builtIn/Mux.hdl 5 | 6 | /** 7 | * Multiplexor. If sel == 1 then out = b else out = a. 8 | */ 9 | 10 | CHIP Mux { 11 | 12 | IN a, b, sel; 13 | OUT out; 14 | 15 | BUILTIN Mux; 16 | } 17 | -------------------------------------------------------------------------------- /tools/builtInChips/Mux16.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: tools/builtIn/Mux16.hdl 5 | 6 | /** 7 | * 16 bit multiplexor. If sel == 1 then out = b else out = a. 8 | */ 9 | 10 | CHIP Mux16 { 11 | 12 | IN a[16], b[16], sel; 13 | OUT out[16]; 14 | 15 | BUILTIN Mux; 16 | } 17 | -------------------------------------------------------------------------------- /tools/builtInChips/Mux4Way16.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/tools/builtInChips/Mux4Way16.class -------------------------------------------------------------------------------- /tools/builtInChips/Mux4Way16.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: tools/builtIn/Mux4Way16.hdl 5 | 6 | /** 7 | * 4-way 16-bit multiplexor. 8 | * out = a if sel == 00 9 | * b if sel == 01 10 | * c if sel == 10 11 | * d if sel == 11 12 | */ 13 | 14 | 15 | CHIP Mux4Way16 { 16 | 17 | IN a[16], b[16], c[16], d[16], sel[2]; 18 | OUT out[16]; 19 | 20 | BUILTIN Mux4Way16; 21 | } 22 | -------------------------------------------------------------------------------- /tools/builtInChips/Mux8Way16.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/tools/builtInChips/Mux8Way16.class -------------------------------------------------------------------------------- /tools/builtInChips/Mux8Way16.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: tools/builtIn/Mux8Way16.hdl 5 | 6 | /** 7 | * 8-way 16-bit multiplexor. 8 | * out = a if sel == 000 9 | * b if sel == 001 10 | * etc. 11 | * h if sel == 111 12 | */ 13 | 14 | 15 | CHIP Mux8Way16 { 16 | 17 | IN a[16], b[16], c[16], d[16], 18 | e[16], f[16], g[16], h[16], 19 | sel[3]; 20 | 21 | OUT out[16]; 22 | 23 | BUILTIN Mux8Way16; 24 | } -------------------------------------------------------------------------------- /tools/builtInChips/Nand.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/tools/builtInChips/Nand.class -------------------------------------------------------------------------------- /tools/builtInChips/Nand.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: tools/builtIn/Nand.hdl 5 | 6 | /** 7 | * Nand gate: out = a Nand b. 8 | */ 9 | 10 | CHIP Nand { 11 | 12 | IN a, b; 13 | OUT out; 14 | 15 | BUILTIN Nand; 16 | } 17 | -------------------------------------------------------------------------------- /tools/builtInChips/Not.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/tools/builtInChips/Not.class -------------------------------------------------------------------------------- /tools/builtInChips/Not.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: tools/builtIn/Not.hdl 5 | 6 | /** 7 | * Not gate: out = not in 8 | */ 9 | 10 | CHIP Not { 11 | 12 | IN in; 13 | OUT out; 14 | 15 | BUILTIN Not; 16 | } -------------------------------------------------------------------------------- /tools/builtInChips/Not16.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/tools/builtInChips/Not16.class -------------------------------------------------------------------------------- /tools/builtInChips/Not16.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: tools/builtIn/Not16.hdl 5 | 6 | /** 7 | * 16-bit Not gate: for i = 0..15: out[i] = not in[i] 8 | */ 9 | 10 | CHIP Not16 { 11 | 12 | IN in[16]; 13 | OUT out[16]; 14 | 15 | BUILTIN Not16; 16 | } -------------------------------------------------------------------------------- /tools/builtInChips/Or.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/tools/builtInChips/Or.class -------------------------------------------------------------------------------- /tools/builtInChips/Or.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: tools/builtIn/Or.hdl 5 | 6 | /** 7 | * Or gate: out = 1 if {a == 1 or b == 1}, 0 otherwise 8 | */ 9 | 10 | CHIP Or { 11 | 12 | IN a, b; 13 | OUT out; 14 | 15 | BUILTIN Or; 16 | } 17 | -------------------------------------------------------------------------------- /tools/builtInChips/Or16.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: tools/builtIn/Or16.hdl 5 | 6 | /** 7 | * 16-bit bitwise Or gate: for i = 0..15 out[i] = a[i] or b[i]. 8 | */ 9 | 10 | CHIP Or16 { 11 | 12 | IN a[16], b[16]; 13 | OUT out[16]; 14 | 15 | BUILTIN Or; 16 | } 17 | -------------------------------------------------------------------------------- /tools/builtInChips/Or8Way.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/tools/builtInChips/Or8Way.class -------------------------------------------------------------------------------- /tools/builtInChips/Or8Way.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: tools/builtIn/Or8Way.hdl 5 | 6 | /** 7 | * 8-way Or gate: out = in[0] or in[1] or ... or in[7]. 8 | */ 9 | 10 | CHIP Or8Way { 11 | 12 | IN in[8]; 13 | OUT out; 14 | 15 | BUILTIN Or8Way; 16 | } 17 | -------------------------------------------------------------------------------- /tools/builtInChips/PC.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/tools/builtInChips/PC.class -------------------------------------------------------------------------------- /tools/builtInChips/PC.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: tools/builtIn/PC.hdl 5 | 6 | /** 7 | * 16-bit counter with load and reset controls. 8 | * 9 | * If reset(t-1) then out(t) = 0 10 | * else if load(t-1) then out(t) = in(t-1) 11 | * else if inc(t-1) then out(t) = out(t-1) + 1 (integer addition) 12 | * else out(t) = out(t-1) 13 | */ 14 | 15 | CHIP PC { 16 | 17 | IN in[16], load, inc, reset; 18 | OUT out[16]; 19 | 20 | BUILTIN PC; 21 | CLOCKED in, load, inc, reset; 22 | } 23 | -------------------------------------------------------------------------------- /tools/builtInChips/RAM.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/tools/builtInChips/RAM.class -------------------------------------------------------------------------------- /tools/builtInChips/RAM16K.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/tools/builtInChips/RAM16K.class -------------------------------------------------------------------------------- /tools/builtInChips/RAM16K.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: tools/builtIn/RAM16K.hdl 5 | 6 | /** 7 | * Memory of 16K registers, each 16-bit wide. 8 | * The chip facilitates read and write operations, as follows: 9 | * Read: out(t) = RAM16K[address(t)](t) 10 | * Write: If load(t-1) then RAM16K[address(t-1)](t) = in(t-1) 11 | * In words: the chip always outputs the value stored at the memory 12 | * location specified by address. If load=1, the in value is loaded 13 | * into the memory location specified by address. This value becomes 14 | * available through the out output starting from the next time step. 15 | */ 16 | 17 | CHIP RAM16K { 18 | 19 | IN in[16], load, address[14]; 20 | OUT out[16]; 21 | 22 | BUILTIN RAM16K; 23 | CLOCKED in, load; 24 | } 25 | -------------------------------------------------------------------------------- /tools/builtInChips/RAM4K.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/tools/builtInChips/RAM4K.class -------------------------------------------------------------------------------- /tools/builtInChips/RAM4K.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: tools/builtIn/RAM4K.hdl 5 | 6 | /** 7 | * Memory of 4K registers, each 16-bit wide. 8 | * The chip facilitates read and write operations, as follows: 9 | * Read: out(t) = RAM4K[address(t)](t) 10 | * Write: If load(t-1) then RAM4K[address(t-1)](t) = in(t-1) 11 | * In words: the chip always outputs the value stored at the memory 12 | * location specified by address. If load == 1, the in value is loaded 13 | * into the memory location specified by address. This value becomes 14 | * available through the out output starting from the next time step. 15 | */ 16 | 17 | CHIP RAM4K { 18 | 19 | IN in[16], load, address[12]; 20 | OUT out[16]; 21 | 22 | BUILTIN RAM4K; 23 | CLOCKED in, load; 24 | } 25 | -------------------------------------------------------------------------------- /tools/builtInChips/RAM512.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/tools/builtInChips/RAM512.class -------------------------------------------------------------------------------- /tools/builtInChips/RAM512.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: tools/builtIn/RAM512.hdl 5 | 6 | /** 7 | * Memory of 512 registers, each 16-bit wide. 8 | * The chip facilitates read and write operations, as follows: 9 | * Read: out(t) = RAM512[address(t)](t) 10 | * Write: If load(t-1) then RAM512[address(t-1)](t) = in(t-1) 11 | * In words: the chip always outputs the value stored at the memory 12 | * location specified by address. If load == 1, the in value is loaded 13 | * into the memory location specified by address. This value becomes 14 | * available through the out output starting from the next time step. 15 | */ 16 | 17 | CHIP RAM512 { 18 | 19 | IN in[16], load, address[9]; 20 | OUT out[16]; 21 | 22 | BUILTIN RAM512; 23 | CLOCKED in, load; 24 | } 25 | -------------------------------------------------------------------------------- /tools/builtInChips/RAM64.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/tools/builtInChips/RAM64.class -------------------------------------------------------------------------------- /tools/builtInChips/RAM64.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: tools/builtIn/RAM64.hdl 5 | 6 | /** 7 | * Memory of 64 registers, each 16-bit wide. 8 | * The chip facilitates read and write operations, as follows: 9 | * Read: out(t) = RAM64[address(t)](t) 10 | * Write: If load(t-1) then RAM64[address(t-1)](t) = in(t-1) 11 | * In words: the chip always outputs the value stored at the memory 12 | * location specified by address. If load == 1, the in value is loaded 13 | * into the memory location specified by address. This value becomes 14 | * available through the out output starting from the next time step. 15 | */ 16 | 17 | CHIP RAM64 { 18 | 19 | IN in[16], load, address[6]; 20 | OUT out[16]; 21 | 22 | BUILTIN RAM64; 23 | CLOCKED in, load; 24 | } 25 | -------------------------------------------------------------------------------- /tools/builtInChips/RAM8.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/tools/builtInChips/RAM8.class -------------------------------------------------------------------------------- /tools/builtInChips/RAM8.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: tools/builtIn/RAM8.hdl 5 | 6 | /** 7 | * Memory of 8 registers, each 16-bit wide. 8 | * The chip facilitates read and write operations, as follows: 9 | * Read: out(t) = RAM8[address(t)](t) 10 | * Write: If load(t-1) then RAM8[address(t-1)](t) = in(t-1) 11 | * In words: the chip always outputs the value stored at the memory 12 | * location specified by address. If load == 1, the in value is loaded 13 | * into the memory location specified by address. This value becomes 14 | * available through the out output starting from the next time step. 15 | */ 16 | 17 | CHIP RAM8 { 18 | 19 | IN in[16], load, address[3]; 20 | OUT out[16]; 21 | 22 | BUILTIN RAM8; 23 | CLOCKED in, load; 24 | } 25 | -------------------------------------------------------------------------------- /tools/builtInChips/ROM32K.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/tools/builtInChips/ROM32K.class -------------------------------------------------------------------------------- /tools/builtInChips/ROM32K.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: tools/builtIn/ROM32K.hdl 5 | 6 | /** 7 | * Read-Only memory (ROM) of 16K registers, each 16-bit wide. 8 | * The chip is designed to facilitate data read, as follows: 9 | * out(t) = ROM32K[address(t)](t) 10 | * In words: the chip always outputs the value stored at the 11 | * memory location specified by address. 12 | * 13 | * The built-in chip implementation has a GUI side-effect, 14 | * showing an array-like component that displays the ROM's 15 | * contents. The ROM32K chip is supposed to be pre-loaded with 16 | * a machine language program. To that end, the built-in chip 17 | * implementation also knows how to handle the "ROM32K load Xxx" 18 | * script command, where Xxx is the name of a text file containing 19 | * a program written in the Hack machine language. When the 20 | * simulator encounters such a command in a test script, the code 21 | * found in the file is loaded into the simulated ROM32K unit. 22 | */ 23 | 24 | CHIP ROM32K { 25 | 26 | IN address[15]; 27 | OUT out[16]; 28 | 29 | BUILTIN ROM32K; 30 | } 31 | -------------------------------------------------------------------------------- /tools/builtInChips/Register.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/tools/builtInChips/Register.class -------------------------------------------------------------------------------- /tools/builtInChips/Register.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: tools/builtIn/Register.hdl 5 | 6 | /** 7 | * 16-Bit register. 8 | * If load[t-1]=1 then out[t] = in[t-1] 9 | * else out does not change (out[t] = out[t-1]) 10 | */ 11 | 12 | CHIP Register { 13 | 14 | IN in[16], load; 15 | OUT out[16]; 16 | 17 | BUILTIN Register; 18 | CLOCKED in, load; 19 | } 20 | -------------------------------------------------------------------------------- /tools/builtInChips/RegisterWithGUI.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/tools/builtInChips/RegisterWithGUI.class -------------------------------------------------------------------------------- /tools/builtInChips/Screen.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/tools/builtInChips/Screen.class -------------------------------------------------------------------------------- /tools/builtInChips/Screen.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: tools/builtIn/Screen.hdl 5 | 6 | /** 7 | * The Screen (memory map). 8 | * Functions exactly like a 16-bit 8K RAM: 9 | * 1. out(t)=Screen[address(t)](t) 10 | * 2. If load(t-1) then Screen[address(t-1)](t)=in(t-1) 11 | * 12 | * The built-in chip implementation has the side effect of continuously 13 | * refreshing a visual 256 by 512 black-and-white screen, simulated 14 | * by the simulator. Each row in the visual screen is represented 15 | * by 32 consecutive 16-bit words, starting at the top left corner 16 | * of the visual screen. Thus the pixel at row r from the top and 17 | * column c from the left (0<=r<=255, 0<=c<=511) reflects the c%16 18 | * bit (counting from LSB to MSB) of the word found in 19 | * Screen[r*32+c/16]. 20 | */ 21 | 22 | CHIP Screen { 23 | 24 | IN in[16], // what to write 25 | load, // write-enable bit 26 | address[13]; // where to read/write 27 | OUT out[16]; // Screen value at the given address 28 | 29 | BUILTIN Screen; 30 | CLOCKED in, load; 31 | } 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /tools/builtInChips/Xor.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/tools/builtInChips/Xor.class -------------------------------------------------------------------------------- /tools/builtInChips/Xor.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of www.nand2tetris.org 2 | // and the book "The Elements of Computing Systems" 3 | // by Nisan and Schocken, MIT Press. 4 | // File name: tools/builtIn/Xor.hdl 5 | 6 | /** 7 | * Exclusive-or gate: out = !(a == b). 8 | */ 9 | 10 | CHIP Xor { 11 | 12 | IN a, b; 13 | OUT out; 14 | 15 | BUILTIN Xor; 16 | } 17 | -------------------------------------------------------------------------------- /tools/builtInVMCode/Array.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/tools/builtInVMCode/Array.class -------------------------------------------------------------------------------- /tools/builtInVMCode/JackOSClass.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/tools/builtInVMCode/JackOSClass.class -------------------------------------------------------------------------------- /tools/builtInVMCode/Keyboard.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/tools/builtInVMCode/Keyboard.class -------------------------------------------------------------------------------- /tools/builtInVMCode/Math.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/tools/builtInVMCode/Math.class -------------------------------------------------------------------------------- /tools/builtInVMCode/Memory.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/tools/builtInVMCode/Memory.class -------------------------------------------------------------------------------- /tools/builtInVMCode/Output.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/tools/builtInVMCode/Output.class -------------------------------------------------------------------------------- /tools/builtInVMCode/Screen.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/tools/builtInVMCode/Screen.class -------------------------------------------------------------------------------- /tools/builtInVMCode/String.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/tools/builtInVMCode/String.class -------------------------------------------------------------------------------- /tools/builtInVMCode/Sys.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ReionChan/nand2tetris/6e7dfdef735889af65e9c8ddd03432082db4540a/tools/builtInVMCode/Sys.class --------------------------------------------------------------------------------