├── tools
├── bin
│ ├── scripts
│ │ ├── defaultVM.txt
│ │ ├── defaultCPU.txt
│ │ └── defaultHW.txt
│ ├── Hardware Simulator.dat
│ ├── images
│ │ ├── ok.gif
│ │ ├── chip.gif
│ │ ├── equal.gif
│ │ ├── find.gif
│ │ ├── hex.gif
│ │ ├── ok2.gif
│ │ ├── open.gif
│ │ ├── open2.gif
│ │ ├── save.gif
│ │ ├── arrow2.gif
│ │ ├── cancel.gif
│ │ ├── clock2.gif
│ │ ├── opendoc.gif
│ │ ├── redflag.gif
│ │ ├── scroll.gif
│ │ ├── smallok.gif
│ │ ├── vcrstop.gif
│ │ ├── keyboard.gif
│ │ ├── smallequal.gif
│ │ ├── smallminus.gif
│ │ ├── smallnew.gif
│ │ ├── smallplus.gif
│ │ ├── vcrforward.gif
│ │ ├── vcrrewind.gif
│ │ ├── calculator2.gif
│ │ ├── smallcancel.gif
│ │ └── vcrfastforward.gif
│ ├── lib
│ │ ├── Hack.jar
│ │ ├── HackGUI.jar
│ │ ├── Compilers.jar
│ │ ├── Simulators.jar
│ │ ├── AssemblerGUI.jar
│ │ ├── SimulatorsGUI.jar
│ │ └── TranslatorsGUI.jar
│ ├── Virtual Machine Emulator.dat
│ ├── classes
│ │ ├── TextComparer.class
│ │ ├── VMEmulatorMain.class
│ │ ├── CPUEmulatorMain.class
│ │ ├── HackAssemblerMain.class
│ │ └── HardwareSimulatorMain.class
│ └── help
│ │ └── compiler.txt
├── .DS_Store
├── builtInChips
│ ├── ALU.hdl
│ ├── ALU.class
│ ├── And.class
│ ├── Bit.class
│ ├── DFF.class
│ ├── Mux.class
│ ├── Not.class
│ ├── Or.class
│ ├── PC.class
│ ├── RAM.class
│ ├── Xor.class
│ ├── Add16.class
│ ├── DMux.class
│ ├── Inc16.class
│ ├── Nand.class
│ ├── Not16.class
│ ├── Or8Way.class
│ ├── RAM16K.class
│ ├── RAM4K.class
│ ├── RAM512.class
│ ├── RAM64.class
│ ├── RAM8.class
│ ├── ROM32K.class
│ ├── Screen.class
│ ├── DMux4Way.class
│ ├── DMux8Way.class
│ ├── Keyboard.class
│ ├── Register.class
│ ├── ARegister.class
│ ├── DRegister.class
│ ├── FullAdder.class
│ ├── HalfAdder.class
│ ├── Mux4Way16.class
│ ├── Mux8Way16.class
│ ├── RegisterWithGUI.class
│ ├── Not.hdl
│ ├── Nand.hdl
│ ├── Xor.hdl
│ ├── And.hdl
│ ├── Mux.hdl
│ ├── Not16.hdl
│ ├── Or.hdl
│ ├── Or16.hdl
│ ├── And16.hdl
│ ├── Mux16.hdl
│ ├── Or8Way.hdl
│ ├── Add16.hdl
│ ├── DMux.hdl
│ ├── DFF.hdl
│ ├── Inc16.hdl
│ ├── Bit.hdl
│ ├── Register.hdl
│ ├── HalfAdder.hdl
│ ├── Mux4Way16.hdl
│ ├── FullAdder.hdl
│ ├── DMux4Way.hdl
│ ├── Mux8Way16.hdl
│ ├── DMux8Way.hdl
│ ├── PC.hdl
│ ├── ARegister.hdl
│ ├── DRegister.hdl
│ ├── Keyboard.hdl
│ ├── RAM8.hdl
│ ├── RAM4K.hdl
│ ├── RAM64.hdl
│ ├── RAM16K.hdl
│ ├── RAM512.hdl
│ ├── ROM32K.hdl
│ └── Screen.hdl
├── builtInVMCode
│ ├── Array.class
│ ├── Math.class
│ ├── Sys.class
│ ├── Memory.class
│ ├── Output.class
│ ├── Screen.class
│ ├── String.class
│ ├── Keyboard.class
│ └── JackOSClass.class
├── OS
│ └── Array.vm
├── TextComparer.bat
├── JackCompiler.bat
├── Assembler.bat
├── VMEmulator.bat
├── CPUEmulator.bat
├── TextComparer.sh
├── JackCompiler.sh
├── HardwareSimulator.bat
├── Assembler.sh
├── VMEmulator.sh
└── CPUEmulator.sh
├── projects
├── 10
│ ├── ArrayTest
│ │ └── Main.jack
│ ├── ExpressionLessSquare
│ │ └── Main.jack
│ └── Square
│ │ └── Main.jack
├── 11
│ ├── Seven
│ │ └── Main.jack
│ ├── Square
│ │ └── Main.jack
│ ├── Pong
│ │ └── Main.jack
│ └── Average
│ │ └── Main.jack
├── 12
│ ├── ArrayTest
│ │ ├── ArrayTest.cmp
│ │ ├── ArrayTest.tst
│ │ └── Main.jack
│ ├── OutputTest
│ │ ├── OutputTestOutput.gif
│ │ └── Main.jack
│ ├── ScreenTest
│ │ └── ScreenTestOutput.gif
│ ├── StringTest
│ │ └── StringTestOutput.gif
│ ├── KeyboardTest
│ │ └── KeyboardTestOutput.gif
│ ├── MemoryTest
│ │ ├── MemoryTest.cmp
│ │ ├── MemoryTest.tst
│ │ └── Main.jack
│ ├── MathTest
│ │ ├── MathTest.cmp
│ │ ├── MathTest.tst
│ │ └── Main.jack
│ ├── Array.jack
│ ├── Sys.jack
│ ├── SysTest
│ │ └── Main.jack
│ └── Memory.jack
├── 13
│ └── more fun to go.txt
├── 07
│ ├── MemoryAccess
│ │ ├── StaticTest
│ │ │ ├── StaticTest.cmp
│ │ │ ├── StaticTest.vm
│ │ │ ├── StaticTestVME.tst
│ │ │ └── StaticTest.tst
│ │ ├── PointerTest
│ │ │ ├── PointerTest.cmp
│ │ │ ├── PointerTest.vm
│ │ │ ├── PointerTest.tst
│ │ │ └── PointerTestVME.tst
│ │ └── BasicTest
│ │ │ ├── BasicTest.cmp
│ │ │ ├── BasicTest.vm
│ │ │ ├── BasicTest.tst
│ │ │ └── BasicTestVME.tst
│ └── StackArithmetic
│ │ ├── SimpleAdd
│ │ ├── SimpleAdd.cmp
│ │ ├── SimpleAdd.vm
│ │ ├── SimpleAddVME.tst
│ │ └── SimpleAdd.tst
│ │ └── StackTest
│ │ ├── StackTest.cmp
│ │ ├── StackTest.tst
│ │ ├── StackTestVME.tst
│ │ └── StackTest.vm
├── 01
│ ├── Not.cmp
│ ├── Not.out
│ ├── Or.cmp
│ ├── Or.out
│ ├── And.cmp
│ ├── And.out
│ ├── Or8Way.cmp
│ ├── Or8Way.out
│ ├── Xor.cmp
│ ├── Xor.out
│ ├── DMux.cmp
│ ├── DMux.out
│ ├── Not16.cmp
│ ├── Not16.out
│ ├── Mux.cmp
│ ├── Mux.out
│ ├── Not.hdl
│ ├── Not.tst
│ ├── DMux4Way.cmp
│ ├── DMux4Way.out
│ ├── And16.cmp
│ ├── And16.out
│ ├── Or16.cmp
│ ├── Or16.out
│ ├── And.hdl
│ ├── DMux.hdl
│ ├── Mux.hdl
│ ├── Or.hdl
│ ├── Or.tst
│ ├── Xor.hdl
│ ├── And.tst
│ ├── DMux.tst
│ ├── Xor.tst
│ ├── Or8Way.tst
│ ├── Not16.tst
│ ├── Mux16.cmp
│ ├── Mux16.out
│ ├── Mux4Way16.hdl
│ ├── Or8Way.hdl
│ ├── DMux4Way.hdl
│ ├── DMux4Way.tst
│ ├── Mux.tst
│ ├── Or16.tst
│ ├── And16.tst
│ ├── Mux8Way16.hdl
│ ├── Mux16.tst
│ ├── Mux4Way16.tst
│ ├── Not16.hdl
│ ├── Mux4Way16.cmp
│ ├── Mux4Way16.out
│ ├── DMux8Way.hdl
│ ├── Or16.hdl
│ ├── And16.hdl
│ ├── DMux8Way.cmp
│ ├── DMux8Way.out
│ ├── DMux8Way.tst
│ ├── Mux16.hdl
│ └── Mux8Way16.tst
├── 08
│ ├── ProgramFlow
│ │ ├── BasicLoop
│ │ │ ├── BasicLoop.cmp
│ │ │ ├── BasicLoop.tst
│ │ │ ├── BasicLoopVME.tst
│ │ │ └── BasicLoop.vm
│ │ └── FibonacciSeries
│ │ │ ├── FibonacciSeries.cmp
│ │ │ ├── FibonacciSeries.tst
│ │ │ ├── FibonacciSeriesVME.tst
│ │ │ └── FibonacciSeries.vm
│ └── FunctionCalls
│ │ ├── FibonacciElement
│ │ ├── FibonacciElement.cmp
│ │ ├── FibonacciElementVME.tst
│ │ ├── FibonacciElement.tst
│ │ ├── Sys.vm
│ │ └── Main.vm
│ │ ├── StaticsTest
│ │ ├── StaticsTest.cmp
│ │ ├── StaticsTest.tst
│ │ ├── StaticsTestVME.tst
│ │ ├── Class1.vm
│ │ ├── Class2.vm
│ │ └── Sys.vm
│ │ ├── SimpleFunction
│ │ ├── SimpleFunction.cmp
│ │ ├── SimpleFunction.vm
│ │ ├── SimpleFunction.tst
│ │ └── SimpleFunctionVME.tst
│ │ └── NestedCall
│ │ ├── NestedCall.cmp
│ │ └── Sys.vm
├── 00
│ ├── Project0.zip.zip
│ └── file.txt
├── 09
│ ├── Jack OS API.pdf
│ ├── BitmapEditor
│ │ └── BitmapEditor.iml
│ ├── HelloWorld
│ │ └── Main.jack
│ ├── Square
│ │ └── Main.jack
│ ├── Fraction
│ │ └── Main.jack
│ ├── List
│ │ └── Main.jack
│ └── Average
│ │ └── Main.jack
├── 05
│ ├── Add.hack
│ ├── Max.hack
│ ├── Rect.hack
│ ├── ComputerAdd-external.cmp
│ ├── Computer.hdl
│ ├── ComputerRect-external.cmp
│ ├── ComputerAdd-external.tst
│ ├── ComputerRect-external.tst
│ ├── ComputerAdd.tst
│ ├── ComputerRect.tst
│ ├── ComputerMax-external.tst
│ ├── ComputerAdd.cmp
│ ├── ComputerMax.tst
│ ├── Memory.hdl
│ └── ComputerMax-external.cmp
├── demo
│ ├── Xor.cmp
│ ├── Xor.out
│ ├── Xor.tst
│ └── Xor.hdl
├── 02
│ ├── HalfAdder.cmp
│ ├── HalfAdder.out
│ ├── Inc16.cmp
│ ├── Inc16.out
│ ├── FullAdder.cmp
│ ├── FullAdder.out
│ ├── Add16.cmp
│ ├── Add16.out
│ ├── HalfAdder.hdl
│ ├── HalfAdder.tst
│ ├── Inc16.tst
│ ├── FullAdder.hdl
│ ├── FullAdder.tst
│ ├── Add16.tst
│ └── Inc16.hdl
├── 04
│ ├── mult
│ │ ├── Mult.cmp
│ │ └── mult.asm
│ └── fill
│ │ ├── Fill.tst
│ │ ├── FillAutomatic.cmp
│ │ └── Fill.asm
├── 06
│ ├── add
│ │ └── Add.asm
│ ├── max
│ │ ├── MaxL.asm
│ │ └── Max.asm
│ └── rect
│ │ ├── RectL.asm
│ │ └── Rect.asm
└── 03
│ ├── a
│ ├── Bit.hdl
│ ├── PC.hdl
│ ├── Register.hdl
│ ├── RAM8.hdl
│ └── RAM64.hdl
│ └── b
│ └── RAM16K.hdl
├── projects_finished
├── project01
│ ├── Not.hdl
│ ├── And.hdl
│ ├── DMux.hdl
│ ├── Mux.hdl
│ ├── Or.hdl
│ ├── Xor.hdl
│ ├── Mux4Way16.hdl
│ ├── Or8Way.hdl
│ ├── DMux4Way.hdl
│ ├── Mux8Way16.hdl
│ ├── Not16.hdl
│ ├── DMux8Way.hdl
│ ├── Or16.hdl
│ ├── And16.hdl
│ └── Mux16.hdl
├── project02
│ ├── HalfAdder.hdl
│ ├── FullAdder.hdl
│ └── Inc16.hdl
└── project03
│ ├── a
│ ├── Bit.hdl
│ ├── PC.hdl
│ ├── Register.hdl
│ └── RAM8.hdl
│ └── b
│ └── RAM16K.hdl
└── README.md
/tools/bin/scripts/defaultVM.txt:
--------------------------------------------------------------------------------
1 | repeat {
2 | vmstep;
3 | }
--------------------------------------------------------------------------------
/tools/bin/scripts/defaultCPU.txt:
--------------------------------------------------------------------------------
1 | repeat {
2 | ticktock;
3 | }
--------------------------------------------------------------------------------
/tools/bin/scripts/defaultHW.txt:
--------------------------------------------------------------------------------
1 | repeat {
2 | tick,
3 | tock;
4 | }
--------------------------------------------------------------------------------
/projects/07/MemoryAccess/StaticTest/StaticTest.cmp:
--------------------------------------------------------------------------------
1 | |RAM[256]|
2 | | 1110 |
3 |
--------------------------------------------------------------------------------
/projects/01/Not.cmp:
--------------------------------------------------------------------------------
1 | | in | out |
2 | | 0 | 1 |
3 | | 1 | 0 |
4 |
--------------------------------------------------------------------------------
/projects/01/Not.out:
--------------------------------------------------------------------------------
1 | | in | out |
2 | | 0 | 1 |
3 | | 1 | 0 |
4 |
--------------------------------------------------------------------------------
/tools/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/tools/.DS_Store
--------------------------------------------------------------------------------
/projects/08/ProgramFlow/BasicLoop/BasicLoop.cmp:
--------------------------------------------------------------------------------
1 | | RAM[0] |RAM[256]|
2 | | 257 | 6 |
3 |
--------------------------------------------------------------------------------
/tools/bin/Hardware Simulator.dat:
--------------------------------------------------------------------------------
1 | C:\Users\iampanda\Desktop\nand2tetris\submissions\project03
2 |
--------------------------------------------------------------------------------
/projects/07/StackArithmetic/SimpleAdd/SimpleAdd.cmp:
--------------------------------------------------------------------------------
1 | | RAM[0] | RAM[256] |
2 | | 257 | 15 |
3 |
--------------------------------------------------------------------------------
/tools/bin/images/ok.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/tools/bin/images/ok.gif
--------------------------------------------------------------------------------
/tools/bin/lib/Hack.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/tools/bin/lib/Hack.jar
--------------------------------------------------------------------------------
/projects/08/FunctionCalls/FibonacciElement/FibonacciElement.cmp:
--------------------------------------------------------------------------------
1 | | RAM[0] |RAM[261]|
2 | | 262 | 3 |
3 |
--------------------------------------------------------------------------------
/tools/bin/images/chip.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/tools/bin/images/chip.gif
--------------------------------------------------------------------------------
/tools/bin/images/equal.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/tools/bin/images/equal.gif
--------------------------------------------------------------------------------
/tools/bin/images/find.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/tools/bin/images/find.gif
--------------------------------------------------------------------------------
/tools/bin/images/hex.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/tools/bin/images/hex.gif
--------------------------------------------------------------------------------
/tools/bin/images/ok2.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/tools/bin/images/ok2.gif
--------------------------------------------------------------------------------
/tools/bin/images/open.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/tools/bin/images/open.gif
--------------------------------------------------------------------------------
/tools/bin/images/open2.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/tools/bin/images/open2.gif
--------------------------------------------------------------------------------
/tools/bin/images/save.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/tools/bin/images/save.gif
--------------------------------------------------------------------------------
/tools/bin/lib/HackGUI.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/tools/bin/lib/HackGUI.jar
--------------------------------------------------------------------------------
/tools/builtInChips/ALU.hdl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/tools/builtInChips/ALU.hdl
--------------------------------------------------------------------------------
/projects/00/Project0.zip.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/projects/00/Project0.zip.zip
--------------------------------------------------------------------------------
/projects/09/Jack OS API.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/projects/09/Jack OS API.pdf
--------------------------------------------------------------------------------
/tools/bin/images/arrow2.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/tools/bin/images/arrow2.gif
--------------------------------------------------------------------------------
/tools/bin/images/cancel.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/tools/bin/images/cancel.gif
--------------------------------------------------------------------------------
/tools/bin/images/clock2.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/tools/bin/images/clock2.gif
--------------------------------------------------------------------------------
/tools/bin/images/opendoc.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/tools/bin/images/opendoc.gif
--------------------------------------------------------------------------------
/tools/bin/images/redflag.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/tools/bin/images/redflag.gif
--------------------------------------------------------------------------------
/tools/bin/images/scroll.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/tools/bin/images/scroll.gif
--------------------------------------------------------------------------------
/tools/bin/images/smallok.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/tools/bin/images/smallok.gif
--------------------------------------------------------------------------------
/tools/bin/images/vcrstop.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/tools/bin/images/vcrstop.gif
--------------------------------------------------------------------------------
/tools/bin/lib/Compilers.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/tools/bin/lib/Compilers.jar
--------------------------------------------------------------------------------
/tools/bin/lib/Simulators.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/tools/bin/lib/Simulators.jar
--------------------------------------------------------------------------------
/tools/builtInChips/ALU.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/tools/builtInChips/ALU.class
--------------------------------------------------------------------------------
/tools/builtInChips/And.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/tools/builtInChips/And.class
--------------------------------------------------------------------------------
/tools/builtInChips/Bit.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/tools/builtInChips/Bit.class
--------------------------------------------------------------------------------
/tools/builtInChips/DFF.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/tools/builtInChips/DFF.class
--------------------------------------------------------------------------------
/tools/builtInChips/Mux.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/tools/builtInChips/Mux.class
--------------------------------------------------------------------------------
/tools/builtInChips/Not.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/tools/builtInChips/Not.class
--------------------------------------------------------------------------------
/tools/builtInChips/Or.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/tools/builtInChips/Or.class
--------------------------------------------------------------------------------
/tools/builtInChips/PC.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/tools/builtInChips/PC.class
--------------------------------------------------------------------------------
/tools/builtInChips/RAM.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/tools/builtInChips/RAM.class
--------------------------------------------------------------------------------
/tools/builtInChips/Xor.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/tools/builtInChips/Xor.class
--------------------------------------------------------------------------------
/projects/08/FunctionCalls/StaticsTest/StaticsTest.cmp:
--------------------------------------------------------------------------------
1 | | RAM[0] |RAM[261]|RAM[262]|
2 | | 263 | -2 | 8 |
3 |
--------------------------------------------------------------------------------
/tools/bin/images/keyboard.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/tools/bin/images/keyboard.gif
--------------------------------------------------------------------------------
/tools/bin/images/smallequal.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/tools/bin/images/smallequal.gif
--------------------------------------------------------------------------------
/tools/bin/images/smallminus.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/tools/bin/images/smallminus.gif
--------------------------------------------------------------------------------
/tools/bin/images/smallnew.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/tools/bin/images/smallnew.gif
--------------------------------------------------------------------------------
/tools/bin/images/smallplus.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/tools/bin/images/smallplus.gif
--------------------------------------------------------------------------------
/tools/bin/images/vcrforward.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/tools/bin/images/vcrforward.gif
--------------------------------------------------------------------------------
/tools/bin/images/vcrrewind.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/tools/bin/images/vcrrewind.gif
--------------------------------------------------------------------------------
/tools/bin/lib/AssemblerGUI.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/tools/bin/lib/AssemblerGUI.jar
--------------------------------------------------------------------------------
/tools/bin/lib/SimulatorsGUI.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/tools/bin/lib/SimulatorsGUI.jar
--------------------------------------------------------------------------------
/tools/builtInChips/Add16.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/tools/builtInChips/Add16.class
--------------------------------------------------------------------------------
/tools/builtInChips/DMux.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/tools/builtInChips/DMux.class
--------------------------------------------------------------------------------
/tools/builtInChips/Inc16.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/tools/builtInChips/Inc16.class
--------------------------------------------------------------------------------
/tools/builtInChips/Nand.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/tools/builtInChips/Nand.class
--------------------------------------------------------------------------------
/tools/builtInChips/Not16.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/tools/builtInChips/Not16.class
--------------------------------------------------------------------------------
/tools/builtInChips/Or8Way.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/tools/builtInChips/Or8Way.class
--------------------------------------------------------------------------------
/tools/builtInChips/RAM16K.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/tools/builtInChips/RAM16K.class
--------------------------------------------------------------------------------
/tools/builtInChips/RAM4K.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/tools/builtInChips/RAM4K.class
--------------------------------------------------------------------------------
/tools/builtInChips/RAM512.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/tools/builtInChips/RAM512.class
--------------------------------------------------------------------------------
/tools/builtInChips/RAM64.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/tools/builtInChips/RAM64.class
--------------------------------------------------------------------------------
/tools/builtInChips/RAM8.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/tools/builtInChips/RAM8.class
--------------------------------------------------------------------------------
/tools/builtInChips/ROM32K.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/tools/builtInChips/ROM32K.class
--------------------------------------------------------------------------------
/tools/builtInChips/Screen.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/tools/builtInChips/Screen.class
--------------------------------------------------------------------------------
/tools/builtInVMCode/Array.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/tools/builtInVMCode/Array.class
--------------------------------------------------------------------------------
/tools/builtInVMCode/Math.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/tools/builtInVMCode/Math.class
--------------------------------------------------------------------------------
/tools/builtInVMCode/Sys.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/tools/builtInVMCode/Sys.class
--------------------------------------------------------------------------------
/projects/12/ArrayTest/ArrayTest.cmp:
--------------------------------------------------------------------------------
1 | |RAM[8000]|RAM[8001]|RAM[8002]|RAM[8003]|
2 | | 222 | 122 | 100 | 10 |
3 |
--------------------------------------------------------------------------------
/tools/bin/Virtual Machine Emulator.dat:
--------------------------------------------------------------------------------
1 | C:\Users\Eytan\Desktop\New folder\nand2tetris\projects\08\FunctionCalls\NestedCall
2 |
--------------------------------------------------------------------------------
/tools/bin/images/calculator2.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/tools/bin/images/calculator2.gif
--------------------------------------------------------------------------------
/tools/bin/images/smallcancel.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/tools/bin/images/smallcancel.gif
--------------------------------------------------------------------------------
/tools/bin/lib/TranslatorsGUI.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/tools/bin/lib/TranslatorsGUI.jar
--------------------------------------------------------------------------------
/tools/builtInChips/DMux4Way.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/tools/builtInChips/DMux4Way.class
--------------------------------------------------------------------------------
/tools/builtInChips/DMux8Way.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/tools/builtInChips/DMux8Way.class
--------------------------------------------------------------------------------
/tools/builtInChips/Keyboard.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/tools/builtInChips/Keyboard.class
--------------------------------------------------------------------------------
/tools/builtInChips/Register.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/tools/builtInChips/Register.class
--------------------------------------------------------------------------------
/tools/builtInVMCode/Memory.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/tools/builtInVMCode/Memory.class
--------------------------------------------------------------------------------
/tools/builtInVMCode/Output.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/tools/builtInVMCode/Output.class
--------------------------------------------------------------------------------
/tools/builtInVMCode/Screen.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/tools/builtInVMCode/Screen.class
--------------------------------------------------------------------------------
/tools/builtInVMCode/String.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/tools/builtInVMCode/String.class
--------------------------------------------------------------------------------
/tools/bin/classes/TextComparer.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/tools/bin/classes/TextComparer.class
--------------------------------------------------------------------------------
/tools/bin/images/vcrfastforward.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/tools/bin/images/vcrfastforward.gif
--------------------------------------------------------------------------------
/tools/builtInChips/ARegister.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/tools/builtInChips/ARegister.class
--------------------------------------------------------------------------------
/tools/builtInChips/DRegister.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/tools/builtInChips/DRegister.class
--------------------------------------------------------------------------------
/tools/builtInChips/FullAdder.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/tools/builtInChips/FullAdder.class
--------------------------------------------------------------------------------
/tools/builtInChips/HalfAdder.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/tools/builtInChips/HalfAdder.class
--------------------------------------------------------------------------------
/tools/builtInChips/Mux4Way16.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/tools/builtInChips/Mux4Way16.class
--------------------------------------------------------------------------------
/tools/builtInChips/Mux8Way16.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/tools/builtInChips/Mux8Way16.class
--------------------------------------------------------------------------------
/tools/builtInVMCode/Keyboard.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/tools/builtInVMCode/Keyboard.class
--------------------------------------------------------------------------------
/tools/bin/classes/VMEmulatorMain.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/tools/bin/classes/VMEmulatorMain.class
--------------------------------------------------------------------------------
/tools/builtInVMCode/JackOSClass.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/tools/builtInVMCode/JackOSClass.class
--------------------------------------------------------------------------------
/tools/bin/classes/CPUEmulatorMain.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/tools/bin/classes/CPUEmulatorMain.class
--------------------------------------------------------------------------------
/tools/bin/classes/HackAssemblerMain.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/tools/bin/classes/HackAssemblerMain.class
--------------------------------------------------------------------------------
/tools/builtInChips/RegisterWithGUI.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/tools/builtInChips/RegisterWithGUI.class
--------------------------------------------------------------------------------
/projects/05/Add.hack:
--------------------------------------------------------------------------------
1 | 0000000000000010
2 | 1110110000010000
3 | 0000000000000011
4 | 1110000010010000
5 | 0000000000000000
6 | 1110001100001000
7 |
--------------------------------------------------------------------------------
/projects/12/OutputTest/OutputTestOutput.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/projects/12/OutputTest/OutputTestOutput.gif
--------------------------------------------------------------------------------
/projects/12/ScreenTest/ScreenTestOutput.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/projects/12/ScreenTest/ScreenTestOutput.gif
--------------------------------------------------------------------------------
/projects/12/StringTest/StringTestOutput.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/projects/12/StringTest/StringTestOutput.gif
--------------------------------------------------------------------------------
/tools/bin/classes/HardwareSimulatorMain.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/tools/bin/classes/HardwareSimulatorMain.class
--------------------------------------------------------------------------------
/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/12/KeyboardTest/KeyboardTestOutput.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guptaanmol184/nand2tetris/HEAD/projects/12/KeyboardTest/KeyboardTestOutput.gif
--------------------------------------------------------------------------------
/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.out:
--------------------------------------------------------------------------------
1 | | a | b | out |
2 | | 0 | 0 | 0 |
3 | | 0 | 1 | 1 |
4 | | 1 | 0 | 1 |
5 | | 1 | 1 | 1 |
6 |
--------------------------------------------------------------------------------
/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.out:
--------------------------------------------------------------------------------
1 | | a | b | out |
2 | | 0 | 0 | 0 |
3 | | 0 | 1 | 0 |
4 | | 1 | 0 | 0 |
5 | | 1 | 1 | 1 |
6 |
--------------------------------------------------------------------------------
/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.out:
--------------------------------------------------------------------------------
1 | | in | out |
2 | | 00000000 | 0 |
3 | | 11111111 | 1 |
4 | | 00010000 | 1 |
5 | | 00000001 | 1 |
6 | | 00100110 | 1 |
7 |
--------------------------------------------------------------------------------
/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.out:
--------------------------------------------------------------------------------
1 | | a | b | out |
2 | | 0 | 0 | 0 |
3 | | 0 | 1 | 1 |
4 | | 1 | 0 | 1 |
5 | | 1 | 1 | 0 |
6 |
--------------------------------------------------------------------------------
/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/demo/Xor.cmp:
--------------------------------------------------------------------------------
1 | | a | b | out |
2 | | 0 | 0 | 0 |
3 | | 0 | 1 | 1 |
4 | | 1 | 0 | 1 |
5 | | 1 | 1 | 0 |
6 |
--------------------------------------------------------------------------------
/projects/demo/Xor.out:
--------------------------------------------------------------------------------
1 | | a | b | out |
2 | | 0 | 0 | 0 |
3 | | 0 | 1 | 1 |
4 | | 1 | 0 | 1 |
5 | | 1 | 1 | 0 |
6 |
--------------------------------------------------------------------------------
/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/NestedCall/NestedCall.cmp:
--------------------------------------------------------------------------------
1 | | RAM[0] | RAM[1] | RAM[2] | RAM[3] | RAM[4] | RAM[5] | RAM[6] |
2 | | 261 | 261 | 256 | 4000 | 5000 | 135 | 246 |
3 |
--------------------------------------------------------------------------------
/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/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/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.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/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.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/13/more fun to go.txt:
--------------------------------------------------------------------------------
1 | See Chapter 13. It's your call!
2 |
3 | And, if you develop something cool, please let us know about it.
4 |
5 | We hope that you enjoyed the course!
6 |
7 | -- Noam and Shimon
8 |
9 | www.nand2tetris.org
--------------------------------------------------------------------------------
/projects/02/Inc16.cmp:
--------------------------------------------------------------------------------
1 | | in | out |
2 | | 0000000000000000 | 0000000000000001 |
3 | | 1111111111111111 | 0000000000000000 |
4 | | 0000000000000101 | 0000000000000110 |
5 | | 1111111111111011 | 1111111111111100 |
6 |
--------------------------------------------------------------------------------
/projects/02/Inc16.out:
--------------------------------------------------------------------------------
1 | | in | out |
2 | | 0000000000000000 | 0000000000000001 |
3 | | 1111111111111111 | 0000000000000000 |
4 | | 0000000000000101 | 0000000000000110 |
5 | | 1111111111111011 | 1111111111111100 |
6 |
--------------------------------------------------------------------------------
/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.out:
--------------------------------------------------------------------------------
1 | | in | out |
2 | | 0000000000000000 | 1111111111111111 |
3 | | 1111111111111111 | 0000000000000000 |
4 | | 1010101010101010 | 0101010101010101 |
5 | | 0011110011000011 | 1100001100111100 |
6 | | 0001001000110100 | 1110110111001011 |
7 |
--------------------------------------------------------------------------------
/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/00/file.txt:
--------------------------------------------------------------------------------
1 | The only purpose of this file is to practice submitting files
2 | in the Nand to Tetris course websites in Coursera.
3 |
4 | There is no need to modify the contents of this file.
5 | All you have to do is submit it as is, following the
6 | Project 0 guidelines in the website.
--------------------------------------------------------------------------------
/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/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/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 (R0 refers to RAM[0])
7 |
8 | @2
9 | D=A
10 | @3
11 | D=D+A
12 | @0
13 | M=D
14 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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/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 | }
--------------------------------------------------------------------------------
/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.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/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.
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 | Nand(a=in ,b=in ,out=out);
17 | }
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/projects_finished/project01/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 | Nand(a=in ,b=in ,out=out);
17 | }
--------------------------------------------------------------------------------
/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/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/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 | }
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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.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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 "Make sure that 'No Animation' is selected. Then, select the keyboard, press any key for some time, and inspect the screen.";
8 |
9 | repeat {
10 | ticktock;
11 | }
12 |
--------------------------------------------------------------------------------
/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/09/BitmapEditor/BitmapEditor.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/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/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/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/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 |
--------------------------------------------------------------------------------
/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.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/04/fill/FillAutomatic.cmp:
--------------------------------------------------------------------------------
1 | |RAM[16384]|RAM[17648]|RAM[18349]|RAM[19444]|RAM[20771]|RAM[21031]|RAM[22596]|RAM[23754]|RAM[24575]|
2 | | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
3 | | -1 | -1 | -1 | -1 | -1 | -1 | -1 | -1 | -1 |
4 | | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
5 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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.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/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.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/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 | Nand(a=a ,b=b ,out=aNandb);
18 | Not(in=aNandb ,out=out);
19 | }
20 |
--------------------------------------------------------------------------------
/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/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 |
--------------------------------------------------------------------------------
/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/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_finished/project01/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 | Nand(a=a ,b=b ,out=aNandb);
18 | Not(in=aNandb ,out=out);
19 | }
20 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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/09/HelloWorld/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/HelloWorld/Main.jack
5 |
6 | /** Hello World program. */
7 | class Main {
8 | function void main() {
9 | /* Prints some text using the standard library. */
10 | do Output.printString("Hello world!");
11 | do Output.println(); // New line
12 | return;
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 | Not(in=sel ,out=Notsel);
18 | And(a=Notsel ,b=in ,out=a);
19 | And(a=sel ,b=in ,out=b);
20 | }
21 |
--------------------------------------------------------------------------------
/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/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 | /** Initializes a new Square Dance game and starts running it. */
7 | class Main {
8 | function void main() {
9 | var SquareGame game;
10 | let game = SquareGame.new();
11 | do game.run();
12 | do game.dispose();
13 | return;
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/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 | Not(in=sel ,out=Notsel);
18 | And(a=a ,b=Notsel ,out=o1);
19 | And(a=b ,b=sel ,out=o2);
20 | Or(a=o1 ,b=o2 ,out=out);
21 | }
--------------------------------------------------------------------------------
/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 | Xor(a=a ,b=b ,out=sum);
17 | And(a=a ,b=b ,out=carry);
18 | }
19 |
--------------------------------------------------------------------------------
/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/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/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 | Not(in=a ,out=Nota);
18 | Not(in=b ,out=Notb);
19 | And(a=Nota ,b=Notb ,out=NotaAndNotb);
20 | Not(in=NotaAndNotb ,out=out);
21 | }
22 |
--------------------------------------------------------------------------------
/projects_finished/project01/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 | Not(in=sel ,out=Notsel);
18 | And(a=Notsel ,b=in ,out=a);
19 | And(a=sel ,b=in ,out=b);
20 | }
21 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/projects_finished/project01/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 | Not(in=sel ,out=Notsel);
18 | And(a=a ,b=Notsel ,out=o1);
19 | And(a=b ,b=sel ,out=o2);
20 | Or(a=o1 ,b=o2 ,out=out);
21 | }
--------------------------------------------------------------------------------
/projects_finished/project02/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 | Xor(a=a ,b=b ,out=sum);
17 | And(a=a ,b=b ,out=carry);
18 | }
19 |
--------------------------------------------------------------------------------
/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/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 | Not(in=a ,out=Nota);
17 | Not(in=b ,out=Notb);
18 | And(a=a ,b=Notb, out=aAndNotb);
19 | And(a=Nota ,b=b, out=bAndNota);
20 | Or(a=aAndNotb ,b=bAndNota ,out=out);
21 | }
--------------------------------------------------------------------------------
/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/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/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/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 | Mux(a=dffout ,b=in ,sel=load ,out=todff);
18 | DFF(in=todff ,out=out ,out=dffout);
19 | }
20 |
--------------------------------------------------------------------------------
/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_finished/project01/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 | Not(in=a ,out=Nota);
18 | Not(in=b ,out=Notb);
19 | And(a=Nota ,b=Notb ,out=NotaAndNotb);
20 | Not(in=NotaAndNotb ,out=out);
21 | }
22 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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/demo/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/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/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, // loads 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_finished/project01/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 | Not(in=a ,out=Nota);
17 | Not(in=b ,out=Notb);
18 | And(a=a ,b=Notb, out=aAndNotb);
19 | And(a=Nota ,b=b, out=bAndNota);
20 | Or(a=aAndNotb ,b=bAndNota ,out=out);
21 | }
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/projects_finished/project03/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 | Mux(a=dffout ,b=in ,sel=load ,out=todff);
18 | DFF(in=todff ,out=out ,out=dffout);
19 | }
20 |
--------------------------------------------------------------------------------
/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/11/Square/Main.jack
5 |
6 | // (same as projects/09/Square/Main.jack)
7 |
8 | /** Initializes a new Square Dance game and starts running it. */
9 | class Main {
10 | function void main() {
11 | var SquareGame game;
12 | let game = SquareGame.new();
13 | do game.run();
14 | do game.dispose();
15 | return;
16 | }
17 | }
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/09/Fraction/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/Fraction/Main.jack
5 |
6 | // Computes the sum of 2/3 and 1/5.
7 | class Main {
8 | function void main() {
9 | var Fraction a, b, c;
10 | let a = Fraction.new(2,3);
11 | let b = Fraction.new(1,5);
12 | let c = a.plus(b); // Computes c = a + b
13 | do c.print(); // Prints "13/15"
14 | return;
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/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, // initializes the stack pointer
12 |
13 | repeat 11 { // StaticTest.vm has 11 instructions
14 | vmstep;
15 | }
16 |
17 | output; // the stack base
18 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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/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/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, // initializes the stack pointer
12 |
13 | repeat 200 { // enough cycles to complete the execution
14 | ticktock;
15 | }
16 |
17 | output; // the stack base
18 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 | }
--------------------------------------------------------------------------------
/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/09/List/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/List/Main.jack
5 |
6 | /** Demonstrates the use of the List abstraction. */
7 | class Main {
8 | function void main() {
9 | // Creates and uses the list (2,3,5).
10 | var List v;
11 | let v = List.new(5,null);
12 | let v = List.new(2,List.new(3,v));
13 | do v.print(); // prints 2 3 5
14 | do v.dispose(); // disposes the list
15 | return;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/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 a Pong game and starts running it. */
12 | function void main() {
13 | var PongGame game;
14 | do PongGame.newInstance();
15 | let game = PongGame.getInstance();
16 | do game.run();
17 | do game.dispose();
18 | return;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/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/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, // initializes the stack pointer
12 |
13 | repeat 3 { // SimpleAdd.vm has 3 instructions
14 | vmstep;
15 | }
16 |
17 | output; // the stack pointer and the stack base
18 |
--------------------------------------------------------------------------------
/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/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, // initializes the stack pointer
12 |
13 | repeat 60 { // enough cycles to complete the execution
14 | ticktock;
15 | }
16 |
17 | output; // the stack pointer and the stack base
18 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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.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/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 | Mux16(a=a ,b=b ,sel=sel[0] ,out=out1);
20 | Mux16(a=c ,b=d ,sel=sel[0] ,out=out2);
21 | Mux16(a= out1,b=out2 ,sel=sel[1] ,out=out);
22 | }
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/projects_finished/project01/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 | Mux16(a=a ,b=b ,sel=sel[0] ,out=out1);
20 | Mux16(a=c ,b=d ,sel=sel[0] ,out=out2);
21 | Mux16(a= out1,b=out2 ,sel=sel[1] ,out=out);
22 | }
--------------------------------------------------------------------------------
/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 | Or(a=in[0] ,b=in[1] ,out=temp0);
17 | Or(a=in[2] ,b=in[3] ,out=temp1);
18 | Or(a=in[4] ,b=in[5] ,out=temp2);
19 | Or(a=in[6] ,b=in[7] ,out=temp3);
20 | Or(a=temp0 ,b=temp1 ,out=temp4);
21 | Or(a=temp2 ,b=temp3 ,out=temp5);
22 | Or(a=temp4 ,b=temp5 ,out=out);
23 | }
--------------------------------------------------------------------------------
/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;
9 | // the screen should remain fully black as long as the key is pressed.
10 | // When no key is pressed, the program clears the screen, i.e. writes
11 | // "white" in every pixel;
12 | // the screen should remain fully clear as long as no key is pressed.
13 |
14 | // Put your code here.
--------------------------------------------------------------------------------
/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 results from translating both Main.vm and Sys.vm into
7 | // a single assembly program, stored in the file FibonacciElement.asm.
8 |
9 | load FibonacciElement.asm,
10 | output-file FibonacciElement.out,
11 | compare-to FibonacciElement.cmp,
12 | output-list RAM[0]%D1.6.1 RAM[261]%D1.6.1;
13 |
14 | repeat 6000 {
15 | ticktock;
16 | }
17 |
18 | output;
19 |
--------------------------------------------------------------------------------
/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_finished/project01/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 | Or(a=in[0] ,b=in[1] ,out=temp0);
17 | Or(a=in[2] ,b=in[3] ,out=temp1);
18 | Or(a=in[4] ,b=in[5] ,out=temp2);
19 | Or(a=in[6] ,b=in[7] ,out=temp3);
20 | Or(a=temp0 ,b=temp1 ,out=temp4);
21 | Or(a=temp2 ,b=temp3 ,out=temp5);
22 | Or(a=temp4 ,b=temp5 ,out=out);
23 | }
--------------------------------------------------------------------------------
/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 | DMux(in=in ,sel=sel[1] ,a=out0 ,b=out1);
20 |
21 | DMux(in=out0 ,sel=sel[0] ,a=a ,b=b);
22 | DMux(in=out1 ,sel=sel[0] ,a=c ,b=d);
23 | }
--------------------------------------------------------------------------------
/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/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 a constant, say n, onto the stack, and calls the Main.fibonacii
7 | // function, which computes the n'th element of the Fibonacci series.
8 | // Note that by convention, the Sys.init function is called "automatically"
9 | // by the bootstrap code.
10 |
11 | function Sys.init 0
12 | push constant 4
13 | call Main.fibonacci 1 // computes the 4'th fibonacci element
14 | label WHILE
15 | goto WHILE // loops infinitely
16 |
--------------------------------------------------------------------------------
/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 |
17 | Xor(a=a ,b=b ,out=temp);
18 | Xor(a=temp ,b=c ,out=sum);
19 |
20 | And(a=a ,b=b ,out=aAndb);
21 | And(a=b ,b=c ,out=bAndc);
22 | And(a=a ,b=c ,out=aAndc);
23 | Or(a=aAndb ,b=bAndc ,out=temp1);
24 | Or(a=temp1 ,b=aAndc ,out=carry);
25 | }
--------------------------------------------------------------------------------
/projects_finished/project01/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 | DMux(in=in ,sel=sel[1] ,a=out0 ,b=out1);
20 |
21 | DMux(in=out0 ,sel=sel[0] ,a=a ,b=b);
22 | DMux(in=out1 ,sel=sel[0] ,a=c ,b=d);
23 | }
--------------------------------------------------------------------------------
/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_finished/project02/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 |
17 | Xor(a=a ,b=b ,out=temp);
18 | Xor(a=temp ,b=c ,out=sum);
19 |
20 | And(a=a ,b=b ,out=aAndb);
21 | And(a=b ,b=c ,out=bAndc);
22 | And(a=a ,b=c ,out=aAndc);
23 | Or(a=aAndb ,b=bAndc ,out=temp1);
24 | Or(a=temp1 ,b=aAndc ,out=carry);
25 | }
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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, // initializes the stack pointer
13 |
14 | repeat 450 { // enough cycles to complete the execution
15 | ticktock;
16 | }
17 |
18 | // outputs the stack base, this, that, and
19 | // some values from the the this and that segments
20 | output;
21 |
--------------------------------------------------------------------------------
/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, // initializes the stack pointer
13 |
14 | repeat 15 { // PointerTest.vm has 15 instructions
15 | vmstep;
16 | }
17 |
18 | // outputs the stack base, this, that, and
19 | // some values from the the this and that segments
20 | output;
21 |
--------------------------------------------------------------------------------
/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 and 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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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/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/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.
8 | * In the Jack language, arrays are instances of the Array class.
9 | * Once declared, the array entries can be accessed using the usual
10 | * syntax arr[i]. Each array entry can hold a primitive data type as
11 | * well as any object type. Different array entries can have different
12 | * data types.
13 | */
14 | class Array {
15 |
16 | /** Constructs a new Array of the given size. */
17 | function Array new(int size) {
18 | }
19 |
20 | /** Disposes this array. */
21 | method void dispose() {
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/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/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 // initializes 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/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 that supports various program execution services.
8 | */
9 | class Sys {
10 |
11 | /** Performs all the initializations required by the OS. */
12 | function void init() {
13 | }
14 |
15 | /** Halts the program execution. */
16 | function void halt() {
17 | }
18 |
19 | /** Waits approximately duration milliseconds and returns. */
20 | function void wait(int duration) {
21 | }
22 |
23 | /** Displays the given error code in the form "ERR",
24 | * and halts the program's execution. */
25 | function void error(int errorCode) {
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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/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, // initializes the stack pointer
13 |
14 | repeat 1000 { // enough cycles to complete the execution
15 | ticktock;
16 | }
17 |
18 | // outputs the stack pointer (RAM[0]) and
19 | // the stack contents: RAM[256]-RAM[265]
20 | output;
21 | 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;
22 | output;
23 |
--------------------------------------------------------------------------------
/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, // initializes the stack pointer
13 |
14 | repeat 38 { // StackTest.vm consists of 38 instructions
15 | vmstep;
16 | }
17 |
18 | // outputs the stack pointer (RAM[0]) and
19 | // the stack contents: RAM[256]-RAM[265]
20 | output;
21 | 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;
22 | output;
23 |
--------------------------------------------------------------------------------
/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/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;
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # nand2tetris
2 |
3 | # Project on hold for sometime...
4 |
5 | ## nand2tetris site resources
6 | + nand2tetris website: http://www.nand2tetris.org
7 | + nand2tetris course book (The elements of computing systems): http://nand2tetris.org/book.php
8 | + course material (includes the book): http://nand2tetris.org/course.php
9 | + HDL survival guide: http://www.nand2tetris.org/software/HDL%20Survival%20Guide.html
10 | + nand2tetris software suit: http://www.nand2tetris.org/software.php
11 |
12 | ## nand2tetris on coursera
13 | + Part 1: https://www.coursera.org/learn/build-a-computer
14 | + Part 2: https://www.coursera.org/learn/nand2tetris2
15 |
16 | ## Basic blocks
17 | + The most fundamental block used for building all the combinational logic is a NAND GATE.
18 | * The most fundamental block used for building all the sequential logic is a D-FLIP FLOP.
19 |
--------------------------------------------------------------------------------
/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/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 | Inc16 (in=outREG, out=outREGINC);
20 |
21 | Mux16 (a=outREG, b=outREGINC, sel=inc, out=i);
22 | Mux16 (a=i, b=in, sel=load, out=l);
23 | Mux16 (a=l, b=false, sel=reset, out=toREG);
24 |
25 | Register (in=toREG, load=true, out=outREG, out=out);
26 | }
27 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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/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 | }
24 |
--------------------------------------------------------------------------------
/projects/09/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/09/Average/Main.jack
5 |
6 | // Inputs some numbers and computes their average
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); // constructs the array
15 |
16 | let i = 0;
17 | while (i < length) {
18 | let a[i] = Keyboard.readInt("Enter a number: ");
19 | let sum = sum + a[i];
20 | let i = i + 1;
21 | }
22 |
23 | do Output.printString("The average is ");
24 | do Output.printInt(sum / length);
25 | return;
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/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_finished/project03/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 | Inc16 (in=outREG, out=outREGINC);
20 |
21 | Mux16 (a=outREG, b=outREGINC, sel=inc, out=i);
22 | Mux16 (a=i, b=in, sel=load, out=l);
23 | Mux16 (a=l, b=false, sel=reset, out=toREG);
24 |
25 | Register (in=toREG, load=true, out=outREG, out=out);
26 | }
27 |
--------------------------------------------------------------------------------
/projects/demo/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/demo/Xor.hdl
5 |
6 | /**
7 | * Exclusive-or gate: true if either a is true and b is false, or
8 | * a is false and b is true; false otherwise.
9 | * QUESTION: how can the simulator execute this program properly without
10 | * HDL implementations of the underlying Not, And, and Or chip-parts?
11 | * Answer: since the demo folder contains no Not.hdl, And.hdl and Or.hdl
12 | * files, the simulator reverts to using their built-in implementations.
13 | */
14 |
15 | CHIP Xor {
16 | IN a, b;
17 | OUT out;
18 |
19 | PARTS:
20 | Not (in=a, out=nota);
21 | Not (in=b, out=notb);
22 | And (a=a, b=notb, out=x);
23 | And (a=nota, b=b, out=y);
24 | Or (a=x, b=y, out=out);
25 | }
--------------------------------------------------------------------------------
/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 | Mux16(a=a ,b=b ,sel=sel[0] ,out=out00);
22 | Mux16(a=c ,b=d ,sel=sel[0] ,out=out01);
23 | Mux16(a=e ,b=f ,sel=sel[0] ,out=out02);
24 | Mux16(a=g ,b=h ,sel=sel[0] ,out=out03);
25 | Mux16(a=out00 ,b=out01 ,sel=sel[1] ,out=out10);
26 | Mux16(a=out02 ,b=out03 ,sel=sel[1] ,out=out11);
27 | Mux16(a=out10 ,b=out11 ,sel=sel[2] ,out=out);
28 | }
--------------------------------------------------------------------------------
/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;
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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/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 | // (Same as projects/09/Average/Main.jack)
7 |
8 | // Inputs some numbers and computes their average
9 | class Main {
10 | function void main() {
11 | var Array a;
12 | var int length;
13 | var int i, sum;
14 |
15 | let length = Keyboard.readInt("How many numbers? ");
16 | let a = Array.new(length); // constructs the array
17 |
18 | let i = 0;
19 | while (i < length) {
20 | let a[i] = Keyboard.readInt("Enter a number: ");
21 | let sum = sum + a[i];
22 | let i = i + 1;
23 | }
24 |
25 | do Output.printString("The average is ");
26 | do Output.printInt(sum / length);
27 | return;
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/projects_finished/project01/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 | Mux16(a=a ,b=b ,sel=sel[0] ,out=out00);
22 | Mux16(a=c ,b=d ,sel=sel[0] ,out=out01);
23 | Mux16(a=e ,b=f ,sel=sel[0] ,out=out02);
24 | Mux16(a=g ,b=h ,sel=sel[0] ,out=out03);
25 | Mux16(a=out00 ,b=out01 ,sel=sel[1] ,out=out10);
26 | Mux16(a=out02 ,b=out03 ,sel=sel[1] ,out=out11);
27 | Mux16(a=out10 ,b=out11 ,sel=sel[2] ,out=out);
28 | }
--------------------------------------------------------------------------------
/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/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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/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 |
--------------------------------------------------------------------------------
/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 | Not(in=in[0] ,out=out[0]);
17 | Not(in=in[1] ,out=out[1]);
18 | Not(in=in[2] ,out=out[2]);
19 | Not(in=in[3] ,out=out[3]);
20 | Not(in=in[4] ,out=out[4]);
21 | Not(in=in[5] ,out=out[5]);
22 | Not(in=in[6] ,out=out[6]);
23 | Not(in=in[7] ,out=out[7]);
24 | Not(in=in[8] ,out=out[8]);
25 | Not(in=in[9] ,out=out[9]);
26 | Not(in=in[10] ,out=out[10]);
27 | Not(in=in[11] ,out=out[11]);
28 | Not(in=in[12] ,out=out[12]);
29 | Not(in=in[13] ,out=out[13]);
30 | Not(in=in[14] ,out=out[14]);
31 | Not(in=in[15] ,out=out[15]);
32 | }
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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_finished/project01/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 | Not(in=in[0] ,out=out[0]);
17 | Not(in=in[1] ,out=out[1]);
18 | Not(in=in[2] ,out=out[2]);
19 | Not(in=in[3] ,out=out[3]);
20 | Not(in=in[4] ,out=out[4]);
21 | Not(in=in[5] ,out=out[5]);
22 | Not(in=in[6] ,out=out[6]);
23 | Not(in=in[7] ,out=out[7]);
24 | Not(in=in[8] ,out=out[8]);
25 | Not(in=in[9] ,out=out[9]);
26 | Not(in=in[10] ,out=out[10]);
27 | Not(in=in[11] ,out=out[11]);
28 | Not(in=in[12] ,out=out[12]);
29 | Not(in=in[13] ,out=out[13]);
30 | Not(in=in[14] ,out=out[14]);
31 | Not(in=in[15] ,out=out[15]);
32 | }
--------------------------------------------------------------------------------
/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/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/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.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/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/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, // stack pointer
14 | set RAM[1] 300, // base address of the local segment
15 | set RAM[2] 400, // base address of the argument segment
16 | set RAM[3] 3000, // base address of the this segment
17 | set RAM[4] 3010, // base address of the that segment
18 |
19 | repeat 600 { // enough cycles to complete the execution
20 | ticktock;
21 | }
22 |
23 | // Outputs the stack base and some values
24 | // from the tested memory segments
25 | output;
26 |
--------------------------------------------------------------------------------
/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, // stack pointer
14 | set local 300, // base address of the local segment
15 | set argument 400, // base address of the argument segment
16 | set this 3000, // base address of the this segment
17 | set that 3010, // base address of the that segment
18 |
19 | repeat 25 { // BasicTest.vm has 25 instructions
20 | vmstep;
21 | }
22 |
23 | // Outputs the stack base and some values
24 | // from the tested memory segments
25 | output;
26 |
--------------------------------------------------------------------------------
/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 elapsed.");
28 |
29 | return;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/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 | // (identical to projects/09/Average/Main.jack)
7 |
8 | /** Computes the average of a sequence of integers. */
9 | class Main {
10 | function void main() {
11 | var Array a;
12 | var int length;
13 | var int i, sum;
14 |
15 | let length = Keyboard.readInt("HOW MANY NUMBERS? ");
16 | let a = Array.new(length);
17 | let i = 0;
18 |
19 | while (i < length) {
20 | let a[i] = Keyboard.readInt("ENTER THE NEXT NUMBER: ");
21 | let i = i + 1;
22 | }
23 |
24 | let i = 0;
25 | let sum = 0;
26 |
27 | while (i < length) {
28 | let sum = sum + a[i];
29 | let i = i + 1;
30 | }
31 |
32 | do Output.printString("THE AVERAGE IS: ");
33 | do Output.printInt(sum / length);
34 | do Output.println();
35 |
36 | return;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/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/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 | // stage 1
20 | DMux(in=in ,sel=sel[2] ,a=out0 ,b=out1);
21 |
22 | // stage 2
23 | DMux(in=out0 ,sel=sel[1] ,a=out2 ,b=out3);
24 | DMux(in=out1 ,sel=sel[1] ,a=out4 ,b=out5);
25 |
26 | // stage 3
27 | DMux(in=out2 ,sel=sel[0] ,a=a ,b=b);
28 | DMux(in=out3 ,sel=sel[0] ,a=c ,b=d);
29 | DMux(in=out4 ,sel=sel[0] ,a=e ,b=f);
30 | DMux(in=out5 ,sel=sel[0] ,a=g ,b=h);
31 |
32 |
33 |
34 | }
--------------------------------------------------------------------------------
/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 | Or(a=a[0] ,b=b[0] ,out=out[0]);
17 | Or(a=a[1] ,b=b[1] ,out=out[1]);
18 | Or(a=a[2] ,b=b[2] ,out=out[2]);
19 | Or(a=a[3] ,b=b[3] ,out=out[3]);
20 | Or(a=a[4] ,b=b[4] ,out=out[4]);
21 | Or(a=a[5] ,b=b[5] ,out=out[5]);
22 | Or(a=a[6] ,b=b[6] ,out=out[6]);
23 | Or(a=a[7] ,b=b[7] ,out=out[7]);
24 | Or(a=a[8] ,b=b[8] ,out=out[8]);
25 | Or(a=a[9] ,b=b[9] ,out=out[9]);
26 | Or(a=a[10] ,b=b[10] ,out=out[10]);
27 | Or(a=a[11] ,b=b[11] ,out=out[11]);
28 | Or(a=a[12] ,b=b[12] ,out=out[12]);
29 | Or(a=a[13] ,b=b[13] ,out=out[13]);
30 | Or(a=a[14] ,b=b[14] ,out=out[14]);
31 | Or(a=a[15] ,b=b[15] ,out=out[15]);
32 | }
--------------------------------------------------------------------------------
/projects_finished/project01/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 | // stage 1
20 | DMux(in=in ,sel=sel[2] ,a=out0 ,b=out1);
21 |
22 | // stage 2
23 | DMux(in=out0 ,sel=sel[1] ,a=out2 ,b=out3);
24 | DMux(in=out1 ,sel=sel[1] ,a=out4 ,b=out5);
25 |
26 | // stage 3
27 | DMux(in=out2 ,sel=sel[0] ,a=a ,b=b);
28 | DMux(in=out3 ,sel=sel[0] ,a=c ,b=d);
29 | DMux(in=out4 ,sel=sel[0] ,a=e ,b=f);
30 | DMux(in=out5 ,sel=sel[0] ,a=g ,b=h);
31 |
32 |
33 |
34 | }
--------------------------------------------------------------------------------
/projects_finished/project01/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 | Or(a=a[0] ,b=b[0] ,out=out[0]);
17 | Or(a=a[1] ,b=b[1] ,out=out[1]);
18 | Or(a=a[2] ,b=b[2] ,out=out[2]);
19 | Or(a=a[3] ,b=b[3] ,out=out[3]);
20 | Or(a=a[4] ,b=b[4] ,out=out[4]);
21 | Or(a=a[5] ,b=b[5] ,out=out[5]);
22 | Or(a=a[6] ,b=b[6] ,out=out[6]);
23 | Or(a=a[7] ,b=b[7] ,out=out[7]);
24 | Or(a=a[8] ,b=b[8] ,out=out[8]);
25 | Or(a=a[9] ,b=b[9] ,out=out[9]);
26 | Or(a=a[10] ,b=b[10] ,out=out[10]);
27 | Or(a=a[11] ,b=b[11] ,out=out[11]);
28 | Or(a=a[12] ,b=b[12] ,out=out[12]);
29 | Or(a=a[13] ,b=b[13] ,out=out[13]);
30 | Or(a=a[14] ,b=b[14] ,out=out[14]);
31 | Or(a=a[15] ,b=b[15] ,out=out[15]);
32 | }
--------------------------------------------------------------------------------
/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 | And(a=a[0] ,b=b[0] ,out=out[0]);
17 | And(a=a[1] ,b=b[1] ,out=out[1]);
18 | And(a=a[2] ,b=b[2] ,out=out[2]);
19 | And(a=a[3] ,b=b[3] ,out=out[3]);
20 | And(a=a[4] ,b=b[4] ,out=out[4]);
21 | And(a=a[5] ,b=b[5] ,out=out[5]);
22 | And(a=a[6] ,b=b[6] ,out=out[6]);
23 | And(a=a[7] ,b=b[7] ,out=out[7]);
24 | And(a=a[8] ,b=b[8] ,out=out[8]);
25 | And(a=a[9] ,b=b[9] ,out=out[9]);
26 | And(a=a[10] ,b=b[10] ,out=out[10]);
27 | And(a=a[11] ,b=b[11] ,out=out[11]);
28 | And(a=a[12] ,b=b[12] ,out=out[12]);
29 | And(a=a[13] ,b=b[13] ,out=out[13]);
30 | And(a=a[14] ,b=b[14] ,out=out[14]);
31 | And(a=a[15] ,b=b[15] ,out=out[15]);
32 | }
--------------------------------------------------------------------------------
/projects_finished/project01/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 | And(a=a[0] ,b=b[0] ,out=out[0]);
17 | And(a=a[1] ,b=b[1] ,out=out[1]);
18 | And(a=a[2] ,b=b[2] ,out=out[2]);
19 | And(a=a[3] ,b=b[3] ,out=out[3]);
20 | And(a=a[4] ,b=b[4] ,out=out[4]);
21 | And(a=a[5] ,b=b[5] ,out=out[5]);
22 | And(a=a[6] ,b=b[6] ,out=out[6]);
23 | And(a=a[7] ,b=b[7] ,out=out[7]);
24 | And(a=a[8] ,b=b[8] ,out=out[8]);
25 | And(a=a[9] ,b=b[9] ,out=out[9]);
26 | And(a=a[10] ,b=b[10] ,out=out[10]);
27 | And(a=a[11] ,b=b[11] ,out=out[11]);
28 | And(a=a[12] ,b=b[12] ,out=out[12]);
29 | And(a=a[13] ,b=b[13] ,out=out[13]);
30 | And(a=a[14] ,b=b[14] ,out=out[14]);
31 | And(a=a[15] ,b=b[15] ,out=out[15]);
32 | }
--------------------------------------------------------------------------------
/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 // checks 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, returns fib(n-2)+fib(n-1)
21 | push argument 0
22 | push constant 2
23 | sub
24 | call Main.fibonacci 1 // computes fib(n-2)
25 | push argument 0
26 | push constant 1
27 | sub
28 | call Main.fibonacci 1 // computes fib(n-1)
29 | add // returns fib(n-1) + fib(n-2)
30 | return
31 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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/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 |
--------------------------------------------------------------------------------
/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/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/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.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/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 | DMux4Way(in=load ,sel=address[12..13] ,a=loadRAM4K0 ,b=loadRAM4K1 ,c=loadRAM4K2 ,d=loadRAM4K3);
19 |
20 | RAM4K(in=in ,load=loadRAM4K0 ,address=address[0..11] ,out=outRAM4K0);
21 | RAM4K(in=in ,load=loadRAM4K1 ,address=address[0..11] ,out=outRAM4K1);
22 | RAM4K(in=in ,load=loadRAM4K2 ,address=address[0..11] ,out=outRAM4K2);
23 | RAM4K(in=in ,load=loadRAM4K3 ,address=address[0..11] ,out=outRAM4K3);
24 |
25 | Mux4Way16(a=outRAM4K0 ,b=outRAM4K1 ,c=outRAM4K2 ,d=outRAM4K3 ,sel=address[12..13] ,out=out);
26 |
27 | }
--------------------------------------------------------------------------------
/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 | Bit(in= in[0],load=load ,out=out[0]);
18 | Bit(in= in[1],load=load ,out=out[1]);
19 | Bit(in= in[2],load=load ,out=out[2]);
20 | Bit(in= in[3],load=load ,out=out[3]);
21 | Bit(in= in[4],load=load ,out=out[4]);
22 | Bit(in= in[5],load=load ,out=out[5]);
23 | Bit(in= in[6],load=load ,out=out[6]);
24 | Bit(in= in[7],load=load ,out=out[7]);
25 | Bit(in= in[8],load=load ,out=out[8]);
26 | Bit(in= in[9],load=load ,out=out[9]);
27 | Bit(in= in[10],load=load ,out=out[10]);
28 | Bit(in= in[11],load=load ,out=out[11]);
29 | Bit(in= in[12],load=load ,out=out[12]);
30 | Bit(in= in[13],load=load ,out=out[13]);
31 | Bit(in= in[14],load=load ,out=out[14]);
32 | Bit(in= in[15],load=load ,out=out[15]);
33 | }
34 |
--------------------------------------------------------------------------------
/projects_finished/project03/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 | DMux4Way(in=load ,sel=address[12..13] ,a=loadRAM4K0 ,b=loadRAM4K1 ,c=loadRAM4K2 ,d=loadRAM4K3);
19 |
20 | RAM4K(in=in ,load=loadRAM4K0 ,address=address[0..11] ,out=outRAM4K0);
21 | RAM4K(in=in ,load=loadRAM4K1 ,address=address[0..11] ,out=outRAM4K1);
22 | RAM4K(in=in ,load=loadRAM4K2 ,address=address[0..11] ,out=outRAM4K2);
23 | RAM4K(in=in ,load=loadRAM4K3 ,address=address[0..11] ,out=outRAM4K3);
24 |
25 | Mux4Way16(a=outRAM4K0 ,b=outRAM4K1 ,c=outRAM4K2 ,d=outRAM4K3 ,sel=address[12..13] ,out=out);
26 |
27 | }
--------------------------------------------------------------------------------
/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 | * This library provides two services: direct access to the computer's main
8 | * memory (RAM), and allocation and recycling of memory blocks. The Hack RAM
9 | * consists of 32,768 words, each holding a 16-bit binary number.
10 | */
11 | class Memory {
12 |
13 | /** Initializes the class. */
14 | function void init() {
15 | }
16 |
17 | /** Returns the RAM value at the given address. */
18 | function int peek(int address) {
19 | }
20 |
21 | /** Sets the RAM value at the given address to the given value. */
22 | function void poke(int address, int value) {
23 | }
24 |
25 | /** Finds an available RAM block of the given size and returns
26 | * a reference to its base address. */
27 | function int alloc(int size) {
28 | }
29 |
30 | /** De-allocates the given object (cast as an array) by making
31 | * it available for future allocations. */
32 | function void deAlloc(Array o) {
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 projects/10/Square/Main.jack. */
7 |
8 | class Main {
9 | static boolean test; // Added for testing -- there is no static keyword
10 | // in the Square files.
11 |
12 | function void main() {
13 | var SquareGame game;
14 | let game = game;
15 | do game.run();
16 | do game.dispose();
17 | return;
18 | }
19 |
20 | function void test() { // Added to test Jack syntax that is not use in
21 | var int i, j; // the Square files.
22 | var String s;
23 | var Array a;
24 | if (i) {
25 | let s = i;
26 | let s = j;
27 | let a[i] = j;
28 | }
29 | else { // There is no else keyword in the Square files.
30 | let i = i;
31 | let j = j;
32 | let i = i | j;
33 | }
34 | return;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/projects_finished/project03/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 | Bit(in= in[0],load=load ,out=out[0]);
18 | Bit(in= in[1],load=load ,out=out[1]);
19 | Bit(in= in[2],load=load ,out=out[2]);
20 | Bit(in= in[3],load=load ,out=out[3]);
21 | Bit(in= in[4],load=load ,out=out[4]);
22 | Bit(in= in[5],load=load ,out=out[5]);
23 | Bit(in= in[6],load=load ,out=out[6]);
24 | Bit(in= in[7],load=load ,out=out[7]);
25 | Bit(in= in[8],load=load ,out=out[8]);
26 | Bit(in= in[9],load=load ,out=out[9]);
27 | Bit(in= in[10],load=load ,out=out[10]);
28 | Bit(in= in[11],load=load ,out=out[11]);
29 | Bit(in= in[12],load=load ,out=out[12]);
30 | Bit(in= in[13],load=load ,out=out[13]);
31 | Bit(in= in[14],load=load ,out=out[14]);
32 | Bit(in= in[15],load=load ,out=out[15]);
33 | }
34 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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/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 |
--------------------------------------------------------------------------------
/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 | Mux (a=a[0], b=b[0], sel=sel, out=out[0]);
18 | Mux (a=a[1], b=b[1], sel=sel, out=out[1]);
19 | Mux (a=a[2], b=b[2], sel=sel, out=out[2]);
20 | Mux (a=a[3], b=b[3], sel=sel, out=out[3]);
21 | Mux (a=a[4], b=b[4], sel=sel, out=out[4]);
22 | Mux (a=a[5], b=b[5], sel=sel, out=out[5]);
23 | Mux (a=a[6], b=b[6], sel=sel, out=out[6]);
24 | Mux (a=a[7], b=b[7], sel=sel, out=out[7]);
25 | Mux (a=a[8], b=b[8], sel=sel, out=out[8]);
26 | Mux (a=a[9], b=b[9], sel=sel, out=out[9]);
27 | Mux (a=a[10], b=b[10], sel=sel, out=out[10]);
28 | Mux (a=a[11], b=b[11], sel=sel, out=out[11]);
29 | Mux (a=a[12], b=b[12], sel=sel, out=out[12]);
30 | Mux (a=a[13], b=b[13], sel=sel, out=out[13]);
31 | Mux (a=a[14], b=b[14], sel=sel, out=out[14]);
32 | Mux (a=a[15], b=b[15], sel=sel, out=out[15]);
33 | }
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/projects_finished/project01/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 | Mux (a=a[0], b=b[0], sel=sel, out=out[0]);
18 | Mux (a=a[1], b=b[1], sel=sel, out=out[1]);
19 | Mux (a=a[2], b=b[2], sel=sel, out=out[2]);
20 | Mux (a=a[3], b=b[3], sel=sel, out=out[3]);
21 | Mux (a=a[4], b=b[4], sel=sel, out=out[4]);
22 | Mux (a=a[5], b=b[5], sel=sel, out=out[5]);
23 | Mux (a=a[6], b=b[6], sel=sel, out=out[6]);
24 | Mux (a=a[7], b=b[7], sel=sel, out=out[7]);
25 | Mux (a=a[8], b=b[8], sel=sel, out=out[8]);
26 | Mux (a=a[9], b=b[9], sel=sel, out=out[9]);
27 | Mux (a=a[10], b=b[10], sel=sel, out=out[10]);
28 | Mux (a=a[11], b=b[11], sel=sel, out=out[11]);
29 | Mux (a=a[12], b=b[12], sel=sel, out=out[12]);
30 | Mux (a=a[13], b=b[13], sel=sel, out=out[13]);
31 | Mux (a=a[14], b=b[14], sel=sel, out=out[14]);
32 | Mux (a=a[15], b=b[15], sel=sel, out=out[15]);
33 | }
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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/10/Square/Main.jack
5 |
6 | // (derived from projects/09/Square/Main.jack, with testing additions)
7 |
8 | /** Initializes a new Square Dance game and starts running it. */
9 | class Main {
10 | static boolean test; // Added for testing -- there is no static keyword
11 | // in the Square files.
12 | function void main() {
13 | var SquareGame game;
14 | let game = SquareGame.new();
15 | do game.run();
16 | do game.dispose();
17 | return;
18 | }
19 |
20 | function void test() { // Added to test Jack syntax that is not use in
21 | var int i, j; // the Square files.
22 | var String s;
23 | var Array a;
24 | if (false) {
25 | let s = "string constant";
26 | let s = null;
27 | let a[1] = a[2];
28 | }
29 | else { // There is no else keyword in the Square files.
30 | let i = i * (-j);
31 | let j = j / (-2); // note: unary negate constant 2
32 | let i = i | j;
33 | }
34 | return;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/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 | DMux8Way(in=load ,sel=address ,a=loadreg0 ,b=loadreg1 ,c=loadreg2 ,d=loadreg3 ,e=loadreg4 ,f=loadreg5 ,g=loadreg6 ,h=loadreg7 );
19 |
20 | Register(in=in ,load=loadreg0 ,out=outreg0);
21 | Register(in=in ,load=loadreg1 ,out=outreg1);
22 | Register(in=in ,load=loadreg2 ,out=outreg2);
23 | Register(in=in ,load=loadreg3 ,out=outreg3);
24 | Register(in=in ,load=loadreg4 ,out=outreg4);
25 | Register(in=in ,load=loadreg5 ,out=outreg5);
26 | Register(in=in ,load=loadreg6 ,out=outreg6);
27 | Register(in=in ,load=loadreg7 ,out=outreg7);
28 |
29 | Mux8Way16(a=outreg0 ,b=outreg1 ,c=outreg2 ,d=outreg3 ,e=outreg4 ,f=outreg5 ,g=outreg6 ,h=outreg7 ,sel=address ,out=out);
30 | }
--------------------------------------------------------------------------------
/projects_finished/project03/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 | DMux8Way(in=load ,sel=address ,a=loadreg0 ,b=loadreg1 ,c=loadreg2 ,d=loadreg3 ,e=loadreg4 ,f=loadreg5 ,g=loadreg6 ,h=loadreg7 );
19 |
20 | Register(in=in ,load=loadreg0 ,out=outreg0);
21 | Register(in=in ,load=loadreg1 ,out=outreg1);
22 | Register(in=in ,load=loadreg2 ,out=outreg2);
23 | Register(in=in ,load=loadreg3 ,out=outreg3);
24 | Register(in=in ,load=loadreg4 ,out=outreg4);
25 | Register(in=in ,load=loadreg5 ,out=outreg5);
26 | Register(in=in ,load=loadreg6 ,out=outreg6);
27 | Register(in=in ,load=loadreg7 ,out=outreg7);
28 |
29 | Mux8Way16(a=outreg0 ,b=outreg1 ,c=outreg2 ,d=outreg3 ,e=outreg4 ,f=outreg5 ,g=outreg6 ,h=outreg7 ,sel=address ,out=out);
30 | }
--------------------------------------------------------------------------------
/projects/05/Memory.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/Memory.hdl
5 |
6 | /**
7 | * The complete address space of the Hack computer's memory,
8 | * including RAM and memory-mapped I/O.
9 | * The chip facilitates read and write operations, as follows:
10 | * Read: out(t) = Memory[address(t)](t)
11 | * Write: if load(t-1) then Memory[address(t-1)](t) = in(t-1)
12 | * In words: the chip always outputs the value stored at the memory
13 | * location specified by address. If load==1, the in value is loaded
14 | * into the memory location specified by address. This value becomes
15 | * available through the out output from the next time step onward.
16 | * Address space rules:
17 | * Only the upper 16K+8K+1 words of the Memory chip are used.
18 | * Access to address>0x6000 is invalid. Access to any address in
19 | * the range 0x4000-0x5FFF results in accessing the screen memory
20 | * map. Access to address 0x6000 results in accessing the keyboard
21 | * memory map. The behavior in these addresses is described in the
22 | * Screen and Keyboard chip specifications given in the book.
23 | */
24 |
25 | CHIP Memory {
26 | IN in[16], load, address[15];
27 | OUT out[16];
28 |
29 | PARTS:
30 | // Put your code here:
31 | }
--------------------------------------------------------------------------------
/projects/05/ComputerMax-external.cmp:
--------------------------------------------------------------------------------
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/12/MathTest/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/MathTest/Main.jack
5 |
6 | /** Test program for the OS Math class. */
7 | class Main {
8 |
9 | /** Performs various mathematical operations, using calls to the Math class methods. */
10 | function void main() {
11 | var Array r; // stores the test results;
12 |
13 | let r = 8000;
14 |
15 | let r[0] = 2 * 3; // 6
16 | let r[1] = r[0] * (-30); // 6 * (-30) = -180
17 | let r[2] = r[1] * 100; // (-180) * 100 = -18000
18 | let r[3] = 1 * r[2]; // 1 * (-18000) = -18000
19 | let r[4] = r[3] * 0; // 0
20 |
21 | let r[5] = 9 / 3; // 3
22 | let r[6] = (-18000) / 6; // -3000
23 | let r[7] = 32766 / (-32767); // 0
24 |
25 | let r[8] = Math.sqrt(9); // 3
26 | let r[9] = Math.sqrt(32767); // 181
27 |
28 | let r[10] = Math.min(345, 123); // 123
29 | let r[11] = Math.max(123, -345); // 123
30 | let r[12] = Math.abs(27); // 27
31 | let r[13] = Math.abs(-32767); // 32767
32 |
33 | return;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/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 | HalfAdder(a=in[0] ,b=true ,sum=out[0] , carry=carry1);
17 | HalfAdder(a=in[1] ,b=carry1 ,sum=out[1] , carry=carry2);
18 | HalfAdder(a=in[2] ,b=carry2 ,sum=out[2] , carry=carry3);
19 | HalfAdder(a=in[3] ,b=carry3 ,sum=out[3] , carry=carry4);
20 | HalfAdder(a=in[4] ,b=carry4 ,sum=out[4] , carry=carry5);
21 | HalfAdder(a=in[5] ,b=carry5 ,sum=out[5] , carry=carry6);
22 | HalfAdder(a=in[6] ,b=carry6 ,sum=out[6] , carry=carry7);
23 | HalfAdder(a=in[7] ,b=carry7 ,sum=out[7] , carry=carry8);
24 | HalfAdder(a=in[8] ,b=carry8 ,sum=out[8] , carry=carry9);
25 | HalfAdder(a=in[9] ,b=carry9 ,sum=out[9] , carry=carry10);
26 | HalfAdder(a=in[10] ,b=carry10 ,sum=out[10] , carry=carry11);
27 | HalfAdder(a=in[11] ,b=carry11 ,sum=out[11] , carry=carry12);
28 | HalfAdder(a=in[12] ,b=carry12 ,sum=out[12] , carry=carry13);
29 | HalfAdder(a=in[13] ,b=carry13 ,sum=out[13] , carry=carry14);
30 | HalfAdder(a=in[14] ,b=carry14 ,sum=out[14] , carry=carry15);
31 | HalfAdder(a=in[15] ,b=carry15 ,sum=out[15] , carry=carry16);
32 | }
--------------------------------------------------------------------------------
/projects/12/OutputTest/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/OutputTest/Main.jack
5 |
6 | /** Test program for the OS Output class. */
7 | class Main {
8 |
9 | /** Outputs the entire character set to the screen using all the
10 | * methods of the Output class. */
11 | function void main() {
12 | var String s;
13 |
14 | let s = String.new(1);
15 | do s.appendChar(String.doubleQuote());
16 |
17 | do Output.moveCursor(0, 63);
18 | do Output.printChar(66);
19 | do Output.moveCursor(22, 0);
20 | do Output.printChar(67);
21 | do Output.moveCursor(22, 63);
22 | do Output.printChar(68);
23 | do Output.printChar(65);
24 |
25 | do Output.moveCursor(2, 0);
26 | do Output.printString("0123456789");
27 | do Output.println();
28 |
29 | do Output.printString("ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz");
30 | do Output.println();
31 |
32 | do Output.printString("!#$%&'()*+,-./:;<=>?@[\]^_`{|}~");
33 | do Output.printString(s);
34 | do Output.println();
35 |
36 | do Output.printInt(-12345);
37 | do Output.backSpace();
38 | do Output.printInt(6789);
39 |
40 | return;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/projects_finished/project02/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 | HalfAdder(a=in[0] ,b=true ,sum=out[0] , carry=carry1);
17 | HalfAdder(a=in[1] ,b=carry1 ,sum=out[1] , carry=carry2);
18 | HalfAdder(a=in[2] ,b=carry2 ,sum=out[2] , carry=carry3);
19 | HalfAdder(a=in[3] ,b=carry3 ,sum=out[3] , carry=carry4);
20 | HalfAdder(a=in[4] ,b=carry4 ,sum=out[4] , carry=carry5);
21 | HalfAdder(a=in[5] ,b=carry5 ,sum=out[5] , carry=carry6);
22 | HalfAdder(a=in[6] ,b=carry6 ,sum=out[6] , carry=carry7);
23 | HalfAdder(a=in[7] ,b=carry7 ,sum=out[7] , carry=carry8);
24 | HalfAdder(a=in[8] ,b=carry8 ,sum=out[8] , carry=carry9);
25 | HalfAdder(a=in[9] ,b=carry9 ,sum=out[9] , carry=carry10);
26 | HalfAdder(a=in[10] ,b=carry10 ,sum=out[10] , carry=carry11);
27 | HalfAdder(a=in[11] ,b=carry11 ,sum=out[11] , carry=carry12);
28 | HalfAdder(a=in[12] ,b=carry12 ,sum=out[12] , carry=carry13);
29 | HalfAdder(a=in[13] ,b=carry13 ,sum=out[13] , carry=carry14);
30 | HalfAdder(a=in[14] ,b=carry14 ,sum=out[14] , carry=carry15);
31 | HalfAdder(a=in[15] ,b=carry15 ,sum=out[15] , carry=carry16);
32 | }
--------------------------------------------------------------------------------
/tools/VMEmulator.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | # $Id: VMEmulator.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 VM Emulator in interactive mode."
16 | echo " `basename "$0"` FILE.tst Starts the VM Emulator and runs the FILE.tst test"
17 | echo " script. The success/failure message is"
18 | echo " printed to the command console."
19 | elif [ $# -eq 0 ]
20 | then
21 | # Run VM emulator in interactive mode
22 | 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" VMEmulatorMain &
23 | else
24 | # Convert arg1 to an absolute path and run VM emulator with arg1
25 | if [ `echo "$1" | sed -e "s/\(.\).*/\1/"` = / ]
26 | then
27 | arg1="$1"
28 | else
29 | arg1="${dir}/$1"
30 | fi
31 | # echo Running "$arg1"
32 | 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" VMEmulatorMain "$arg1"
33 | fi
34 |
--------------------------------------------------------------------------------
/tools/CPUEmulator.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | # $Id: CPUEmulator.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 CPU Emulator in interactive mode."
16 | echo " `basename "$0"` FILE.tst Starts the CPU Emulator and runs the File.tst"
17 | echo " test script. The success/failure message"
18 | echo " is printed to the command console."
19 | elif [ $# -eq 0 ]
20 | then
21 | # Run CPU emulator in interactive mode
22 | 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" CPUEmulatorMain &
23 | else
24 | # Convert arg1 to an absolute path and run CPU emulator with arg1
25 | if [ `echo "$1" | sed -e "s/\(.\).*/\1/"` = / ]
26 | then
27 | arg1="$1"
28 | else
29 | arg1="${dir}/$1"
30 | fi
31 | # echo Running "$arg1"
32 | 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" CPUEmulatorMain "$arg1"
33 | fi
34 |
--------------------------------------------------------------------------------
/projects/08/FunctionCalls/NestedCall/Sys.vm:
--------------------------------------------------------------------------------
1 | // Sys.vm for NestedCall test.
2 |
3 | // Sys.init()
4 | //
5 | // Calls Sys.main() and stores return value in temp 1.
6 | // Does not return. (Enters infinite loop.)
7 |
8 | function Sys.init 0
9 | push constant 4000 // test THIS and THAT context save
10 | pop pointer 0
11 | push constant 5000
12 | pop pointer 1
13 | call Sys.main 0
14 | pop temp 1
15 | label LOOP
16 | goto LOOP
17 |
18 | // Sys.main()
19 | //
20 | // Sets locals 1, 2 and 3, leaving locals 0 and 4 unchanged to test
21 | // default local initialization to 0. (RAM set to -1 by test setup.)
22 | // Calls Sys.add12(123) and stores return value (135) in temp 0.
23 | // Returns local 0 + local 1 + local 2 + local 3 + local 4 (456) to confirm
24 | // that locals were not mangled by function call.
25 |
26 | function Sys.main 5
27 | push constant 4001
28 | pop pointer 0
29 | push constant 5001
30 | pop pointer 1
31 | push constant 200
32 | pop local 1
33 | push constant 40
34 | pop local 2
35 | push constant 6
36 | pop local 3
37 | push constant 123
38 | call Sys.add12 1
39 | pop temp 0
40 | push local 0
41 | push local 1
42 | push local 2
43 | push local 3
44 | push local 4
45 | add
46 | add
47 | add
48 | add
49 | return
50 |
51 | // Sys.add12(int n)
52 | //
53 | // Returns n+12.
54 |
55 | function Sys.add12 0
56 | push constant 4002
57 | pop pointer 0
58 | push constant 5002
59 | pop pointer 1
60 | push argument 0
61 | push constant 12
62 | add
63 | return
64 |
--------------------------------------------------------------------------------
/projects/12/MemoryTest/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/MemoryTest/Main.jack
5 |
6 | /** Test program for the OS Memory class. */
7 | class Main {
8 |
9 | /** Performs various memory manipulations. */
10 | function void main() {
11 | var int temp;
12 | var Array a, b, c;
13 |
14 | do Memory.poke(8000, 333); // RAM[8000] = 333
15 | let temp = Memory.peek(8000);
16 | do Memory.poke(8001, temp + 1); // RAM[8001] = 334
17 |
18 | let a = Array.new(3); // uses Memory.alloc
19 | let a[2] = 222;
20 | do Memory.poke(8002, a[2]); // RAM[8002] = 222
21 |
22 | let b = Array.new(3);
23 | let b[1] = a[2] - 100;
24 | do Memory.poke(8003, b[1]); // RAM[8003] = 122
25 |
26 | let c = Array.new(500);
27 | let c[499] = a[2] - b[1];
28 | do Memory.poke(8004, c[499]); // RAM[8004] = 100
29 |
30 | do a.dispose(); // uses Memory.deAlloc
31 | do b.dispose();
32 |
33 | let b = Array.new(3);
34 | let b[0] = c[499] - 90;
35 | do Memory.poke(8005, b[0]); // RAM[8005] = 10
36 |
37 | do c.dispose();
38 | do b.dispose();
39 |
40 | return;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/projects/01/Mux8Way16.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/Mux8Way16.tst
5 |
6 | load Mux8Way16.hdl,
7 | output-file Mux8Way16.out,
8 | compare-to Mux8Way16.cmp,
9 | output-list a%B1.16.1 b%B1.16.1 c%B1.16.1 d%B1.16.1 e%B1.16.1 f%B1.16.1 g%B1.16.1 h%B1.16.1 sel%B2.3.2 out%B1.16.1;
10 |
11 | set a 0,
12 | set b 0,
13 | set c 0,
14 | set d 0,
15 | set e 0,
16 | set f 0,
17 | set g 0,
18 | set h 0,
19 | set sel 0,
20 | eval,
21 | output;
22 |
23 | set sel 1,
24 | eval,
25 | output;
26 |
27 | set sel 2,
28 | eval,
29 | output;
30 |
31 | set sel 3,
32 | eval,
33 | output;
34 |
35 | set sel 4,
36 | eval,
37 | output;
38 |
39 | set sel 5,
40 | eval,
41 | output;
42 |
43 | set sel 6,
44 | eval,
45 | output;
46 |
47 | set sel 7,
48 | eval,
49 | output;
50 |
51 | set a %B0001001000110100,
52 | set b %B0010001101000101,
53 | set c %B0011010001010110,
54 | set d %B0100010101100111,
55 | set e %B0101011001111000,
56 | set f %B0110011110001001,
57 | set g %B0111100010011010,
58 | set h %B1000100110101011,
59 | set sel 0,
60 | eval,
61 | output;
62 |
63 | set sel 1,
64 | eval,
65 | output;
66 |
67 | set sel 2,
68 | eval,
69 | output;
70 |
71 | set sel 3,
72 | eval,
73 | output;
74 |
75 | set sel 4,
76 | eval,
77 | output;
78 |
79 | set sel 5,
80 | eval,
81 | output;
82 |
83 | set sel 6,
84 | eval,
85 | output;
86 |
87 | set sel 7,
88 | eval,
89 | output;
90 |
--------------------------------------------------------------------------------
/projects/08/ProgramFlow/FibonacciSeries/FibonacciSeries.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/FibonacciSeries/FibonacciSeries.vm
5 |
6 | // Puts the first argument[0] elements of the Fibonacci series
7 | // in the memory, starting in the address given in argument[1].
8 | // Argument[0] and argument[1] are initialized by the test script
9 | // before this code starts running.
10 |
11 | push argument 1
12 | pop pointer 1 // that = argument[1]
13 |
14 | push constant 0
15 | pop that 0 // first element in the series = 0
16 | push constant 1
17 | pop that 1 // second element in the series = 1
18 |
19 | push argument 0
20 | push constant 2
21 | sub
22 | pop argument 0 // num_of_elements -= 2 (first 2 elements are set)
23 |
24 | label MAIN_LOOP_START
25 |
26 | push argument 0
27 | if-goto COMPUTE_ELEMENT // if num_of_elements > 0, goto COMPUTE_ELEMENT
28 | goto END_PROGRAM // otherwise, goto END_PROGRAM
29 |
30 | label COMPUTE_ELEMENT
31 |
32 | push that 0
33 | push that 1
34 | add
35 | pop that 2 // that[2] = that[0] + that[1]
36 |
37 | push pointer 1
38 | push constant 1
39 | add
40 | pop pointer 1 // that += 1
41 |
42 | push argument 0
43 | push constant 1
44 | sub
45 | pop argument 0 // num_of_elements--
46 |
47 | goto MAIN_LOOP_START
48 |
49 | label END_PROGRAM
50 |
--------------------------------------------------------------------------------
/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 | DMux8Way(in=load ,sel=address[3..5] ,a=loadRAM80 ,b=loadRAM81 ,c=loadRAM82 ,d=loadRAM83 ,e=loadRAM84 ,f=loadRAM85 ,g=loadRAM86 ,h=loadRAM87 );
19 |
20 | RAM8(in=in ,load=loadRAM80 ,address=address[0..2] ,out=outRAM80);
21 | RAM8(in=in ,load=loadRAM81 ,address=address[0..2] ,out=outRAM81);
22 | RAM8(in=in ,load=loadRAM82 ,address=address[0..2] ,out=outRAM82);
23 | RAM8(in=in ,load=loadRAM83 ,address=address[0..2] ,out=outRAM83);
24 | RAM8(in=in ,load=loadRAM84 ,address=address[0..2] ,out=outRAM84);
25 | RAM8(in=in ,load=loadRAM85 ,address=address[0..2] ,out=outRAM85);
26 | RAM8(in=in ,load=loadRAM86 ,address=address[0..2] ,out=outRAM86);
27 | RAM8(in=in ,load=loadRAM87 ,address=address[0..2] ,out=outRAM87);
28 |
29 | Mux8Way16(a=outRAM80 ,b=outRAM81 ,c=outRAM82 ,d=outRAM83 ,e=outRAM84 ,f=outRAM85 ,g=outRAM86 ,h=outRAM87 ,sel=address[3..5] ,out=out);
30 | }
--------------------------------------------------------------------------------