This commit is contained in:
2021-04-21 17:01:42 +03:00
commit 281a96945a
613 changed files with 202255 additions and 0 deletions

602
.gitignore vendored Normal file
View File

@@ -0,0 +1,602 @@
.history
# Prerequisites
*.d
# Compiled Object files
*.slo
*.lo
*.o
*.obj
# Precompiled Headers
*.gch
*.pch
# Compiled Dynamic libraries
*.so
*.dylib
*.dll
# Fortran module files
*.mod
*.smod
# Compiled Static libraries
*.lai
*.la
*.a
*.lib
# Executables
*.exe
*.out
*.app
# Prerequisites
*.d
# Object files
*.o
*.ko
*.obj
*.elf
# Linker output
*.ilk
*.map
*.exp
# Precompiled Headers
*.gch
*.pch
# Libraries
*.lib
*.a
*.la
*.lo
# Shared objects (inc. Windows DLLs)
*.dll
*.so
*.so.*
*.dylib
# Executables
*.exe
*.out
*.app
*.i*86
*.x86_64
*.hex
# Debug files
*.dSYM/
*.su
*.idb
*.pdb
# Kernel Module Compile Results
*.mod*
*.cmd
.tmp_versions/
modules.order
Module.symvers
Mkfile.old
dkms.conf
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
.pybuilder/
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version
# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/
# Celery stuff
celerybeat-schedule
celerybeat.pid
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/
# pytype static type analyzer
.pytype/
# Cython debug symbols
cython_debug/
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
##
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
# User-specific files
*.rsuser
*.suo
*.user
*.userosscache
*.sln.docstates
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
# Mono auto generated files
mono_crash.*
# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
[Ww][Ii][Nn]32/
[Aa][Rr][Mm]/
[Aa][Rr][Mm]64/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/
[Ll]ogs/
# Visual Studio 2015/2017 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/
# Visual Studio 2017 auto generated files
Generated\ Files/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
# NUnit
*.VisualState.xml
TestResult.xml
nunit-*.xml
# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c
# Benchmark Results
BenchmarkDotNet.Artifacts/
# .NET Core
project.lock.json
project.fragment.lock.json
artifacts/
# ASP.NET Scaffolding
ScaffoldingReadMe.txt
# StyleCop
StyleCopReport.xml
# Files built by Visual Studio
*_i.c
*_p.c
*_h.h
*.ilk
*.meta
*.obj
*.iobj
*.pch
*.pdb
*.ipdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*_wpftmp.csproj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc
# Chutzpah Test files
_Chutzpah*
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opendb
*.opensdf
*.sdf
*.cachefile
*.VC.db
*.VC.VC.opendb
# Visual Studio profiler
*.psess
*.vsp
*.vspx
*.sap
# Visual Studio Trace Files
*.e2e
# TFS 2012 Local Workspace
$tf/
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# AxoCover is a Code Coverage Tool
.axoCover/*
!.axoCover/settings.json
# Coverlet is a free, cross platform Code Coverage Tool
coverage*.json
coverage*.xml
coverage*.info
# Visual Studio code coverage results
*.coverage
*.coveragexml
# NCrunch
_NCrunch_*
.*crunch*.local.xml
nCrunchTemp_*
# MightyMoose
*.mm.*
AutoTest.Net/
# Web workbench (sass)
.sass-cache/
# Installshield output folder
[Ee]xpress/
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish/
# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# Note: Comment the next line if you want to checkin your web deploy settings,
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
*.publishproj
# Microsoft Azure Web App publish settings. Comment the next line if you want to
# checkin your Azure Web App publish settings, but sensitive information contained
# in these scripts will be unencrypted
PublishScripts/
# NuGet Packages
*.nupkg
# NuGet Symbol Packages
*.snupkg
# The packages folder can be ignored because of Package Restore
**/[Pp]ackages/*
# except build/, which is used as an MSBuild target.
!**/[Pp]ackages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/[Pp]ackages/repositories.config
# NuGet v3's project.json files produces more ignorable files
*.nuget.props
*.nuget.targets
# Microsoft Azure Build Output
csx/
*.build.csdef
# Microsoft Azure Emulator
ecf/
rcf/
# Windows Store app package directories and files
AppPackages/
BundleArtifacts/
Package.StoreAssociation.xml
_pkginfo.txt
*.appx
*.appxbundle
*.appxupload
# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!?*.[Cc]ache/
# Others
ClientBin/
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.jfm
*.pfx
*.publishsettings
orleans.codegen.cs
# Including strong name files can present a security risk
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
#*.snk
# Since there are multiple workflows, uncomment next line to ignore bower_components
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
#bower_components/
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
ServiceFabricBackup/
*.rptproj.bak
# SQL Server files
*.mdf
*.ldf
*.ndf
# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings
*.rptproj.rsuser
*- [Bb]ackup.rdl
*- [Bb]ackup ([0-9]).rdl
*- [Bb]ackup ([0-9][0-9]).rdl
# Microsoft Fakes
FakesAssemblies/
# GhostDoc plugin setting file
*.GhostDoc.xml
# Node.js Tools for Visual Studio
.ntvs_analysis.dat
node_modules/
# Visual Studio 6 build log
*.plg
# Visual Studio 6 workspace options file
*.opt
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
*.vbw
# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
**/*.DesktopClient/ModelManifest.xml
**/*.Server/GeneratedArtifacts
**/*.Server/ModelManifest.xml
_Pvt_Extensions
# Paket dependency manager
.paket/paket.exe
paket-files/
# FAKE - F# Make
.fake/
# CodeRush personal settings
.cr/personal
# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc
# Cake - Uncomment if you are using it
# tools/**
# !tools/packages.config
# Tabs Studio
*.tss
# Telerik's JustMock configuration file
*.jmconfig
# BizTalk build output
*.btp.cs
*.btm.cs
*.odx.cs
*.xsd.cs
# OpenCover UI analysis results
OpenCover/
# Azure Stream Analytics local run output
ASALocalRun/
# MSBuild Binary and Structured Log
*.binlog
# NVidia Nsight GPU debugger configuration file
*.nvuser
# MFractors (Xamarin productivity tool) working folder
.mfractor/
# Local History for Visual Studio
.localhistory/
# BeatPulse healthcheck temp database
healthchecksdb
# Backup folder for Package Reference Convert tool in Visual Studio 2017
MigrationBackup/
# Ionide (cross platform F# VS Code tools) working folder
.ionide/
# Fody - auto-generated XML schema
FodyWeavers.xsd
CMakeLists.txt.user
CMakeCache.txt
CMakeFiles
CMakeScripts
Testing
Makefile
cmake_install.cmake
install_manifest.txt
compile_commands.json
CTestTestfile.cmake
_deps

6
projects/00/file.txt Normal file
View File

@@ -0,0 +1,6 @@
The only purpose of this file is to practice submitting files
in the Nand to Tetris course websites in Coursera.
There is no need to modify the contents of this file.
All you have to do is submit it as is, following the
Project 0 guidelines in the website.

BIN
projects/00/project0.zip Normal file

Binary file not shown.

5
projects/01/And.cmp Normal file
View File

@@ -0,0 +1,5 @@
| a | b | out |
| 0 | 0 | 0 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |

19
projects/01/And.hdl Normal file
View File

@@ -0,0 +1,19 @@
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/01/And.hdl
/**
* And gate:
* out = 1 if (a == 1 and b == 1)
* 0 otherwise
*/
CHIP And {
IN a, b;
OUT out;
PARTS:
Nand(a=a, b=b, out=nand);
Not(in=nand, out=out);
}

29
projects/01/And.tst Normal file
View File

@@ -0,0 +1,29 @@
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/01/And.tst
load And.hdl,
output-file And.out,
compare-to And.cmp,
output-list a%B3.1.3 b%B3.1.3 out%B3.1.3;
set a 0,
set b 0,
eval,
output;
set a 0,
set b 1,
eval,
output;
set a 1,
set b 0,
eval,
output;
set a 1,
set b 1,
eval,
output;

7
projects/01/And16.cmp Normal file
View File

@@ -0,0 +1,7 @@
| a | b | out |
| 0000000000000000 | 0000000000000000 | 0000000000000000 |
| 0000000000000000 | 1111111111111111 | 0000000000000000 |
| 1111111111111111 | 1111111111111111 | 1111111111111111 |
| 1010101010101010 | 0101010101010101 | 0000000000000000 |
| 0011110011000011 | 0000111111110000 | 0000110011000000 |
| 0001001000110100 | 1001100001110110 | 0001000000110100 |

32
projects/01/And16.hdl Normal file
View File

@@ -0,0 +1,32 @@
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computag Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/01/And16.hdl
/**
* 16-bit bitwise And:
* for i = 0..15: out[i] = (a[i] and b[i])
*/
CHIP And16 {
IN a[16], b[16];
OUT out[16];
PARTS:
And(a=a[0], b=b[0], out=out[0]);
And(a=a[1], b=b[1], out=out[1]);
And(a=a[2], b=b[2], out=out[2]);
And(a=a[3], b=b[3], out=out[3]);
And(a=a[4], b=b[4], out=out[4]);
And(a=a[5], b=b[5], out=out[5]);
And(a=a[6], b=b[6], out=out[6]);
And(a=a[7], b=b[7], out=out[7]);
And(a=a[8], b=b[8], out=out[8]);
And(a=a[9], b=b[9], out=out[9]);
And(a=a[10], b=b[10], out=out[10]);
And(a=a[11], b=b[11], out=out[11]);
And(a=a[12], b=b[12], out=out[12]);
And(a=a[13], b=b[13], out=out[13]);
And(a=a[14], b=b[14], out=out[14]);
And(a=a[15], b=b[15], out=out[15]);
}

39
projects/01/And16.tst Normal file
View File

@@ -0,0 +1,39 @@
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/01/And16.tst
load And16.hdl,
output-file And16.out,
compare-to And16.cmp,
output-list a%B1.16.1 b%B1.16.1 out%B1.16.1;
set a %B0000000000000000,
set b %B0000000000000000,
eval,
output;
set a %B0000000000000000,
set b %B1111111111111111,
eval,
output;
set a %B1111111111111111,
set b %B1111111111111111,
eval,
output;
set a %B1010101010101010,
set b %B0101010101010101,
eval,
output;
set a %B0011110011000011,
set b %B0000111111110000,
eval,
output;
set a %B0001001000110100,
set b %B1001100001110110,
eval,
output;

5
projects/01/DMux.cmp Normal file
View File

@@ -0,0 +1,5 @@
| in | sel | a | b |
| 0 | 0 | 0 | 0 |
| 0 | 1 | 0 | 0 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 1 |

20
projects/01/DMux.hdl Normal file
View File

@@ -0,0 +1,20 @@
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/01/DMux.hdl
/**
* Demultiplexor:
* {a, b} = {in, 0} if sel == 0
* {0, in} if sel == 1
*/
CHIP DMux {
IN in, sel;
OUT a, b;
PARTS:
Not(in=sel, out=notsel);
And(a=notsel, b=in, out=a);
And(a=sel, b=in, out=b);
}

27
projects/01/DMux.tst Normal file
View File

@@ -0,0 +1,27 @@
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/01/DMux.tst
load DMux.hdl,
output-file DMux.out,
compare-to DMux.cmp,
output-list in%B3.1.3 sel%B3.1.3 a%B3.1.3 b%B3.1.3;
set in 0,
set sel 0,
eval,
output;
set sel 1,
eval,
output;
set in 1,
set sel 0,
eval,
output;
set sel 1,
eval,
output;

9
projects/01/DMux4Way.cmp Normal file
View File

@@ -0,0 +1,9 @@
| in | sel | a | b | c | d |
| 0 | 00 | 0 | 0 | 0 | 0 |
| 0 | 01 | 0 | 0 | 0 | 0 |
| 0 | 10 | 0 | 0 | 0 | 0 |
| 0 | 11 | 0 | 0 | 0 | 0 |
| 1 | 00 | 1 | 0 | 0 | 0 |
| 1 | 01 | 0 | 1 | 0 | 0 |
| 1 | 10 | 0 | 0 | 1 | 0 |
| 1 | 11 | 0 | 0 | 0 | 1 |

31
projects/01/DMux4Way.hdl Normal file
View File

@@ -0,0 +1,31 @@
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/01/DMux4Way.hdl
/**
* 4-way demultiplexor:
* {a, b, c, d} = {in, 0, 0, 0} if sel == 00
* {0, in, 0, 0} if sel == 01
* {0, 0, in, 0} if sel == 10
* {0, 0, 0, in} if sel == 11
*/
CHIP DMux4Way {
IN in, sel[2];
OUT a, b, c, d;
PARTS:
Not(in=sel[0], out=notsel0);
Not(in=sel[1], out=notsel1);
And(a=notsel0, b=notsel1, out=shouldA);
And(a=sel[0], b=notsel1, out=shouldB);
And(a=notsel0, b=sel[1], out=shouldC);
And(a=sel[0], b=sel[1], out=shouldD);
And(a=shouldA, b=in, out=a);
And(a=shouldB, b=in, out=b);
And(a=shouldC, b=in, out=c);
And(a=shouldD, b=in, out=d);
}

43
projects/01/DMux4Way.tst Normal file
View File

@@ -0,0 +1,43 @@
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/01/DMux4Way.tst
load DMux4Way.hdl,
output-file DMux4Way.out,
compare-to DMux4Way.cmp,
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;
set in 0,
set sel %B00,
eval,
output;
set sel %B01,
eval,
output;
set sel %B10,
eval,
output;
set sel %B11,
eval,
output;
set in 1,
set sel %B00,
eval,
output;
set sel %B01,
eval,
output;
set sel %B10,
eval,
output;
set sel %B11,
eval,
output;

17
projects/01/DMux8Way.cmp Normal file
View File

@@ -0,0 +1,17 @@
| in | sel | a | b | c | d | e | f | g | h |
| 0 | 000 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 001 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 010 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 011 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 100 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 101 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 110 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 111 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 1 | 000 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 1 | 001 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 |
| 1 | 010 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 |
| 1 | 011 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 |
| 1 | 100 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 |
| 1 | 101 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 |
| 1 | 110 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 |
| 1 | 111 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 |

32
projects/01/DMux8Way.hdl Normal file
View File

@@ -0,0 +1,32 @@
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/01/DMux8Way.hdl
/**
* 8-way demultiplexor:
* {a, b, c, d, e, f, g, h} = {in, 0, 0, 0, 0, 0, 0, 0} if sel == 000
* {0, in, 0, 0, 0, 0, 0, 0} if sel == 001
* etc.
* {0, 0, 0, 0, 0, 0, 0, in} if sel == 111
*/
CHIP DMux8Way {
IN in, sel[3];
OUT a, b, c, d, e, f, g, h;
PARTS:
DMux4Way(in=in, sel=sel[0..1], a=pa, b=pb, c=pc, d=pd);
DMux4Way(in=in, sel=sel[0..1], a=pe, b=pf, c=pg, d=ph);
Not(in=sel[2], out=notsel2);
And(a=pa, b=notsel2, out=a);
And(a=pb, b=notsel2, out=b);
And(a=pc, b=notsel2, out=c);
And(a=pd, b=notsel2, out=d);
And(a=pe, b=sel[2], out=e);
And(a=pf, b=sel[2], out=f);
And(a=pg, b=sel[2], out=g);
And(a=ph, b=sel[2], out=h);
}

75
projects/01/DMux8Way.tst Normal file
View File

@@ -0,0 +1,75 @@
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/01/DMux8Way.tst
load DMux8Way.hdl,
output-file DMux8Way.out,
compare-to DMux8Way.cmp,
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;
set in 0,
set sel %B000,
eval,
output;
set sel %B001,
eval,
output;
set sel %B010,
eval,
output;
set sel %B011,
eval,
output;
set sel %B100,
eval,
output;
set sel %B101,
eval,
output;
set sel %B110,
eval,
output;
set sel %B111,
eval,
output;
set in 1,
set sel %B000,
eval,
output;
set sel %B001,
eval,
output;
set sel %B010,
eval,
output;
set sel %B011,
eval,
output;
set sel %B100,
eval,
output;
set sel %B101,
eval,
output;
set sel %B110,
eval,
output;
set sel %B111,
eval,
output;

9
projects/01/Mux.cmp Normal file
View File

@@ -0,0 +1,9 @@
| a | b | sel | out |
| 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 0 |
| 0 | 1 | 0 | 0 |
| 0 | 1 | 1 | 1 |
| 1 | 0 | 0 | 1 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 1 |
| 1 | 1 | 1 | 1 |

21
projects/01/Mux.hdl Normal file
View File

@@ -0,0 +1,21 @@
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/01/Mux.hdl
/**
* Multiplexor:
* out = a if sel == 0
* b otherwise
*/
CHIP Mux {
IN a, b, sel;
OUT out;
PARTS:
Not(in=sel, out=notsel);
And(a=b, b=sel, out=selb);
And(a=a, b=notsel, out=sela);
Or(a=selb, b=sela, out=out);
}

49
projects/01/Mux.tst Normal file
View File

@@ -0,0 +1,49 @@
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/01/Mux.tst
load Mux.hdl,
output-file Mux.out,
compare-to Mux.cmp,
output-list a%B3.1.3 b%B3.1.3 sel%B3.1.3 out%B3.1.3;
set a 0,
set b 0,
set sel 0,
eval,
output;
set sel 1,
eval,
output;
set a 0,
set b 1,
set sel 0,
eval,
output;
set sel 1,
eval,
output;
set a 1,
set b 0,
set sel 0,
eval,
output;
set sel 1,
eval,
output;
set a 1,
set b 1,
set sel 0,
eval,
output;
set sel 1,
eval,
output;

9
projects/01/Mux16.cmp Normal file
View File

@@ -0,0 +1,9 @@
| a | b | sel | out |
| 0000000000000000 | 0000000000000000 | 0 | 0000000000000000 |
| 0000000000000000 | 0000000000000000 | 1 | 0000000000000000 |
| 0000000000000000 | 0001001000110100 | 0 | 0000000000000000 |
| 0000000000000000 | 0001001000110100 | 1 | 0001001000110100 |
| 1001100001110110 | 0000000000000000 | 0 | 1001100001110110 |
| 1001100001110110 | 0000000000000000 | 1 | 0000000000000000 |
| 1010101010101010 | 0101010101010101 | 0 | 1010101010101010 |
| 1010101010101010 | 0101010101010101 | 1 | 0101010101010101 |

33
projects/01/Mux16.hdl Normal file
View File

@@ -0,0 +1,33 @@
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/01/Mux16.hdl
/**
* 16-bit multiplexor:
* for i = 0..15 out[i] = a[i] if sel == 0
* b[i] if sel == 1
*/
CHIP Mux16 {
IN a[16], b[16], sel;
OUT out[16];
PARTS:
Mux(sel=sel, a=a[0], b=b[0], out=out[0]);
Mux(sel=sel, a=a[1], b=b[1], out=out[1]);
Mux(sel=sel, a=a[2], b=b[2], out=out[2]);
Mux(sel=sel, a=a[3], b=b[3], out=out[3]);
Mux(sel=sel, a=a[4], b=b[4], out=out[4]);
Mux(sel=sel, a=a[5], b=b[5], out=out[5]);
Mux(sel=sel, a=a[6], b=b[6], out=out[6]);
Mux(sel=sel, a=a[7], b=b[7], out=out[7]);
Mux(sel=sel, a=a[8], b=b[8], out=out[8]);
Mux(sel=sel, a=a[9], b=b[9], out=out[9]);
Mux(sel=sel, a=a[10], b=b[10], out=out[10]);
Mux(sel=sel, a=a[11], b=b[11], out=out[11]);
Mux(sel=sel, a=a[12], b=b[12], out=out[12]);
Mux(sel=sel, a=a[13], b=b[13], out=out[13]);
Mux(sel=sel, a=a[14], b=b[14], out=out[14]);
Mux(sel=sel, a=a[15], b=b[15], out=out[15]);
}

49
projects/01/Mux16.tst Normal file
View File

@@ -0,0 +1,49 @@
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/01/Mux16.tst
load Mux16.hdl,
output-file Mux16.out,
compare-to Mux16.cmp,
output-list a%B1.16.1 b%B1.16.1 sel%D2.1.2 out%B1.16.1;
set a 0,
set b 0,
set sel 0,
eval,
output;
set sel 1,
eval,
output;
set a %B0000000000000000,
set b %B0001001000110100,
set sel 0,
eval,
output;
set sel 1,
eval,
output;
set a %B1001100001110110,
set b %B0000000000000000,
set sel 0,
eval,
output;
set sel 1,
eval,
output;
set a %B1010101010101010,
set b %B0101010101010101,
set sel 0,
eval,
output;
set sel 1,
eval,
output;

View File

@@ -0,0 +1,9 @@
| a | b | c | d | sel | out |
| 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 00 | 0000000000000000 |
| 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 01 | 0000000000000000 |
| 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 10 | 0000000000000000 |
| 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 11 | 0000000000000000 |
| 0001001000110100 | 1001100001110110 | 1010101010101010 | 0101010101010101 | 00 | 0001001000110100 |
| 0001001000110100 | 1001100001110110 | 1010101010101010 | 0101010101010101 | 01 | 1001100001110110 |
| 0001001000110100 | 1001100001110110 | 1010101010101010 | 0101010101010101 | 10 | 1010101010101010 |
| 0001001000110100 | 1001100001110110 | 1010101010101010 | 0101010101010101 | 11 | 0101010101010101 |

32
projects/01/Mux4Way16.hdl Normal file
View File

@@ -0,0 +1,32 @@
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/01/Mux4Way16.hdl
/**
* 4-way 16-bit multiplexor:
* out = a if sel == 00
* b if sel == 01
* c if sel == 10
* d if sel == 11
*/
CHIP Mux4Way16 {
IN a[16], b[16], c[16], d[16], sel[2];
OUT out[16];
PARTS:
Nand(a=sel[0], b=sel[1], out=shouldAorBorC);
And(a=sel[0], b=sel[1], out=shouldD);
Xor(a=sel[0], b=sel[1], out=shouldBorC);
And(a=shouldBorC, b=sel[0], out=shouldB);
And(a=shouldBorC, b=sel[1], out=shouldC);
Nand(a=shouldAorBorC, b=shouldBorC, out=shouldA);
Mux16(a=c, b=b, sel=shouldB, out=BorC);
Mux16(a=a, b=d, sel=shouldD, out=DorA);
Mux16(a=DorA, b=BorC, sel=shouldBorC, out=out);
}

49
projects/01/Mux4Way16.tst Normal file
View File

@@ -0,0 +1,49 @@
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/01/Mux4Way16.tst
load Mux4Way16.hdl,
output-file Mux4Way16.out,
compare-to Mux4Way16.cmp,
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;
set a 0,
set b 0,
set c 0,
set d 0,
set sel 0,
eval,
output;
set sel 1,
eval,
output;
set sel 2,
eval,
output;
set sel 3,
eval,
output;
set a %B0001001000110100,
set b %B1001100001110110,
set c %B1010101010101010,
set d %B0101010101010101,
set sel 0,
eval,
output;
set sel 1,
eval,
output;
set sel 2,
eval,
output;
set sel 3,
eval,
output;

17
projects/01/Mux8Way16.cmp Normal file
View File

@@ -0,0 +1,17 @@
| a | b | c | d | e | f | g | h | sel | out |
| 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 000 | 0000000000000000 |
| 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 001 | 0000000000000000 |
| 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 010 | 0000000000000000 |
| 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 011 | 0000000000000000 |
| 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 100 | 0000000000000000 |
| 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 101 | 0000000000000000 |
| 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 110 | 0000000000000000 |
| 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 111 | 0000000000000000 |
| 0001001000110100 | 0010001101000101 | 0011010001010110 | 0100010101100111 | 0101011001111000 | 0110011110001001 | 0111100010011010 | 1000100110101011 | 000 | 0001001000110100 |
| 0001001000110100 | 0010001101000101 | 0011010001010110 | 0100010101100111 | 0101011001111000 | 0110011110001001 | 0111100010011010 | 1000100110101011 | 001 | 0010001101000101 |
| 0001001000110100 | 0010001101000101 | 0011010001010110 | 0100010101100111 | 0101011001111000 | 0110011110001001 | 0111100010011010 | 1000100110101011 | 010 | 0011010001010110 |
| 0001001000110100 | 0010001101000101 | 0011010001010110 | 0100010101100111 | 0101011001111000 | 0110011110001001 | 0111100010011010 | 1000100110101011 | 011 | 0100010101100111 |
| 0001001000110100 | 0010001101000101 | 0011010001010110 | 0100010101100111 | 0101011001111000 | 0110011110001001 | 0111100010011010 | 1000100110101011 | 100 | 0101011001111000 |
| 0001001000110100 | 0010001101000101 | 0011010001010110 | 0100010101100111 | 0101011001111000 | 0110011110001001 | 0111100010011010 | 1000100110101011 | 101 | 0110011110001001 |
| 0001001000110100 | 0010001101000101 | 0011010001010110 | 0100010101100111 | 0101011001111000 | 0110011110001001 | 0111100010011010 | 1000100110101011 | 110 | 0111100010011010 |
| 0001001000110100 | 0010001101000101 | 0011010001010110 | 0100010101100111 | 0101011001111000 | 0110011110001001 | 0111100010011010 | 1000100110101011 | 111 | 1000100110101011 |

30
projects/01/Mux8Way16.hdl Normal file
View File

@@ -0,0 +1,30 @@
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/01/Mux8Way16.hdl
/**
* 8-way 16-bit multiplexor:
* out = a == 000
* b == 001
* c == 010
d == 011
e == 100
f == 101
g == 110
* h == 111
*/
CHIP Mux8Way16 {
IN a[16], b[16], c[16], d[16],
e[16], f[16], g[16], h[16],
sel[3];
OUT out[16];
PARTS:
Mux4Way16(a=a, b=b, c=c, d=d, sel=sel[0..1], out=ABCD);
Mux4Way16(a=e, b=f, c=g, d=h, sel=sel[0..1], out=EFGH);
Mux16(a=ABCD, b=EFGH, sel=sel[2], out=out);
}

89
projects/01/Mux8Way16.tst Normal file
View File

@@ -0,0 +1,89 @@
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/01/Mux8Way16.tst
load Mux8Way16.hdl,
output-file Mux8Way16.out,
compare-to Mux8Way16.cmp,
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;
set a 0,
set b 0,
set c 0,
set d 0,
set e 0,
set f 0,
set g 0,
set h 0,
set sel 0,
eval,
output;
set sel 1,
eval,
output;
set sel 2,
eval,
output;
set sel 3,
eval,
output;
set sel 4,
eval,
output;
set sel 5,
eval,
output;
set sel 6,
eval,
output;
set sel 7,
eval,
output;
set a %B0001001000110100,
set b %B0010001101000101,
set c %B0011010001010110,
set d %B0100010101100111,
set e %B0101011001111000,
set f %B0110011110001001,
set g %B0111100010011010,
set h %B1000100110101011,
set sel 0,
eval,
output;
set sel 1,
eval,
output;
set sel 2,
eval,
output;
set sel 3,
eval,
output;
set sel 4,
eval,
output;
set sel 5,
eval,
output;
set sel 6,
eval,
output;
set sel 7,
eval,
output;

3
projects/01/Not.cmp Normal file
View File

@@ -0,0 +1,3 @@
| in | out |
| 0 | 1 |
| 1 | 0 |

17
projects/01/Not.hdl Normal file
View File

@@ -0,0 +1,17 @@
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/01/Not.hdl
/**
* Not gate:
* out = not in
*/
CHIP Not {
IN in;
OUT out;
PARTS:
Nand(a=in, b=in, out=out);
}

17
projects/01/Not.tst Normal file
View File

@@ -0,0 +1,17 @@
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/01/Not.tst
load Not.hdl,
output-file Not.out,
compare-to Not.cmp,
output-list in%B3.1.3 out%B3.1.3;
set in 0,
eval,
output;
set in 1,
eval,
output;

6
projects/01/Not16.cmp Normal file
View File

@@ -0,0 +1,6 @@
| in | out |
| 0000000000000000 | 1111111111111111 |
| 1111111111111111 | 0000000000000000 |
| 1010101010101010 | 0101010101010101 |
| 0011110011000011 | 1100001100111100 |
| 0001001000110100 | 1110110111001011 |

32
projects/01/Not16.hdl Normal file
View File

@@ -0,0 +1,32 @@
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/01/Not16.hdl
/**
* 16-bit Not:
* for i=0..15: out[i] = not in[i]
*/
CHIP Not16 {
IN in[16];
OUT out[16];
PARTS:
Not(in=in[0], out=out[0]);
Not(in=in[1], out=out[1]);
Not(in=in[2], out=out[2]);
Not(in=in[3], out=out[3]);
Not(in=in[4], out=out[4]);
Not(in=in[5], out=out[5]);
Not(in=in[6], out=out[6]);
Not(in=in[7], out=out[7]);
Not(in=in[8], out=out[8]);
Not(in=in[9], out=out[9]);
Not(in=in[10], out=out[10]);
Not(in=in[11], out=out[11]);
Not(in=in[12], out=out[12]);
Not(in=in[13], out=out[13]);
Not(in=in[14], out=out[14]);
Not(in=in[15], out=out[15]);
}

29
projects/01/Not16.tst Normal file
View File

@@ -0,0 +1,29 @@
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/01/Not16.tst
load Not16.hdl,
output-file Not16.out,
compare-to Not16.cmp,
output-list in%B1.16.1 out%B1.16.1;
set in %B0000000000000000,
eval,
output;
set in %B1111111111111111,
eval,
output;
set in %B1010101010101010,
eval,
output;
set in %B0011110011000011,
eval,
output;
set in %B0001001000110100,
eval,
output;

5
projects/01/Or.cmp Normal file
View File

@@ -0,0 +1,5 @@
| a | b | out |
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 1 |

20
projects/01/Or.hdl Normal file
View File

@@ -0,0 +1,20 @@
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/01/Or.hdl
/**
* Or gate:
* out = 1 if (a == 1 or b == 1)
* 0 otherwise
*/
CHIP Or {
IN a, b;
OUT out;
PARTS:
Not(in=a, out=nota);
Not(in=b, out=notb);
Nand(a=nota, b=notb, out=out);
}

29
projects/01/Or.tst Normal file
View File

@@ -0,0 +1,29 @@
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/01/Or.tst
load Or.hdl,
output-file Or.out,
compare-to Or.cmp,
output-list a%B3.1.3 b%B3.1.3 out%B3.1.3;
set a 0,
set b 0,
eval,
output;
set a 0,
set b 1,
eval,
output;
set a 1,
set b 0,
eval,
output;
set a 1,
set b 1,
eval,
output;

7
projects/01/Or16.cmp Normal file
View File

@@ -0,0 +1,7 @@
| a | b | out |
| 0000000000000000 | 0000000000000000 | 0000000000000000 |
| 0000000000000000 | 1111111111111111 | 1111111111111111 |
| 1111111111111111 | 1111111111111111 | 1111111111111111 |
| 1010101010101010 | 0101010101010101 | 1111111111111111 |
| 0011110011000011 | 0000111111110000 | 0011111111110011 |
| 0001001000110100 | 1001100001110110 | 1001101001110110 |

32
projects/01/Or16.hdl Normal file
View File

@@ -0,0 +1,32 @@
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/01/Or16.hdl
/**
* 16-bit bitwise Or:
* for i = 0..15 out[i] = (a[i] or b[i])
*/
CHIP Or16 {
IN a[16], b[16];
OUT out[16];
PARTS:
Or(a=a[0], b=b[0], out=out[0]);
Or(a=a[1], b=b[1], out=out[1]);
Or(a=a[2], b=b[2], out=out[2]);
Or(a=a[3], b=b[3], out=out[3]);
Or(a=a[4], b=b[4], out=out[4]);
Or(a=a[5], b=b[5], out=out[5]);
Or(a=a[6], b=b[6], out=out[6]);
Or(a=a[7], b=b[7], out=out[7]);
Or(a=a[8], b=b[8], out=out[8]);
Or(a=a[9], b=b[9], out=out[9]);
Or(a=a[10], b=b[10], out=out[10]);
Or(a=a[11], b=b[11], out=out[11]);
Or(a=a[12], b=b[12], out=out[12]);
Or(a=a[13], b=b[13], out=out[13]);
Or(a=a[14], b=b[14], out=out[14]);
Or(a=a[15], b=b[15], out=out[15]);
}

39
projects/01/Or16.tst Normal file
View File

@@ -0,0 +1,39 @@
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/01/Or16.tst
load Or16.hdl,
output-file Or16.out,
compare-to Or16.cmp,
output-list a%B1.16.1 b%B1.16.1 out%B1.16.1;
set a %B0000000000000000,
set b %B0000000000000000,
eval,
output;
set a %B0000000000000000,
set b %B1111111111111111,
eval,
output;
set a %B1111111111111111,
set b %B1111111111111111,
eval,
output;
set a %B1010101010101010,
set b %B0101010101010101,
eval,
output;
set a %B0011110011000011,
set b %B0000111111110000,
eval,
output;
set a %B0001001000110100,
set b %B1001100001110110,
eval,
output;

6
projects/01/Or8Way.cmp Normal file
View File

@@ -0,0 +1,6 @@
| in | out |
| 00000000 | 0 |
| 11111111 | 1 |
| 00010000 | 1 |
| 00000001 | 1 |
| 00100110 | 1 |

23
projects/01/Or8Way.hdl Normal file
View File

@@ -0,0 +1,23 @@
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/01/Or8Way.hdl
/**
* 8-way Or:
* out = (in[0] or in[1] or ... or in[7])
*/
CHIP Or8Way {
IN in[8];
OUT out;
PARTS:
Or(a=in[0], b=in[1], out=or1);
Or(a=or1, b=in[2], out=or2);
Or(a=or2, b=in[3], out=or3);
Or(a=or3, b=in[4], out=or4);
Or(a=or4, b=in[5], out=or5);
Or(a=or5, b=in[6], out=or6);
Or(a=or6, b=in[7], out=out);
}

29
projects/01/Or8Way.tst Normal file
View File

@@ -0,0 +1,29 @@
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/01/Or8Way.tst
load Or8Way.hdl,
output-file Or8Way.out,
compare-to Or8Way.cmp,
output-list in%B2.8.2 out%B2.1.2;
set in %B00000000,
eval,
output;
set in %B11111111,
eval,
output;
set in %B00010000,
eval,
output;
set in %B00000001,
eval,
output;
set in %B00100110,
eval,
output;

5
projects/01/Xor.cmp Normal file
View File

@@ -0,0 +1,5 @@
| a | b | out |
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |

19
projects/01/Xor.hdl Normal file
View File

@@ -0,0 +1,19 @@
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/01/Xor.hdl
/**
* Exclusive-or gate:
* out = not (a == b)
*/
CHIP Xor {
IN a, b;
OUT out;
PARTS:
Nand(a=a, b=b, out=aisb);
Or(a=a, b=b, out=aorb);
And(a=aisb, b=aorb, out=out);
}

29
projects/01/Xor.tst Normal file
View File

@@ -0,0 +1,29 @@
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/01/Xor.tst
load Xor.hdl,
output-file Xor.out,
compare-to Xor.cmp,
output-list a%B3.1.3 b%B3.1.3 out%B3.1.3;
set a 0,
set b 0,
eval,
output;
set a 0,
set b 1,
eval,
output;
set a 1,
set b 0,
eval,
output;
set a 1,
set b 1,
eval,
output;

BIN
projects/01/project1.zip Normal file

Binary file not shown.

BIN
projects/02/02.zip Normal file

Binary file not shown.

View File

@@ -0,0 +1,37 @@
| x | y |zx |nx |zy |ny | f |no | out |
| 0000000000000000 | 1111111111111111 | 1 | 0 | 1 | 0 | 1 | 0 | 0000000000000000 |
| 0000000000000000 | 1111111111111111 | 1 | 1 | 1 | 1 | 1 | 1 | 0000000000000001 |
| 0000000000000000 | 1111111111111111 | 1 | 1 | 1 | 0 | 1 | 0 | 1111111111111111 |
| 0000000000000000 | 1111111111111111 | 0 | 0 | 1 | 1 | 0 | 0 | 0000000000000000 |
| 0000000000000000 | 1111111111111111 | 1 | 1 | 0 | 0 | 0 | 0 | 1111111111111111 |
| 0000000000000000 | 1111111111111111 | 0 | 0 | 1 | 1 | 0 | 1 | 1111111111111111 |
| 0000000000000000 | 1111111111111111 | 1 | 1 | 0 | 0 | 0 | 1 | 0000000000000000 |
| 0000000000000000 | 1111111111111111 | 0 | 0 | 1 | 1 | 1 | 1 | 0000000000000000 |
| 0000000000000000 | 1111111111111111 | 1 | 1 | 0 | 0 | 1 | 1 | 0000000000000001 |
| 0000000000000000 | 1111111111111111 | 0 | 1 | 1 | 1 | 1 | 1 | 0000000000000001 |
| 0000000000000000 | 1111111111111111 | 1 | 1 | 0 | 1 | 1 | 1 | 0000000000000000 |
| 0000000000000000 | 1111111111111111 | 0 | 0 | 1 | 1 | 1 | 0 | 1111111111111111 |
| 0000000000000000 | 1111111111111111 | 1 | 1 | 0 | 0 | 1 | 0 | 1111111111111110 |
| 0000000000000000 | 1111111111111111 | 0 | 0 | 0 | 0 | 1 | 0 | 1111111111111111 |
| 0000000000000000 | 1111111111111111 | 0 | 1 | 0 | 0 | 1 | 1 | 0000000000000001 |
| 0000000000000000 | 1111111111111111 | 0 | 0 | 0 | 1 | 1 | 1 | 1111111111111111 |
| 0000000000000000 | 1111111111111111 | 0 | 0 | 0 | 0 | 0 | 0 | 0000000000000000 |
| 0000000000000000 | 1111111111111111 | 0 | 1 | 0 | 1 | 0 | 1 | 1111111111111111 |
| 0101101110100000 | 0001111011010010 | 1 | 0 | 1 | 0 | 1 | 0 | 0000000000000000 |
| 0101101110100000 | 0001111011010010 | 1 | 1 | 1 | 1 | 1 | 1 | 0000000000000001 |
| 0101101110100000 | 0001111011010010 | 1 | 1 | 1 | 0 | 1 | 0 | 1111111111111111 |
| 0101101110100000 | 0001111011010010 | 0 | 0 | 1 | 1 | 0 | 0 | 0101101110100000 |
| 0101101110100000 | 0001111011010010 | 1 | 1 | 0 | 0 | 0 | 0 | 0001111011010010 |
| 0101101110100000 | 0001111011010010 | 0 | 0 | 1 | 1 | 0 | 1 | 1010010001011111 |
| 0101101110100000 | 0001111011010010 | 1 | 1 | 0 | 0 | 0 | 1 | 1110000100101101 |
| 0101101110100000 | 0001111011010010 | 0 | 0 | 1 | 1 | 1 | 1 | 1010010001100000 |
| 0101101110100000 | 0001111011010010 | 1 | 1 | 0 | 0 | 1 | 1 | 1110000100101110 |
| 0101101110100000 | 0001111011010010 | 0 | 1 | 1 | 1 | 1 | 1 | 0101101110100001 |
| 0101101110100000 | 0001111011010010 | 1 | 1 | 0 | 1 | 1 | 1 | 0001111011010011 |
| 0101101110100000 | 0001111011010010 | 0 | 0 | 1 | 1 | 1 | 0 | 0101101110011111 |
| 0101101110100000 | 0001111011010010 | 1 | 1 | 0 | 0 | 1 | 0 | 0001111011010001 |
| 0101101110100000 | 0001111011010010 | 0 | 0 | 0 | 0 | 1 | 0 | 0111101001110010 |
| 0101101110100000 | 0001111011010010 | 0 | 1 | 0 | 0 | 1 | 1 | 0011110011001110 |
| 0101101110100000 | 0001111011010010 | 0 | 0 | 0 | 1 | 1 | 1 | 1100001100110010 |
| 0101101110100000 | 0001111011010010 | 0 | 0 | 0 | 0 | 0 | 0 | 0001101010000000 |
| 0101101110100000 | 0001111011010010 | 0 | 1 | 0 | 1 | 0 | 1 | 0101111111110010 |

353
projects/02/ALU-nostat.tst Normal file
View File

@@ -0,0 +1,353 @@
// This file is part of the materials accompanying the book
// "The Elements of Computing Systems" by Nisan and Schocken,
// MIT Press. Book site: www.idc.ac.il/tecs
// File name: projects/02/ALU-nostat.tst
// ALU-nostat.tst provides a partial test of the ALU chip.
// It IS NOT a replacement for ALU.tst.
// ALU-nostat.tst tests only the computation part of the ALU.
// The 'zr' and 'ng' status outputs are ignored.
// This test lets you concentrate on getting the ALU computation right without the
// additional task of handling the status outputs.
// Once your ALU passes ALU-nostat.tst you need to test it with ALU.tst.
// This way, any comparison failures during ALU.tst will be caused by errors in
// the handling of the 'zr' and 'ng' status outputs.
load ALU.hdl,
output-file ALU-nostat.out,
compare-to ALU-nostat.cmp,
output-list x%B1.16.1 y%B1.16.1 zx%B1.1.1 nx%B1.1.1 zy%B1.1.1
ny%B1.1.1 f%B1.1.1 no%B1.1.1 out%B1.16.1;
set x %B0000000000000000,
set y %B1111111111111111,
set zx 1,
set nx 0,
set zy 1,
set ny 0,
set f 1,
set no 0,
eval,
output;
set zx 1,
set nx 1,
set zy 1,
set ny 1,
set f 1,
set no 1,
eval,
output;
set zx 1,
set nx 1,
set zy 1,
set ny 0,
set f 1,
set no 0,
eval,
output;
set zx 0,
set nx 0,
set zy 1,
set ny 1,
set f 0,
set no 0,
eval,
output;
set zx 1,
set nx 1,
set zy 0,
set ny 0,
set f 0,
set no 0,
eval,
output;
set zx 0,
set nx 0,
set zy 1,
set ny 1,
set f 0,
set no 1,
eval,
output;
set zx 1,
set nx 1,
set zy 0,
set ny 0,
set f 0,
set no 1,
eval,
output;
set zx 0,
set nx 0,
set zy 1,
set ny 1,
set f 1,
set no 1,
eval,
output;
set zx 1,
set nx 1,
set zy 0,
set ny 0,
set f 1,
set no 1,
eval,
output;
set zx 0,
set nx 1,
set zy 1,
set ny 1,
set f 1,
set no 1,
eval,
output;
set zx 1,
set nx 1,
set zy 0,
set ny 1,
set f 1,
set no 1,
eval,
output;
set zx 0,
set nx 0,
set zy 1,
set ny 1,
set f 1,
set no 0,
eval,
output;
set zx 1,
set nx 1,
set zy 0,
set ny 0,
set f 1,
set no 0,
eval,
output;
set zx 0,
set nx 0,
set zy 0,
set ny 0,
set f 1,
set no 0,
eval,
output;
set zx 0,
set nx 1,
set zy 0,
set ny 0,
set f 1,
set no 1,
eval,
output;
set zx 0,
set nx 0,
set zy 0,
set ny 1,
set f 1,
set no 1,
eval,
output;
set zx 0,
set nx 0,
set zy 0,
set ny 0,
set f 0,
set no 0,
eval,
output;
set zx 0,
set nx 1,
set zy 0,
set ny 1,
set f 0,
set no 1,
eval,
output;
set x %B101101110100000,
set y %B001111011010010,
set zx 1,
set nx 0,
set zy 1,
set ny 0,
set f 1,
set no 0,
eval,
output;
set zx 1,
set nx 1,
set zy 1,
set ny 1,
set f 1,
set no 1,
eval,
output;
set zx 1,
set nx 1,
set zy 1,
set ny 0,
set f 1,
set no 0,
eval,
output;
set zx 0,
set nx 0,
set zy 1,
set ny 1,
set f 0,
set no 0,
eval,
output;
set zx 1,
set nx 1,
set zy 0,
set ny 0,
set f 0,
set no 0,
eval,
output;
set zx 0,
set nx 0,
set zy 1,
set ny 1,
set f 0,
set no 1,
eval,
output;
set zx 1,
set nx 1,
set zy 0,
set ny 0,
set f 0,
set no 1,
eval,
output;
set zx 0,
set nx 0,
set zy 1,
set ny 1,
set f 1,
set no 1,
eval,
output;
set zx 1,
set nx 1,
set zy 0,
set ny 0,
set f 1,
set no 1,
eval,
output;
set zx 0,
set nx 1,
set zy 1,
set ny 1,
set f 1,
set no 1,
eval,
output;
set zx 1,
set nx 1,
set zy 0,
set ny 1,
set f 1,
set no 1,
eval,
output;
set zx 0,
set nx 0,
set zy 1,
set ny 1,
set f 1,
set no 0,
eval,
output;
set zx 1,
set nx 1,
set zy 0,
set ny 0,
set f 1,
set no 0,
eval,
output;
set zx 0,
set nx 0,
set zy 0,
set ny 0,
set f 1,
set no 0,
eval,
output;
set zx 0,
set nx 1,
set zy 0,
set ny 0,
set f 1,
set no 1,
eval,
output;
set zx 0,
set nx 0,
set zy 0,
set ny 1,
set f 1,
set no 1,
eval,
output;
set zx 0,
set nx 0,
set zy 0,
set ny 0,
set f 0,
set no 0,
eval,
output;
set zx 0,
set nx 1,
set zy 0,
set ny 1,
set f 0,
set no 1,
eval,
output;

37
projects/02/ALU.cmp Normal file
View File

@@ -0,0 +1,37 @@
| x | y |zx |nx |zy |ny | f |no | out |zr |ng |
| 0000000000000000 | 1111111111111111 | 1 | 0 | 1 | 0 | 1 | 0 | 0000000000000000 | 1 | 0 |
| 0000000000000000 | 1111111111111111 | 1 | 1 | 1 | 1 | 1 | 1 | 0000000000000001 | 0 | 0 |
| 0000000000000000 | 1111111111111111 | 1 | 1 | 1 | 0 | 1 | 0 | 1111111111111111 | 0 | 1 |
| 0000000000000000 | 1111111111111111 | 0 | 0 | 1 | 1 | 0 | 0 | 0000000000000000 | 1 | 0 |
| 0000000000000000 | 1111111111111111 | 1 | 1 | 0 | 0 | 0 | 0 | 1111111111111111 | 0 | 1 |
| 0000000000000000 | 1111111111111111 | 0 | 0 | 1 | 1 | 0 | 1 | 1111111111111111 | 0 | 1 |
| 0000000000000000 | 1111111111111111 | 1 | 1 | 0 | 0 | 0 | 1 | 0000000000000000 | 1 | 0 |
| 0000000000000000 | 1111111111111111 | 0 | 0 | 1 | 1 | 1 | 1 | 0000000000000000 | 1 | 0 |
| 0000000000000000 | 1111111111111111 | 1 | 1 | 0 | 0 | 1 | 1 | 0000000000000001 | 0 | 0 |
| 0000000000000000 | 1111111111111111 | 0 | 1 | 1 | 1 | 1 | 1 | 0000000000000001 | 0 | 0 |
| 0000000000000000 | 1111111111111111 | 1 | 1 | 0 | 1 | 1 | 1 | 0000000000000000 | 1 | 0 |
| 0000000000000000 | 1111111111111111 | 0 | 0 | 1 | 1 | 1 | 0 | 1111111111111111 | 0 | 1 |
| 0000000000000000 | 1111111111111111 | 1 | 1 | 0 | 0 | 1 | 0 | 1111111111111110 | 0 | 1 |
| 0000000000000000 | 1111111111111111 | 0 | 0 | 0 | 0 | 1 | 0 | 1111111111111111 | 0 | 1 |
| 0000000000000000 | 1111111111111111 | 0 | 1 | 0 | 0 | 1 | 1 | 0000000000000001 | 0 | 0 |
| 0000000000000000 | 1111111111111111 | 0 | 0 | 0 | 1 | 1 | 1 | 1111111111111111 | 0 | 1 |
| 0000000000000000 | 1111111111111111 | 0 | 0 | 0 | 0 | 0 | 0 | 0000000000000000 | 1 | 0 |
| 0000000000000000 | 1111111111111111 | 0 | 1 | 0 | 1 | 0 | 1 | 1111111111111111 | 0 | 1 |
| 0000000000010001 | 0000000000000011 | 1 | 0 | 1 | 0 | 1 | 0 | 0000000000000000 | 1 | 0 |
| 0000000000010001 | 0000000000000011 | 1 | 1 | 1 | 1 | 1 | 1 | 0000000000000001 | 0 | 0 |
| 0000000000010001 | 0000000000000011 | 1 | 1 | 1 | 0 | 1 | 0 | 1111111111111111 | 0 | 1 |
| 0000000000010001 | 0000000000000011 | 0 | 0 | 1 | 1 | 0 | 0 | 0000000000010001 | 0 | 0 |
| 0000000000010001 | 0000000000000011 | 1 | 1 | 0 | 0 | 0 | 0 | 0000000000000011 | 0 | 0 |
| 0000000000010001 | 0000000000000011 | 0 | 0 | 1 | 1 | 0 | 1 | 1111111111101110 | 0 | 1 |
| 0000000000010001 | 0000000000000011 | 1 | 1 | 0 | 0 | 0 | 1 | 1111111111111100 | 0 | 1 |
| 0000000000010001 | 0000000000000011 | 0 | 0 | 1 | 1 | 1 | 1 | 1111111111101111 | 0 | 1 |
| 0000000000010001 | 0000000000000011 | 1 | 1 | 0 | 0 | 1 | 1 | 1111111111111101 | 0 | 1 |
| 0000000000010001 | 0000000000000011 | 0 | 1 | 1 | 1 | 1 | 1 | 0000000000010010 | 0 | 0 |
| 0000000000010001 | 0000000000000011 | 1 | 1 | 0 | 1 | 1 | 1 | 0000000000000100 | 0 | 0 |
| 0000000000010001 | 0000000000000011 | 0 | 0 | 1 | 1 | 1 | 0 | 0000000000010000 | 0 | 0 |
| 0000000000010001 | 0000000000000011 | 1 | 1 | 0 | 0 | 1 | 0 | 0000000000000010 | 0 | 0 |
| 0000000000010001 | 0000000000000011 | 0 | 0 | 0 | 0 | 1 | 0 | 0000000000010100 | 0 | 0 |
| 0000000000010001 | 0000000000000011 | 0 | 1 | 0 | 0 | 1 | 1 | 0000000000001110 | 0 | 0 |
| 0000000000010001 | 0000000000000011 | 0 | 0 | 0 | 1 | 1 | 1 | 1111111111110010 | 0 | 1 |
| 0000000000010001 | 0000000000000011 | 0 | 0 | 0 | 0 | 0 | 0 | 0000000000000001 | 0 | 0 |
| 0000000000010001 | 0000000000000011 | 0 | 1 | 0 | 1 | 0 | 1 | 0000000000010011 | 0 | 0 |

66
projects/02/ALU.hdl Normal file
View File

@@ -0,0 +1,66 @@
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/02/ALU.hdl
/**
* The ALU (Arithmetic Logic Unit).
* Computes one of the following functions:
* x+y, x-y, y-x, 0, 1, -1, x, y, -x, -y, !x, !y,
* x+1, y+1, x-1, y-1, x&y, x|y on two 16-bit inputs,
* according to 6 input bits denoted zx,nx,zy,ny,f,no.
* In addition, the ALU computes two 1-bit outputs:
* if the ALU output == 0, zr is set to 1; otherwise zr is set to 0;
* if the ALU output < 0, ng is set to 1; otherwise ng is set to 0.
*/
// Implementation: the ALU logic manipulates the x and y inputs
// and operates on the resulting values, as follows:
// if (zx == 1) set x = 0 // 16-bit constant
// if (nx == 1) set x = !x // bitwise not
// if (zy == 1) set y = 0 // 16-bit constant
// if (ny == 1) set y = !y // bitwise not
// if (f == 1) set out = x + y // integer 2's complement addition
// if (f == 0) set out = x & y // bitwise and
// if (no == 1) set out = !out // bitwise not
// if (out == 0) set zr = 1
// if (out < 0) set ng = 1
CHIP ALU {
IN
x[16], y[16], // 16-bit inputs
zx, // zero the x input?
nx, // negate the x input?
zy, // zero the y input?
ny, // negate the y input?
f, // compute out = x + y (if 1) or x & y (if 0)
no; // negate the out output?
OUT
out[16], // 16-bit output
zr, // 1 if (out == 0), 0 otherwise
ng; // 1 if (out < 0), 0 otherwise
PARTS:
Mux16(a=x, b=false, sel=zx, out=xz);
Not16(in=xz, out=ntxz);
Mux16(a=xz, b=ntxz, sel=nx, out=ngx);
Mux16(a=y, b=false, sel=zy, out=yz);
Not16(in=yz, out=ntyz);
Mux16(a=yz, b=ntyz, sel=ny, out=nyx);
Add16(a=ngx, b=nyx, out=add);
And16(a=ngx, b=nyx, out=and);
Mux16(a=and, b=add, sel=f, out=alm);
Not16(in=alm, out=almn);
Mux16(a=alm, b=almn, sel=no, out[0..7]=fin1, out[8..15]=fin2, out[15]=ng, out=fin);
Or8Way(in=fin1, out=has1);
Or8Way(in=fin2, out=has2);
Or(a=has1, b=has2, out=nzr);
Not(in=nzr, out=zr);
And16(a=true, b=fin, out=out);
}

377
projects/02/ALU.tst Normal file
View File

@@ -0,0 +1,377 @@
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/02/ALU.tst
load ALU.hdl,
output-file ALU.out,
compare-to ALU.cmp,
output-list x%B1.16.1 y%B1.16.1 zx%B1.1.1 nx%B1.1.1 zy%B1.1.1
ny%B1.1.1 f%B1.1.1 no%B1.1.1 out%B1.16.1 zr%B1.1.1
ng%B1.1.1;
set x %B0000000000000000, // x = 0
set y %B1111111111111111; // y = -1
// Compute 0
set zx 1,
set nx 0,
set zy 1,
set ny 0,
set f 1,
set no 0,
eval,
output;
// Compute 1
set zx 1,
set nx 1,
set zy 1,
set ny 1,
set f 1,
set no 1,
eval,
output;
// Compute -1
set zx 1,
set nx 1,
set zy 1,
set ny 0,
set f 1,
set no 0,
eval,
output;
// Compute x
set zx 0,
set nx 0,
set zy 1,
set ny 1,
set f 0,
set no 0,
eval,
output;
// Compute y
set zx 1,
set nx 1,
set zy 0,
set ny 0,
set f 0,
set no 0,
eval,
output;
// Compute !x
set zx 0,
set nx 0,
set zy 1,
set ny 1,
set f 0,
set no 1,
eval,
output;
// Compute !y
set zx 1,
set nx 1,
set zy 0,
set ny 0,
set f 0,
set no 1,
eval,
output;
// Compute -x
set zx 0,
set nx 0,
set zy 1,
set ny 1,
set f 1,
set no 1,
eval,
output;
// Compute -y
set zx 1,
set nx 1,
set zy 0,
set ny 0,
set f 1,
set no 1,
eval,
output;
// Compute x + 1
set zx 0,
set nx 1,
set zy 1,
set ny 1,
set f 1,
set no 1,
eval,
output;
// Compute y + 1
set zx 1,
set nx 1,
set zy 0,
set ny 1,
set f 1,
set no 1,
eval,
output;
// Compute x - 1
set zx 0,
set nx 0,
set zy 1,
set ny 1,
set f 1,
set no 0,
eval,
output;
// Compute y - 1
set zx 1,
set nx 1,
set zy 0,
set ny 0,
set f 1,
set no 0,
eval,
output;
// Compute x + y
set zx 0,
set nx 0,
set zy 0,
set ny 0,
set f 1,
set no 0,
eval,
output;
// Compute x - y
set zx 0,
set nx 1,
set zy 0,
set ny 0,
set f 1,
set no 1,
eval,
output;
// Compute y - x
set zx 0,
set nx 0,
set zy 0,
set ny 1,
set f 1,
set no 1,
eval,
output;
// Compute x & y
set zx 0,
set nx 0,
set zy 0,
set ny 0,
set f 0,
set no 0,
eval,
output;
// Compute x | y
set zx 0,
set nx 1,
set zy 0,
set ny 1,
set f 0,
set no 1,
eval,
output;
set x %B000000000010001, // x = 17
set y %B000000000000011; // y = 3
// Compute 0
set zx 1,
set nx 0,
set zy 1,
set ny 0,
set f 1,
set no 0,
eval,
output;
// Compute 1
set zx 1,
set nx 1,
set zy 1,
set ny 1,
set f 1,
set no 1,
eval,
output;
// Compute -1
set zx 1,
set nx 1,
set zy 1,
set ny 0,
set f 1,
set no 0,
eval,
output;
// Compute x
set zx 0,
set nx 0,
set zy 1,
set ny 1,
set f 0,
set no 0,
eval,
output;
// Compute y
set zx 1,
set nx 1,
set zy 0,
set ny 0,
set f 0,
set no 0,
eval,
output;
// Compute !x
set zx 0,
set nx 0,
set zy 1,
set ny 1,
set f 0,
set no 1,
eval,
output;
// Compute !y
set zx 1,
set nx 1,
set zy 0,
set ny 0,
set f 0,
set no 1,
eval,
output;
// Compute -x
set zx 0,
set nx 0,
set zy 1,
set ny 1,
set f 1,
set no 1,
eval,
output;
// Compute -y
set zx 1,
set nx 1,
set zy 0,
set ny 0,
set f 1,
set no 1,
eval,
output;
// Compute x + 1
set zx 0,
set nx 1,
set zy 1,
set ny 1,
set f 1,
set no 1,
eval,
output;
// Compute y + 1
set zx 1,
set nx 1,
set zy 0,
set ny 1,
set f 1,
set no 1,
eval,
output;
// Compute x - 1
set zx 0,
set nx 0,
set zy 1,
set ny 1,
set f 1,
set no 0,
eval,
output;
// Compute y - 1
set zx 1,
set nx 1,
set zy 0,
set ny 0,
set f 1,
set no 0,
eval,
output;
// Compute x + y
set zx 0,
set nx 0,
set zy 0,
set ny 0,
set f 1,
set no 0,
eval,
output;
// Compute x - y
set zx 0,
set nx 1,
set zy 0,
set ny 0,
set f 1,
set no 1,
eval,
output;
// Compute y - x
set zx 0,
set nx 0,
set zy 0,
set ny 1,
set f 1,
set no 1,
eval,
output;
// Compute x & y
set zx 0,
set nx 0,
set zy 0,
set ny 0,
set f 0,
set no 0,
eval,
output;
// Compute x | y
set zx 0,
set nx 1,
set zy 0,
set ny 1,
set f 0,
set no 1,
eval,
output;

7
projects/02/Add16.cmp Normal file
View File

@@ -0,0 +1,7 @@
| a | b | out |
| 0000000000000000 | 0000000000000000 | 0000000000000000 |
| 0000000000000000 | 1111111111111111 | 1111111111111111 |
| 1111111111111111 | 1111111111111111 | 1111111111111110 |
| 1010101010101010 | 0101010101010101 | 1111111111111111 |
| 0011110011000011 | 0000111111110000 | 0100110010110011 |
| 0001001000110100 | 1001100001110110 | 1010101010101010 |

32
projects/02/Add16.hdl Normal file
View File

@@ -0,0 +1,32 @@
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/02/Adder16.hdl
/**
* Adds two 16-bit values.
* The most significant carry bit is ignored.
*/
CHIP Add16 {
IN a[16], b[16];
OUT out[16];
PARTS:
FullAdder(a=a[0], b=b[0], c=false, sum=out[0], carry=c1);
FullAdder(a=a[1], b=b[1], c=c1, sum=out[1], carry=c2);
FullAdder(a=a[2], b=b[2], c=c2, sum=out[2], carry=c3);
FullAdder(a=a[3], b=b[3], c=c3, sum=out[3], carry=c4);
FullAdder(a=a[4], b=b[4], c=c4, sum=out[4], carry=c5);
FullAdder(a=a[5], b=b[5], c=c5, sum=out[5], carry=c6);
FullAdder(a=a[6], b=b[6], c=c6, sum=out[6], carry=c7);
FullAdder(a=a[7], b=b[7], c=c7, sum=out[7], carry=c8);
FullAdder(a=a[8], b=b[8], c=c8, sum=out[8], carry=c9);
FullAdder(a=a[9], b=b[9], c=c9, sum=out[9], carry=c10);
FullAdder(a=a[10], b=b[10], c=c10, sum=out[10], carry=c11);
FullAdder(a=a[11], b=b[11], c=c11, sum=out[11], carry=c12);
FullAdder(a=a[12], b=b[12], c=c12, sum=out[12], carry=c13);
FullAdder(a=a[13], b=b[13], c=c13, sum=out[13], carry=c14);
FullAdder(a=a[14], b=b[14], c=c14, sum=out[14], carry=c15);
FullAdder(a=a[15], b=b[15], c=c15, sum=out[15], carry=c16);
}

39
projects/02/Add16.tst Normal file
View File

@@ -0,0 +1,39 @@
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/02/Add16.tst
load Add16.hdl,
output-file Add16.out,
compare-to Add16.cmp,
output-list a%B1.16.1 b%B1.16.1 out%B1.16.1;
set a %B0000000000000000,
set b %B0000000000000000,
eval,
output;
set a %B0000000000000000,
set b %B1111111111111111,
eval,
output;
set a %B1111111111111111,
set b %B1111111111111111,
eval,
output;
set a %B1010101010101010,
set b %B0101010101010101,
eval,
output;
set a %B0011110011000011,
set b %B0000111111110000,
eval,
output;
set a %B0001001000110100,
set b %B1001100001110110,
eval,
output;

View File

@@ -0,0 +1,9 @@
| a | b | c | sum | carry |
| 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 1 | 0 |
| 0 | 1 | 0 | 1 | 0 |
| 0 | 1 | 1 | 0 | 1 |
| 1 | 0 | 0 | 1 | 0 |
| 1 | 0 | 1 | 0 | 1 |
| 1 | 1 | 0 | 0 | 1 |
| 1 | 1 | 1 | 1 | 1 |

27
projects/02/FullAdder.hdl Normal file
View File

@@ -0,0 +1,27 @@
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/02/FullAdder.hdl
/**
* Computes the sum of three bits.
*/
CHIP FullAdder {
IN a, b, c; // 1-bit inputs
OUT sum, // Right bit of a + b + c
carry; // Left bit of a + b + c
PARTS:
HalfAdder(a=a, b=b, sum=h1, carry=c1);
HalfAdder(a=h1, b=c, sum=h2, carry=c2);
Xor(a=a, b=b, out=axb);
And(a=axb, b=c, out=notout);
Or(a=h1, b=h2, out=sum1);
Xor(a=sum1, b=notout, out=sum);
Or(a=c1, b=c2, out=carry);
}

47
projects/02/FullAdder.tst Normal file
View File

@@ -0,0 +1,47 @@
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/02/FullAdder.tst
load FullAdder.hdl,
output-file FullAdder.out,
compare-to FullAdder.cmp,
output-list a%B3.1.3 b%B3.1.3 c%B3.1.3 sum%B3.1.3 carry%B3.1.3;
set a 0,
set b 0,
set c 0,
eval,
output;
set c 1,
eval,
output;
set b 1,
set c 0,
eval,
output;
set c 1,
eval,
output;
set a 1,
set b 0,
set c 0,
eval,
output;
set c 1,
eval,
output;
set b 1,
set c 0,
eval,
output;
set c 1,
eval,
output;

View File

@@ -0,0 +1,5 @@
| a | b | sum | carry |
| 0 | 0 | 0 | 0 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 1 |

18
projects/02/HalfAdder.hdl Normal file
View File

@@ -0,0 +1,18 @@
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/02/HalfAdder.hdl
/**
* Computes the sum of two bits.
*/
CHIP HalfAdder {
IN a, b; // 1-bit inputs
OUT sum, // Right bit of a + b
carry; // Left bit of a + b
PARTS:
Xor(a=a, b=b, out=sum);
And(a=a, b=b, out=carry);
}

29
projects/02/HalfAdder.tst Normal file
View File

@@ -0,0 +1,29 @@
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/02/HalfAdder.tst
load HalfAdder.hdl,
output-file HalfAdder.out,
compare-to HalfAdder.cmp,
output-list a%B3.1.3 b%B3.1.3 sum%B3.1.3 carry%B3.1.3;
set a 0,
set b 0,
eval,
output;
set a 0,
set b 1,
eval,
output;
set a 1,
set b 0,
eval,
output;
set a 1,
set b 1,
eval,
output;

5
projects/02/Inc16.cmp Normal file
View File

@@ -0,0 +1,5 @@
| in | out |
| 0000000000000000 | 0000000000000001 |
| 1111111111111111 | 0000000000000000 |
| 0000000000000101 | 0000000000000110 |
| 1111111111111011 | 1111111111111100 |

17
projects/02/Inc16.hdl Normal file
View File

@@ -0,0 +1,17 @@
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/02/Inc16.hdl
/**
* 16-bit incrementer:
* out = in + 1 (arithmetic addition)
*/
CHIP Inc16 {
IN in[16];
OUT out[16];
PARTS:
Add16(a=in, b[0]=true, out=out);
}

25
projects/02/Inc16.tst Normal file
View File

@@ -0,0 +1,25 @@
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/02/Inc16.tst
load Inc16.hdl,
output-file Inc16.out,
compare-to Inc16.cmp,
output-list in%B1.16.1 out%B1.16.1;
set in %B0000000000000000, // in = 0
eval,
output;
set in %B1111111111111111, // in = -1
eval,
output;
set in %B0000000000000101, // in = 5
eval,
output;
set in %B1111111111111011, // in = -5
eval,
output;

BIN
projects/03/03.zip Normal file

Binary file not shown.

215
projects/03/a/Bit.cmp Normal file
View File

@@ -0,0 +1,215 @@
| time | in |load | out |
| 0+ | 0 | 0 | 0 |
| 1 | 0 | 0 | 0 |
| 1+ | 0 | 1 | 0 |
| 2 | 0 | 1 | 0 |
| 2+ | 1 | 0 | 0 |
| 3 | 1 | 0 | 0 |
| 3+ | 1 | 1 | 0 |
| 4 | 1 | 1 | 1 |
| 4+ | 0 | 0 | 1 |
| 5 | 0 | 0 | 1 |
| 5+ | 1 | 0 | 1 |
| 6 | 1 | 0 | 1 |
| 6+ | 0 | 1 | 1 |
| 7 | 0 | 1 | 0 |
| 7+ | 1 | 1 | 0 |
| 8 | 1 | 1 | 1 |
| 8+ | 0 | 0 | 1 |
| 9 | 0 | 0 | 1 |
| 9+ | 0 | 0 | 1 |
| 10 | 0 | 0 | 1 |
| 10+ | 0 | 0 | 1 |
| 11 | 0 | 0 | 1 |
| 11+ | 0 | 0 | 1 |
| 12 | 0 | 0 | 1 |
| 12+ | 0 | 0 | 1 |
| 13 | 0 | 0 | 1 |
| 13+ | 0 | 0 | 1 |
| 14 | 0 | 0 | 1 |
| 14+ | 0 | 0 | 1 |
| 15 | 0 | 0 | 1 |
| 15+ | 0 | 0 | 1 |
| 16 | 0 | 0 | 1 |
| 16+ | 0 | 0 | 1 |
| 17 | 0 | 0 | 1 |
| 17+ | 0 | 0 | 1 |
| 18 | 0 | 0 | 1 |
| 18+ | 0 | 0 | 1 |
| 19 | 0 | 0 | 1 |
| 19+ | 0 | 0 | 1 |
| 20 | 0 | 0 | 1 |
| 20+ | 0 | 0 | 1 |
| 21 | 0 | 0 | 1 |
| 21+ | 0 | 0 | 1 |
| 22 | 0 | 0 | 1 |
| 22+ | 0 | 0 | 1 |
| 23 | 0 | 0 | 1 |
| 23+ | 0 | 0 | 1 |
| 24 | 0 | 0 | 1 |
| 24+ | 0 | 0 | 1 |
| 25 | 0 | 0 | 1 |
| 25+ | 0 | 0 | 1 |
| 26 | 0 | 0 | 1 |
| 26+ | 0 | 0 | 1 |
| 27 | 0 | 0 | 1 |
| 27+ | 0 | 0 | 1 |
| 28 | 0 | 0 | 1 |
| 28+ | 0 | 0 | 1 |
| 29 | 0 | 0 | 1 |
| 29+ | 0 | 0 | 1 |
| 30 | 0 | 0 | 1 |
| 30+ | 0 | 0 | 1 |
| 31 | 0 | 0 | 1 |
| 31+ | 0 | 0 | 1 |
| 32 | 0 | 0 | 1 |
| 32+ | 0 | 0 | 1 |
| 33 | 0 | 0 | 1 |
| 33+ | 0 | 0 | 1 |
| 34 | 0 | 0 | 1 |
| 34+ | 0 | 0 | 1 |
| 35 | 0 | 0 | 1 |
| 35+ | 0 | 0 | 1 |
| 36 | 0 | 0 | 1 |
| 36+ | 0 | 0 | 1 |
| 37 | 0 | 0 | 1 |
| 37+ | 0 | 0 | 1 |
| 38 | 0 | 0 | 1 |
| 38+ | 0 | 0 | 1 |
| 39 | 0 | 0 | 1 |
| 39+ | 0 | 0 | 1 |
| 40 | 0 | 0 | 1 |
| 40+ | 0 | 0 | 1 |
| 41 | 0 | 0 | 1 |
| 41+ | 0 | 0 | 1 |
| 42 | 0 | 0 | 1 |
| 42+ | 0 | 0 | 1 |
| 43 | 0 | 0 | 1 |
| 43+ | 0 | 0 | 1 |
| 44 | 0 | 0 | 1 |
| 44+ | 0 | 0 | 1 |
| 45 | 0 | 0 | 1 |
| 45+ | 0 | 0 | 1 |
| 46 | 0 | 0 | 1 |
| 46+ | 0 | 0 | 1 |
| 47 | 0 | 0 | 1 |
| 47+ | 0 | 0 | 1 |
| 48 | 0 | 0 | 1 |
| 48+ | 0 | 0 | 1 |
| 49 | 0 | 0 | 1 |
| 49+ | 0 | 0 | 1 |
| 50 | 0 | 0 | 1 |
| 50+ | 0 | 0 | 1 |
| 51 | 0 | 0 | 1 |
| 51+ | 0 | 0 | 1 |
| 52 | 0 | 0 | 1 |
| 52+ | 0 | 0 | 1 |
| 53 | 0 | 0 | 1 |
| 53+ | 0 | 0 | 1 |
| 54 | 0 | 0 | 1 |
| 54+ | 0 | 0 | 1 |
| 55 | 0 | 0 | 1 |
| 55+ | 0 | 0 | 1 |
| 56 | 0 | 0 | 1 |
| 56+ | 0 | 0 | 1 |
| 57 | 0 | 0 | 1 |
| 57+ | 0 | 1 | 1 |
| 58 | 0 | 1 | 0 |
| 58+ | 1 | 0 | 0 |
| 59 | 1 | 0 | 0 |
| 59+ | 1 | 0 | 0 |
| 60 | 1 | 0 | 0 |
| 60+ | 1 | 0 | 0 |
| 61 | 1 | 0 | 0 |
| 61+ | 1 | 0 | 0 |
| 62 | 1 | 0 | 0 |
| 62+ | 1 | 0 | 0 |
| 63 | 1 | 0 | 0 |
| 63+ | 1 | 0 | 0 |
| 64 | 1 | 0 | 0 |
| 64+ | 1 | 0 | 0 |
| 65 | 1 | 0 | 0 |
| 65+ | 1 | 0 | 0 |
| 66 | 1 | 0 | 0 |
| 66+ | 1 | 0 | 0 |
| 67 | 1 | 0 | 0 |
| 67+ | 1 | 0 | 0 |
| 68 | 1 | 0 | 0 |
| 68+ | 1 | 0 | 0 |
| 69 | 1 | 0 | 0 |
| 69+ | 1 | 0 | 0 |
| 70 | 1 | 0 | 0 |
| 70+ | 1 | 0 | 0 |
| 71 | 1 | 0 | 0 |
| 71+ | 1 | 0 | 0 |
| 72 | 1 | 0 | 0 |
| 72+ | 1 | 0 | 0 |
| 73 | 1 | 0 | 0 |
| 73+ | 1 | 0 | 0 |
| 74 | 1 | 0 | 0 |
| 74+ | 1 | 0 | 0 |
| 75 | 1 | 0 | 0 |
| 75+ | 1 | 0 | 0 |
| 76 | 1 | 0 | 0 |
| 76+ | 1 | 0 | 0 |
| 77 | 1 | 0 | 0 |
| 77+ | 1 | 0 | 0 |
| 78 | 1 | 0 | 0 |
| 78+ | 1 | 0 | 0 |
| 79 | 1 | 0 | 0 |
| 79+ | 1 | 0 | 0 |
| 80 | 1 | 0 | 0 |
| 80+ | 1 | 0 | 0 |
| 81 | 1 | 0 | 0 |
| 81+ | 1 | 0 | 0 |
| 82 | 1 | 0 | 0 |
| 82+ | 1 | 0 | 0 |
| 83 | 1 | 0 | 0 |
| 83+ | 1 | 0 | 0 |
| 84 | 1 | 0 | 0 |
| 84+ | 1 | 0 | 0 |
| 85 | 1 | 0 | 0 |
| 85+ | 1 | 0 | 0 |
| 86 | 1 | 0 | 0 |
| 86+ | 1 | 0 | 0 |
| 87 | 1 | 0 | 0 |
| 87+ | 1 | 0 | 0 |
| 88 | 1 | 0 | 0 |
| 88+ | 1 | 0 | 0 |
| 89 | 1 | 0 | 0 |
| 89+ | 1 | 0 | 0 |
| 90 | 1 | 0 | 0 |
| 90+ | 1 | 0 | 0 |
| 91 | 1 | 0 | 0 |
| 91+ | 1 | 0 | 0 |
| 92 | 1 | 0 | 0 |
| 92+ | 1 | 0 | 0 |
| 93 | 1 | 0 | 0 |
| 93+ | 1 | 0 | 0 |
| 94 | 1 | 0 | 0 |
| 94+ | 1 | 0 | 0 |
| 95 | 1 | 0 | 0 |
| 95+ | 1 | 0 | 0 |
| 96 | 1 | 0 | 0 |
| 96+ | 1 | 0 | 0 |
| 97 | 1 | 0 | 0 |
| 97+ | 1 | 0 | 0 |
| 98 | 1 | 0 | 0 |
| 98+ | 1 | 0 | 0 |
| 99 | 1 | 0 | 0 |
| 99+ | 1 | 0 | 0 |
| 100 | 1 | 0 | 0 |
| 100+ | 1 | 0 | 0 |
| 101 | 1 | 0 | 0 |
| 101+ | 1 | 0 | 0 |
| 102 | 1 | 0 | 0 |
| 102+ | 1 | 0 | 0 |
| 103 | 1 | 0 | 0 |
| 103+ | 1 | 0 | 0 |
| 104 | 1 | 0 | 0 |
| 104+ | 1 | 0 | 0 |
| 105 | 1 | 0 | 0 |
| 105+ | 1 | 0 | 0 |
| 106 | 1 | 0 | 0 |
| 106+ | 1 | 0 | 0 |
| 107 | 1 | 0 | 0 |

19
projects/03/a/Bit.hdl Normal file
View File

@@ -0,0 +1,19 @@
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/03/a/Bit.hdl
/**
* 1-bit register:
* If load[t] == 1 then out[t+1] = in[t]
* else out does not change (out[t+1] = out[t])
*/
CHIP Bit {
IN in, load;
OUT out;
PARTS:
Mux(a=mux, b=in, sel=load, out=dff);
DFF(in=dff, out=mux, out=out);
}

865
projects/03/a/Bit.tst Normal file
View File

@@ -0,0 +1,865 @@
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/03/a/Bit.tst
load Bit.hdl,
output-file Bit.out,
compare-to Bit.cmp,
output-list time%S1.4.1 in%B2.1.2 load%B2.1.2 out%B2.1.2;
set in 0,
set load 0,
tick,
output;
tock,
output;
set in 0,
set load 1,
tick,
output;
tock,
output;
set in 1,
set load 0,
tick,
output;
tock,
output;
set in 1,
set load 1,
tick,
output;
tock,
output;
set in 0,
set load 0,
tick,
output;
tock,
output;
set in 1,
set load 0,
tick,
output;
tock,
output;
set in 0,
set load 1,
tick,
output;
tock,
output;
set in 1,
set load 1,
tick,
output;
tock,
output;
set in 0,
set load 0,
tick,
output;
tock,
output;
set in 0,
set load 0,
tick,
output;
tock,
output;
set in 0,
set load 0,
tick,
output;
tock,
output;
set in 0,
set load 0,
tick,
output;
tock,
output;
set in 0,
set load 0,
tick,
output;
tock,
output;
set in 0,
set load 0,
tick,
output;
tock,
output;
set in 0,
set load 0,
tick,
output;
tock,
output;
set in 0,
set load 0,
tick,
output;
tock,
output;
set in 0,
set load 0,
tick,
output;
tock,
output;
set in 0,
set load 0,
tick,
output;
tock,
output;
set in 0,
set load 0,
tick,
output;
tock,
output;
set in 0,
set load 0,
tick,
output;
tock,
output;
set in 0,
set load 0,
tick,
output;
tock,
output;
set in 0,
set load 0,
tick,
output;
tock,
output;
set in 0,
set load 0,
tick,
output;
tock,
output;
set in 0,
set load 0,
tick,
output;
tock,
output;
set in 0,
set load 0,
tick,
output;
tock,
output;
set in 0,
set load 0,
tick,
output;
tock,
output;
set in 0,
set load 0,
tick,
output;
tock,
output;
set in 0,
set load 0,
tick,
output;
tock,
output;
set in 0,
set load 0,
tick,
output;
tock,
output;
set in 0,
set load 0,
tick,
output;
tock,
output;
set in 0,
set load 0,
tick,
output;
tock,
output;
set in 0,
set load 0,
tick,
output;
tock,
output;
set in 0,
set load 0,
tick,
output;
tock,
output;
set in 0,
set load 0,
tick,
output;
tock,
output;
set in 0,
set load 0,
tick,
output;
tock,
output;
set in 0,
set load 0,
tick,
output;
tock,
output;
set in 0,
set load 0,
tick,
output;
tock,
output;
set in 0,
set load 0,
tick,
output;
tock,
output;
set in 0,
set load 0,
tick,
output;
tock,
output;
set in 0,
set load 0,
tick,
output;
tock,
output;
set in 0,
set load 0,
tick,
output;
tock,
output;
set in 0,
set load 0,
tick,
output;
tock,
output;
set in 0,
set load 0,
tick,
output;
tock,
output;
set in 0,
set load 0,
tick,
output;
tock,
output;
set in 0,
set load 0,
tick,
output;
tock,
output;
set in 0,
set load 0,
tick,
output;
tock,
output;
set in 0,
set load 0,
tick,
output;
tock,
output;
set in 0,
set load 0,
tick,
output;
tock,
output;
set in 0,
set load 0,
tick,
output;
tock,
output;
set in 0,
set load 0,
tick,
output;
tock,
output;
set in 0,
set load 0,
tick,
output;
tock,
output;
set in 0,
set load 0,
tick,
output;
tock,
output;
set in 0,
set load 0,
tick,
output;
tock,
output;
set in 0,
set load 0,
tick,
output;
tock,
output;
set in 0,
set load 0,
tick,
output;
tock,
output;
set in 0,
set load 0,
tick,
output;
tock,
output;
set in 0,
set load 0,
tick,
output;
tock,
output;
set in 0,
set load 1,
tick,
output;
tock,
output;
set in 1,
set load 0,
tick,
output;
tock,
output;
set in 1,
set load 0,
tick,
output;
tock,
output;
set in 1,
set load 0,
tick,
output;
tock,
output;
set in 1,
set load 0,
tick,
output;
tock,
output;
set in 1,
set load 0,
tick,
output;
tock,
output;
set in 1,
set load 0,
tick,
output;
tock,
output;
set in 1,
set load 0,
tick,
output;
tock,
output;
set in 1,
set load 0,
tick,
output;
tock,
output;
set in 1,
set load 0,
tick,
output;
tock,
output;
set in 1,
set load 0,
tick,
output;
tock,
output;
set in 1,
set load 0,
tick,
output;
tock,
output;
set in 1,
set load 0,
tick,
output;
tock,
output;
set in 1,
set load 0,
tick,
output;
tock,
output;
set in 1,
set load 0,
tick,
output;
tock,
output;
set in 1,
set load 0,
tick,
output;
tock,
output;
set in 1,
set load 0,
tick,
output;
tock,
output;
set in 1,
set load 0,
tick,
output;
tock,
output;
set in 1,
set load 0,
tick,
output;
tock,
output;
set in 1,
set load 0,
tick,
output;
tock,
output;
set in 1,
set load 0,
tick,
output;
tock,
output;
set in 1,
set load 0,
tick,
output;
tock,
output;
set in 1,
set load 0,
tick,
output;
tock,
output;
set in 1,
set load 0,
tick,
output;
tock,
output;
set in 1,
set load 0,
tick,
output;
tock,
output;
set in 1,
set load 0,
tick,
output;
tock,
output;
set in 1,
set load 0,
tick,
output;
tock,
output;
set in 1,
set load 0,
tick,
output;
tock,
output;
set in 1,
set load 0,
tick,
output;
tock,
output;
set in 1,
set load 0,
tick,
output;
tock,
output;
set in 1,
set load 0,
tick,
output;
tock,
output;
set in 1,
set load 0,
tick,
output;
tock,
output;
set in 1,
set load 0,
tick,
output;
tock,
output;
set in 1,
set load 0,
tick,
output;
tock,
output;
set in 1,
set load 0,
tick,
output;
tock,
output;
set in 1,
set load 0,
tick,
output;
tock,
output;
set in 1,
set load 0,
tick,
output;
tock,
output;
set in 1,
set load 0,
tick,
output;
tock,
output;
set in 1,
set load 0,
tick,
output;
tock,
output;
set in 1,
set load 0,
tick,
output;
tock,
output;
set in 1,
set load 0,
tick,
output;
tock,
output;
set in 1,
set load 0,
tick,
output;
tock,
output;
set in 1,
set load 0,
tick,
output;
tock,
output;
set in 1,
set load 0,
tick,
output;
tock,
output;
set in 1,
set load 0,
tick,
output;
tock,
output;
set in 1,
set load 0,
tick,
output;
tock,
output;
set in 1,
set load 0,
tick,
output;
tock,
output;
set in 1,
set load 0,
tick,
output;
tock,
output;
set in 1,
set load 0,
tick,
output;
tock,
output;
set in 1,
set load 0,
tick,
output;
tock,
output;

31
projects/03/a/PC.cmp Normal file
View File

@@ -0,0 +1,31 @@
| time | in |reset|load | inc | out |
| 0+ | 0 | 0 | 0 | 0 | 0 |
| 1 | 0 | 0 | 0 | 0 | 0 |
| 1+ | 0 | 0 | 0 | 1 | 0 |
| 2 | 0 | 0 | 0 | 1 | 1 |
| 2+ | -32123 | 0 | 0 | 1 | 1 |
| 3 | -32123 | 0 | 0 | 1 | 2 |
| 3+ | -32123 | 0 | 1 | 1 | 2 |
| 4 | -32123 | 0 | 1 | 1 | -32123 |
| 4+ | -32123 | 0 | 0 | 1 | -32123 |
| 5 | -32123 | 0 | 0 | 1 | -32122 |
| 5+ | -32123 | 0 | 0 | 1 | -32122 |
| 6 | -32123 | 0 | 0 | 1 | -32121 |
| 6+ | 12345 | 0 | 1 | 0 | -32121 |
| 7 | 12345 | 0 | 1 | 0 | 12345 |
| 7+ | 12345 | 1 | 1 | 0 | 12345 |
| 8 | 12345 | 1 | 1 | 0 | 0 |
| 8+ | 12345 | 0 | 1 | 1 | 0 |
| 9 | 12345 | 0 | 1 | 1 | 12345 |
| 9+ | 12345 | 1 | 1 | 1 | 12345 |
| 10 | 12345 | 1 | 1 | 1 | 0 |
| 10+ | 12345 | 0 | 0 | 1 | 0 |
| 11 | 12345 | 0 | 0 | 1 | 1 |
| 11+ | 12345 | 1 | 0 | 1 | 1 |
| 12 | 12345 | 1 | 0 | 1 | 0 |
| 12+ | 0 | 0 | 1 | 1 | 0 |
| 13 | 0 | 0 | 1 | 1 | 0 |
| 13+ | 0 | 0 | 0 | 1 | 0 |
| 14 | 0 | 0 | 0 | 1 | 1 |
| 14+ | 22222 | 1 | 0 | 0 | 1 |
| 15 | 22222 | 1 | 0 | 0 | 0 |

29
projects/03/a/PC.hdl Normal file
View File

@@ -0,0 +1,29 @@
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/03/a/PC.hdl
/**
* A 16-bit counter with load and reset control bits.
* if (reset[t] == 1) out[t+1] = 0
* else if (load[t] == 1) out[t+1] = in[t]
* else if (inc[t] == 1) out[t+1] = out[t] + 1 (integer addition)
* else out[t+1] = out[t]
*/
CHIP PC {
IN in[16],load,inc,reset;
OUT out[16];
PARTS:
Inc16(in=regout, out=reginc);
Mux16(a=regout, b=reginc, sel=inc, out=incmux);
Mux16(a=incmux, b=in, sel=load, out=loadmux);
Mux16(a=loadmux, b=false, sel=reset, out=resmux);
Or8Way(in[0]=reset, in[1]=load, in[2]=inc, out=regload);
Register(in=resmux, load=regload, out=regout, out=out);
}

125
projects/03/a/PC.tst Normal file
View File

@@ -0,0 +1,125 @@
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/03/a/PC.tst
load PC.hdl,
output-file PC.out,
compare-to PC.cmp,
output-list time%S1.4.1 in%D1.6.1 reset%B2.1.2 load%B2.1.2 inc%B2.1.2 out%D1.6.1;
set in 0,
set reset 0,
set load 0,
set inc 0,
tick,
output;
tock,
output;
set inc 1,
tick,
output;
tock,
output;
set in -32123,
tick,
output;
tock,
output;
set load 1,
tick,
output;
tock,
output;
set load 0,
tick,
output;
tock,
output;
tick,
output;
tock,
output;
set in 12345,
set load 1,
set inc 0,
tick,
output;
tock,
output;
set reset 1,
tick,
output;
tock,
output;
set reset 0,
set inc 1,
tick,
output;
tock,
output;
set reset 1,
tick,
output;
tock,
output;
set reset 0,
set load 0,
tick,
output;
tock,
output;
set reset 1,
tick,
output;
tock,
output;
set in 0,
set reset 0,
set load 1,
tick,
output;
tock,
output;
set load 0,
set inc 1,
tick,
output;
tock,
output;
set in 22222,
set reset 1,
set inc 0,
tick,
output;
tock,
output;

320
projects/03/a/RAM64.cmp Normal file
View File

@@ -0,0 +1,320 @@
| time | in |load |address| out |
| 0+ | 0 | 0 | 0 | 0 |
| 1 | 0 | 0 | 0 | 0 |
| 1+ | 0 | 1 | 0 | 0 |
| 2 | 0 | 1 | 0 | 0 |
| 2+ | 1313 | 0 | 0 | 0 |
| 3 | 1313 | 0 | 0 | 0 |
| 3+ | 1313 | 1 | 13 | 0 |
| 4 | 1313 | 1 | 13 | 1313 |
| 4+ | 1313 | 0 | 0 | 0 |
| 5 | 1313 | 0 | 0 | 0 |
| 5+ | 4747 | 0 | 47 | 0 |
| 6 | 4747 | 0 | 47 | 0 |
| 6+ | 4747 | 1 | 47 | 0 |
| 7 | 4747 | 1 | 47 | 4747 |
| 7+ | 4747 | 0 | 47 | 4747 |
| 8 | 4747 | 0 | 47 | 4747 |
| 8 | 4747 | 0 | 13 | 1313 |
| 8+ | 6363 | 0 | 13 | 1313 |
| 9 | 6363 | 0 | 13 | 1313 |
| 9+ | 6363 | 1 | 63 | 0 |
| 10 | 6363 | 1 | 63 | 6363 |
| 10+ | 6363 | 0 | 63 | 6363 |
| 11 | 6363 | 0 | 63 | 6363 |
| 11 | 6363 | 0 | 47 | 4747 |
| 11 | 6363 | 0 | 63 | 6363 |
| 11+ | 6363 | 0 | 40 | 0 |
| 12 | 6363 | 0 | 40 | 0 |
| 12 | 6363 | 0 | 41 | 0 |
| 12 | 6363 | 0 | 42 | 0 |
| 12 | 6363 | 0 | 43 | 0 |
| 12 | 6363 | 0 | 44 | 0 |
| 12 | 6363 | 0 | 45 | 0 |
| 12 | 6363 | 0 | 46 | 0 |
| 12 | 6363 | 0 | 47 | 4747 |
| 12+ | 21845 | 1 | 40 | 0 |
| 13 | 21845 | 1 | 40 | 21845 |
| 13+ | 21845 | 1 | 41 | 0 |
| 14 | 21845 | 1 | 41 | 21845 |
| 14+ | 21845 | 1 | 42 | 0 |
| 15 | 21845 | 1 | 42 | 21845 |
| 15+ | 21845 | 1 | 43 | 0 |
| 16 | 21845 | 1 | 43 | 21845 |
| 16+ | 21845 | 1 | 44 | 0 |
| 17 | 21845 | 1 | 44 | 21845 |
| 17+ | 21845 | 1 | 45 | 0 |
| 18 | 21845 | 1 | 45 | 21845 |
| 18+ | 21845 | 1 | 46 | 0 |
| 19 | 21845 | 1 | 46 | 21845 |
| 19+ | 21845 | 1 | 47 | 4747 |
| 20 | 21845 | 1 | 47 | 21845 |
| 20+ | 21845 | 0 | 40 | 21845 |
| 21 | 21845 | 0 | 40 | 21845 |
| 21 | 21845 | 0 | 41 | 21845 |
| 21 | 21845 | 0 | 42 | 21845 |
| 21 | 21845 | 0 | 43 | 21845 |
| 21 | 21845 | 0 | 44 | 21845 |
| 21 | 21845 | 0 | 45 | 21845 |
| 21 | 21845 | 0 | 46 | 21845 |
| 21 | 21845 | 0 | 47 | 21845 |
| 21+ | -21846 | 1 | 40 | 21845 |
| 22 | -21846 | 1 | 40 | -21846 |
| 22+ | -21846 | 0 | 40 | -21846 |
| 23 | -21846 | 0 | 40 | -21846 |
| 23 | -21846 | 0 | 41 | 21845 |
| 23 | -21846 | 0 | 42 | 21845 |
| 23 | -21846 | 0 | 43 | 21845 |
| 23 | -21846 | 0 | 44 | 21845 |
| 23 | -21846 | 0 | 45 | 21845 |
| 23 | -21846 | 0 | 46 | 21845 |
| 23 | -21846 | 0 | 47 | 21845 |
| 23+ | 21845 | 1 | 40 | -21846 |
| 24 | 21845 | 1 | 40 | 21845 |
| 24+ | -21846 | 1 | 41 | 21845 |
| 25 | -21846 | 1 | 41 | -21846 |
| 25+ | -21846 | 0 | 40 | 21845 |
| 26 | -21846 | 0 | 40 | 21845 |
| 26 | -21846 | 0 | 41 | -21846 |
| 26 | -21846 | 0 | 42 | 21845 |
| 26 | -21846 | 0 | 43 | 21845 |
| 26 | -21846 | 0 | 44 | 21845 |
| 26 | -21846 | 0 | 45 | 21845 |
| 26 | -21846 | 0 | 46 | 21845 |
| 26 | -21846 | 0 | 47 | 21845 |
| 26+ | 21845 | 1 | 41 | -21846 |
| 27 | 21845 | 1 | 41 | 21845 |
| 27+ | -21846 | 1 | 42 | 21845 |
| 28 | -21846 | 1 | 42 | -21846 |
| 28+ | -21846 | 0 | 40 | 21845 |
| 29 | -21846 | 0 | 40 | 21845 |
| 29 | -21846 | 0 | 41 | 21845 |
| 29 | -21846 | 0 | 42 | -21846 |
| 29 | -21846 | 0 | 43 | 21845 |
| 29 | -21846 | 0 | 44 | 21845 |
| 29 | -21846 | 0 | 45 | 21845 |
| 29 | -21846 | 0 | 46 | 21845 |
| 29 | -21846 | 0 | 47 | 21845 |
| 29+ | 21845 | 1 | 42 | -21846 |
| 30 | 21845 | 1 | 42 | 21845 |
| 30+ | -21846 | 1 | 43 | 21845 |
| 31 | -21846 | 1 | 43 | -21846 |
| 31+ | -21846 | 0 | 40 | 21845 |
| 32 | -21846 | 0 | 40 | 21845 |
| 32 | -21846 | 0 | 41 | 21845 |
| 32 | -21846 | 0 | 42 | 21845 |
| 32 | -21846 | 0 | 43 | -21846 |
| 32 | -21846 | 0 | 44 | 21845 |
| 32 | -21846 | 0 | 45 | 21845 |
| 32 | -21846 | 0 | 46 | 21845 |
| 32 | -21846 | 0 | 47 | 21845 |
| 32+ | 21845 | 1 | 43 | -21846 |
| 33 | 21845 | 1 | 43 | 21845 |
| 33+ | -21846 | 1 | 44 | 21845 |
| 34 | -21846 | 1 | 44 | -21846 |
| 34+ | -21846 | 0 | 40 | 21845 |
| 35 | -21846 | 0 | 40 | 21845 |
| 35 | -21846 | 0 | 41 | 21845 |
| 35 | -21846 | 0 | 42 | 21845 |
| 35 | -21846 | 0 | 43 | 21845 |
| 35 | -21846 | 0 | 44 | -21846 |
| 35 | -21846 | 0 | 45 | 21845 |
| 35 | -21846 | 0 | 46 | 21845 |
| 35 | -21846 | 0 | 47 | 21845 |
| 35+ | 21845 | 1 | 44 | -21846 |
| 36 | 21845 | 1 | 44 | 21845 |
| 36+ | -21846 | 1 | 45 | 21845 |
| 37 | -21846 | 1 | 45 | -21846 |
| 37+ | -21846 | 0 | 40 | 21845 |
| 38 | -21846 | 0 | 40 | 21845 |
| 38 | -21846 | 0 | 41 | 21845 |
| 38 | -21846 | 0 | 42 | 21845 |
| 38 | -21846 | 0 | 43 | 21845 |
| 38 | -21846 | 0 | 44 | 21845 |
| 38 | -21846 | 0 | 45 | -21846 |
| 38 | -21846 | 0 | 46 | 21845 |
| 38 | -21846 | 0 | 47 | 21845 |
| 38+ | 21845 | 1 | 45 | -21846 |
| 39 | 21845 | 1 | 45 | 21845 |
| 39+ | -21846 | 1 | 46 | 21845 |
| 40 | -21846 | 1 | 46 | -21846 |
| 40+ | -21846 | 0 | 40 | 21845 |
| 41 | -21846 | 0 | 40 | 21845 |
| 41 | -21846 | 0 | 41 | 21845 |
| 41 | -21846 | 0 | 42 | 21845 |
| 41 | -21846 | 0 | 43 | 21845 |
| 41 | -21846 | 0 | 44 | 21845 |
| 41 | -21846 | 0 | 45 | 21845 |
| 41 | -21846 | 0 | 46 | -21846 |
| 41 | -21846 | 0 | 47 | 21845 |
| 41+ | 21845 | 1 | 46 | -21846 |
| 42 | 21845 | 1 | 46 | 21845 |
| 42+ | -21846 | 1 | 47 | 21845 |
| 43 | -21846 | 1 | 47 | -21846 |
| 43+ | -21846 | 0 | 40 | 21845 |
| 44 | -21846 | 0 | 40 | 21845 |
| 44 | -21846 | 0 | 41 | 21845 |
| 44 | -21846 | 0 | 42 | 21845 |
| 44 | -21846 | 0 | 43 | 21845 |
| 44 | -21846 | 0 | 44 | 21845 |
| 44 | -21846 | 0 | 45 | 21845 |
| 44 | -21846 | 0 | 46 | 21845 |
| 44 | -21846 | 0 | 47 | -21846 |
| 44+ | 21845 | 1 | 47 | -21846 |
| 45 | 21845 | 1 | 47 | 21845 |
| 45+ | 21845 | 0 | 40 | 21845 |
| 46 | 21845 | 0 | 40 | 21845 |
| 46 | 21845 | 0 | 41 | 21845 |
| 46 | 21845 | 0 | 42 | 21845 |
| 46 | 21845 | 0 | 43 | 21845 |
| 46 | 21845 | 0 | 44 | 21845 |
| 46 | 21845 | 0 | 45 | 21845 |
| 46 | 21845 | 0 | 46 | 21845 |
| 46 | 21845 | 0 | 47 | 21845 |
| 46+ | 21845 | 0 | 5 | 0 |
| 47 | 21845 | 0 | 5 | 0 |
| 47 | 21845 | 0 | 13 | 1313 |
| 47 | 21845 | 0 | 21 | 0 |
| 47 | 21845 | 0 | 29 | 0 |
| 47 | 21845 | 0 | 37 | 0 |
| 47 | 21845 | 0 | 45 | 21845 |
| 47 | 21845 | 0 | 53 | 0 |
| 47 | 21845 | 0 | 61 | 0 |
| 47+ | 21845 | 1 | 5 | 0 |
| 48 | 21845 | 1 | 5 | 21845 |
| 48+ | 21845 | 1 | 13 | 1313 |
| 49 | 21845 | 1 | 13 | 21845 |
| 49+ | 21845 | 1 | 21 | 0 |
| 50 | 21845 | 1 | 21 | 21845 |
| 50+ | 21845 | 1 | 29 | 0 |
| 51 | 21845 | 1 | 29 | 21845 |
| 51+ | 21845 | 1 | 37 | 0 |
| 52 | 21845 | 1 | 37 | 21845 |
| 52+ | 21845 | 1 | 45 | 21845 |
| 53 | 21845 | 1 | 45 | 21845 |
| 53+ | 21845 | 1 | 53 | 0 |
| 54 | 21845 | 1 | 53 | 21845 |
| 54+ | 21845 | 1 | 61 | 0 |
| 55 | 21845 | 1 | 61 | 21845 |
| 55+ | 21845 | 0 | 5 | 21845 |
| 56 | 21845 | 0 | 5 | 21845 |
| 56 | 21845 | 0 | 13 | 21845 |
| 56 | 21845 | 0 | 21 | 21845 |
| 56 | 21845 | 0 | 29 | 21845 |
| 56 | 21845 | 0 | 37 | 21845 |
| 56 | 21845 | 0 | 45 | 21845 |
| 56 | 21845 | 0 | 53 | 21845 |
| 56 | 21845 | 0 | 61 | 21845 |
| 56+ | -21846 | 1 | 5 | 21845 |
| 57 | -21846 | 1 | 5 | -21846 |
| 57+ | -21846 | 0 | 5 | -21846 |
| 58 | -21846 | 0 | 5 | -21846 |
| 58 | -21846 | 0 | 13 | 21845 |
| 58 | -21846 | 0 | 21 | 21845 |
| 58 | -21846 | 0 | 29 | 21845 |
| 58 | -21846 | 0 | 37 | 21845 |
| 58 | -21846 | 0 | 45 | 21845 |
| 58 | -21846 | 0 | 53 | 21845 |
| 58 | -21846 | 0 | 61 | 21845 |
| 58+ | 21845 | 1 | 5 | -21846 |
| 59 | 21845 | 1 | 5 | 21845 |
| 59+ | -21846 | 1 | 13 | 21845 |
| 60 | -21846 | 1 | 13 | -21846 |
| 60+ | -21846 | 0 | 5 | 21845 |
| 61 | -21846 | 0 | 5 | 21845 |
| 61 | -21846 | 0 | 13 | -21846 |
| 61 | -21846 | 0 | 21 | 21845 |
| 61 | -21846 | 0 | 29 | 21845 |
| 61 | -21846 | 0 | 37 | 21845 |
| 61 | -21846 | 0 | 45 | 21845 |
| 61 | -21846 | 0 | 53 | 21845 |
| 61 | -21846 | 0 | 61 | 21845 |
| 61+ | 21845 | 1 | 13 | -21846 |
| 62 | 21845 | 1 | 13 | 21845 |
| 62+ | -21846 | 1 | 21 | 21845 |
| 63 | -21846 | 1 | 21 | -21846 |
| 63+ | -21846 | 0 | 5 | 21845 |
| 64 | -21846 | 0 | 5 | 21845 |
| 64 | -21846 | 0 | 13 | 21845 |
| 64 | -21846 | 0 | 21 | -21846 |
| 64 | -21846 | 0 | 29 | 21845 |
| 64 | -21846 | 0 | 37 | 21845 |
| 64 | -21846 | 0 | 45 | 21845 |
| 64 | -21846 | 0 | 53 | 21845 |
| 64 | -21846 | 0 | 61 | 21845 |
| 64+ | 21845 | 1 | 21 | -21846 |
| 65 | 21845 | 1 | 21 | 21845 |
| 65+ | -21846 | 1 | 29 | 21845 |
| 66 | -21846 | 1 | 29 | -21846 |
| 66+ | -21846 | 0 | 5 | 21845 |
| 67 | -21846 | 0 | 5 | 21845 |
| 67 | -21846 | 0 | 13 | 21845 |
| 67 | -21846 | 0 | 21 | 21845 |
| 67 | -21846 | 0 | 29 | -21846 |
| 67 | -21846 | 0 | 37 | 21845 |
| 67 | -21846 | 0 | 45 | 21845 |
| 67 | -21846 | 0 | 53 | 21845 |
| 67 | -21846 | 0 | 61 | 21845 |
| 67+ | 21845 | 1 | 29 | -21846 |
| 68 | 21845 | 1 | 29 | 21845 |
| 68+ | -21846 | 1 | 37 | 21845 |
| 69 | -21846 | 1 | 37 | -21846 |
| 69+ | -21846 | 0 | 5 | 21845 |
| 70 | -21846 | 0 | 5 | 21845 |
| 70 | -21846 | 0 | 13 | 21845 |
| 70 | -21846 | 0 | 21 | 21845 |
| 70 | -21846 | 0 | 29 | 21845 |
| 70 | -21846 | 0 | 37 | -21846 |
| 70 | -21846 | 0 | 45 | 21845 |
| 70 | -21846 | 0 | 53 | 21845 |
| 70 | -21846 | 0 | 61 | 21845 |
| 70+ | 21845 | 1 | 37 | -21846 |
| 71 | 21845 | 1 | 37 | 21845 |
| 71+ | -21846 | 1 | 45 | 21845 |
| 72 | -21846 | 1 | 45 | -21846 |
| 72+ | -21846 | 0 | 5 | 21845 |
| 73 | -21846 | 0 | 5 | 21845 |
| 73 | -21846 | 0 | 13 | 21845 |
| 73 | -21846 | 0 | 21 | 21845 |
| 73 | -21846 | 0 | 29 | 21845 |
| 73 | -21846 | 0 | 37 | 21845 |
| 73 | -21846 | 0 | 45 | -21846 |
| 73 | -21846 | 0 | 53 | 21845 |
| 73 | -21846 | 0 | 61 | 21845 |
| 73+ | 21845 | 1 | 45 | -21846 |
| 74 | 21845 | 1 | 45 | 21845 |
| 74+ | -21846 | 1 | 53 | 21845 |
| 75 | -21846 | 1 | 53 | -21846 |
| 75+ | -21846 | 0 | 5 | 21845 |
| 76 | -21846 | 0 | 5 | 21845 |
| 76 | -21846 | 0 | 13 | 21845 |
| 76 | -21846 | 0 | 21 | 21845 |
| 76 | -21846 | 0 | 29 | 21845 |
| 76 | -21846 | 0 | 37 | 21845 |
| 76 | -21846 | 0 | 45 | 21845 |
| 76 | -21846 | 0 | 53 | -21846 |
| 76 | -21846 | 0 | 61 | 21845 |
| 76+ | 21845 | 1 | 53 | -21846 |
| 77 | 21845 | 1 | 53 | 21845 |
| 77+ | -21846 | 1 | 61 | 21845 |
| 78 | -21846 | 1 | 61 | -21846 |
| 78+ | -21846 | 0 | 5 | 21845 |
| 79 | -21846 | 0 | 5 | 21845 |
| 79 | -21846 | 0 | 13 | 21845 |
| 79 | -21846 | 0 | 21 | 21845 |
| 79 | -21846 | 0 | 29 | 21845 |
| 79 | -21846 | 0 | 37 | 21845 |
| 79 | -21846 | 0 | 45 | 21845 |
| 79 | -21846 | 0 | 53 | 21845 |
| 79 | -21846 | 0 | 61 | -21846 |
| 79+ | 21845 | 1 | 61 | -21846 |
| 80 | 21845 | 1 | 61 | 21845 |
| 80+ | 21845 | 0 | 5 | 21845 |
| 81 | 21845 | 0 | 5 | 21845 |
| 81 | 21845 | 0 | 13 | 21845 |
| 81 | 21845 | 0 | 21 | 21845 |
| 81 | 21845 | 0 | 29 | 21845 |
| 81 | 21845 | 0 | 37 | 21845 |
| 81 | 21845 | 0 | 45 | 21845 |
| 81 | 21845 | 0 | 53 | 21845 |
| 81 | 21845 | 0 | 61 | 21845 |

29
projects/03/a/RAM64.hdl Normal file
View File

@@ -0,0 +1,29 @@
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/03/a/RAM64.hdl
/**
* Memory of 64 registers, each 16 bit-wide. Out holds the value
* stored at the memory location specified by address. If load==1, then
* the in value is loaded into the memory location specified by address
* (the loaded value will be emitted to out from the next time step onward).
*/
CHIP RAM64 {
IN in[16], load, address[6];
OUT out[16];
PARTS:
RAM8(in=in, load=load1, address=address[0..2], out=out1);
RAM8(in=in, load=load2, address=address[0..2], out=out2);
RAM8(in=in, load=load3, address=address[0..2], out=out3);
RAM8(in=in, load=load4, address=address[0..2], out=out4);
RAM8(in=in, load=load5, address=address[0..2], out=out5);
RAM8(in=in, load=load6, address=address[0..2], out=out6);
RAM8(in=in, load=load7, address=address[0..2], out=out7);
RAM8(in=in, load=load8, address=address[0..2], out=out8);
DMux8Way(in=load, sel=address[3..5], a=load1, b=load2, c=load3, d=load4, e=load5, f=load6, g=load7, h=load8);
Mux8Way16(a=out1, b=out2, c=out3, d=out4, e=out5, f=out6, g=out7, h=out8, sel=address[3..5], out=out);
}

1026
projects/03/a/RAM64.tst Normal file

File diff suppressed because it is too large Load Diff

173
projects/03/a/RAM8.cmp Normal file
View File

@@ -0,0 +1,173 @@
| time | in |load |address| out |
| 0+ | 0 | 0 | 0 | 0 |
| 1 | 0 | 0 | 0 | 0 |
| 1+ | 0 | 1 | 0 | 0 |
| 2 | 0 | 1 | 0 | 0 |
| 2+ | 11111 | 0 | 0 | 0 |
| 3 | 11111 | 0 | 0 | 0 |
| 3+ | 11111 | 1 | 1 | 0 |
| 4 | 11111 | 1 | 1 | 11111 |
| 4+ | 11111 | 0 | 0 | 0 |
| 5 | 11111 | 0 | 0 | 0 |
| 5+ | 3333 | 0 | 3 | 0 |
| 6 | 3333 | 0 | 3 | 0 |
| 6+ | 3333 | 1 | 3 | 0 |
| 7 | 3333 | 1 | 3 | 3333 |
| 7+ | 3333 | 0 | 3 | 3333 |
| 8 | 3333 | 0 | 3 | 3333 |
| 8 | 3333 | 0 | 1 | 11111 |
| 8+ | 7777 | 0 | 1 | 11111 |
| 9 | 7777 | 0 | 1 | 11111 |
| 9+ | 7777 | 1 | 7 | 0 |
| 10 | 7777 | 1 | 7 | 7777 |
| 10+ | 7777 | 0 | 7 | 7777 |
| 11 | 7777 | 0 | 7 | 7777 |
| 11 | 7777 | 0 | 3 | 3333 |
| 11 | 7777 | 0 | 7 | 7777 |
| 11+ | 7777 | 0 | 0 | 0 |
| 12 | 7777 | 0 | 0 | 0 |
| 12 | 7777 | 0 | 1 | 11111 |
| 12 | 7777 | 0 | 2 | 0 |
| 12 | 7777 | 0 | 3 | 3333 |
| 12 | 7777 | 0 | 4 | 0 |
| 12 | 7777 | 0 | 5 | 0 |
| 12 | 7777 | 0 | 6 | 0 |
| 12 | 7777 | 0 | 7 | 7777 |
| 12+ | 21845 | 1 | 0 | 0 |
| 13 | 21845 | 1 | 0 | 21845 |
| 13+ | 21845 | 1 | 1 | 11111 |
| 14 | 21845 | 1 | 1 | 21845 |
| 14+ | 21845 | 1 | 2 | 0 |
| 15 | 21845 | 1 | 2 | 21845 |
| 15+ | 21845 | 1 | 3 | 3333 |
| 16 | 21845 | 1 | 3 | 21845 |
| 16+ | 21845 | 1 | 4 | 0 |
| 17 | 21845 | 1 | 4 | 21845 |
| 17+ | 21845 | 1 | 5 | 0 |
| 18 | 21845 | 1 | 5 | 21845 |
| 18+ | 21845 | 1 | 6 | 0 |
| 19 | 21845 | 1 | 6 | 21845 |
| 19+ | 21845 | 1 | 7 | 7777 |
| 20 | 21845 | 1 | 7 | 21845 |
| 20+ | 21845 | 0 | 0 | 21845 |
| 21 | 21845 | 0 | 0 | 21845 |
| 21 | 21845 | 0 | 1 | 21845 |
| 21 | 21845 | 0 | 2 | 21845 |
| 21 | 21845 | 0 | 3 | 21845 |
| 21 | 21845 | 0 | 4 | 21845 |
| 21 | 21845 | 0 | 5 | 21845 |
| 21 | 21845 | 0 | 6 | 21845 |
| 21 | 21845 | 0 | 7 | 21845 |
| 21+ | -21846 | 1 | 0 | 21845 |
| 22 | -21846 | 1 | 0 | -21846 |
| 22+ | -21846 | 0 | 0 | -21846 |
| 23 | -21846 | 0 | 0 | -21846 |
| 23 | -21846 | 0 | 1 | 21845 |
| 23 | -21846 | 0 | 2 | 21845 |
| 23 | -21846 | 0 | 3 | 21845 |
| 23 | -21846 | 0 | 4 | 21845 |
| 23 | -21846 | 0 | 5 | 21845 |
| 23 | -21846 | 0 | 6 | 21845 |
| 23 | -21846 | 0 | 7 | 21845 |
| 23+ | 21845 | 1 | 0 | -21846 |
| 24 | 21845 | 1 | 0 | 21845 |
| 24+ | -21846 | 1 | 1 | 21845 |
| 25 | -21846 | 1 | 1 | -21846 |
| 25+ | -21846 | 0 | 0 | 21845 |
| 26 | -21846 | 0 | 0 | 21845 |
| 26 | -21846 | 0 | 1 | -21846 |
| 26 | -21846 | 0 | 2 | 21845 |
| 26 | -21846 | 0 | 3 | 21845 |
| 26 | -21846 | 0 | 4 | 21845 |
| 26 | -21846 | 0 | 5 | 21845 |
| 26 | -21846 | 0 | 6 | 21845 |
| 26 | -21846 | 0 | 7 | 21845 |
| 26+ | 21845 | 1 | 1 | -21846 |
| 27 | 21845 | 1 | 1 | 21845 |
| 27+ | -21846 | 1 | 2 | 21845 |
| 28 | -21846 | 1 | 2 | -21846 |
| 28+ | -21846 | 0 | 0 | 21845 |
| 29 | -21846 | 0 | 0 | 21845 |
| 29 | -21846 | 0 | 1 | 21845 |
| 29 | -21846 | 0 | 2 | -21846 |
| 29 | -21846 | 0 | 3 | 21845 |
| 29 | -21846 | 0 | 4 | 21845 |
| 29 | -21846 | 0 | 5 | 21845 |
| 29 | -21846 | 0 | 6 | 21845 |
| 29 | -21846 | 0 | 7 | 21845 |
| 29+ | 21845 | 1 | 2 | -21846 |
| 30 | 21845 | 1 | 2 | 21845 |
| 30+ | -21846 | 1 | 3 | 21845 |
| 31 | -21846 | 1 | 3 | -21846 |
| 31+ | -21846 | 0 | 0 | 21845 |
| 32 | -21846 | 0 | 0 | 21845 |
| 32 | -21846 | 0 | 1 | 21845 |
| 32 | -21846 | 0 | 2 | 21845 |
| 32 | -21846 | 0 | 3 | -21846 |
| 32 | -21846 | 0 | 4 | 21845 |
| 32 | -21846 | 0 | 5 | 21845 |
| 32 | -21846 | 0 | 6 | 21845 |
| 32 | -21846 | 0 | 7 | 21845 |
| 32+ | 21845 | 1 | 3 | -21846 |
| 33 | 21845 | 1 | 3 | 21845 |
| 33+ | -21846 | 1 | 4 | 21845 |
| 34 | -21846 | 1 | 4 | -21846 |
| 34+ | -21846 | 0 | 0 | 21845 |
| 35 | -21846 | 0 | 0 | 21845 |
| 35 | -21846 | 0 | 1 | 21845 |
| 35 | -21846 | 0 | 2 | 21845 |
| 35 | -21846 | 0 | 3 | 21845 |
| 35 | -21846 | 0 | 4 | -21846 |
| 35 | -21846 | 0 | 5 | 21845 |
| 35 | -21846 | 0 | 6 | 21845 |
| 35 | -21846 | 0 | 7 | 21845 |
| 35+ | 21845 | 1 | 4 | -21846 |
| 36 | 21845 | 1 | 4 | 21845 |
| 36+ | -21846 | 1 | 5 | 21845 |
| 37 | -21846 | 1 | 5 | -21846 |
| 37+ | -21846 | 0 | 0 | 21845 |
| 38 | -21846 | 0 | 0 | 21845 |
| 38 | -21846 | 0 | 1 | 21845 |
| 38 | -21846 | 0 | 2 | 21845 |
| 38 | -21846 | 0 | 3 | 21845 |
| 38 | -21846 | 0 | 4 | 21845 |
| 38 | -21846 | 0 | 5 | -21846 |
| 38 | -21846 | 0 | 6 | 21845 |
| 38 | -21846 | 0 | 7 | 21845 |
| 38+ | 21845 | 1 | 5 | -21846 |
| 39 | 21845 | 1 | 5 | 21845 |
| 39+ | -21846 | 1 | 6 | 21845 |
| 40 | -21846 | 1 | 6 | -21846 |
| 40+ | -21846 | 0 | 0 | 21845 |
| 41 | -21846 | 0 | 0 | 21845 |
| 41 | -21846 | 0 | 1 | 21845 |
| 41 | -21846 | 0 | 2 | 21845 |
| 41 | -21846 | 0 | 3 | 21845 |
| 41 | -21846 | 0 | 4 | 21845 |
| 41 | -21846 | 0 | 5 | 21845 |
| 41 | -21846 | 0 | 6 | -21846 |
| 41 | -21846 | 0 | 7 | 21845 |
| 41+ | 21845 | 1 | 6 | -21846 |
| 42 | 21845 | 1 | 6 | 21845 |
| 42+ | -21846 | 1 | 7 | 21845 |
| 43 | -21846 | 1 | 7 | -21846 |
| 43+ | -21846 | 0 | 0 | 21845 |
| 44 | -21846 | 0 | 0 | 21845 |
| 44 | -21846 | 0 | 1 | 21845 |
| 44 | -21846 | 0 | 2 | 21845 |
| 44 | -21846 | 0 | 3 | 21845 |
| 44 | -21846 | 0 | 4 | 21845 |
| 44 | -21846 | 0 | 5 | 21845 |
| 44 | -21846 | 0 | 6 | 21845 |
| 44 | -21846 | 0 | 7 | -21846 |
| 44+ | 21845 | 1 | 7 | -21846 |
| 45 | 21845 | 1 | 7 | 21845 |
| 45+ | 21845 | 0 | 0 | 21845 |
| 46 | 21845 | 0 | 0 | 21845 |
| 46 | 21845 | 0 | 1 | 21845 |
| 46 | 21845 | 0 | 2 | 21845 |
| 46 | 21845 | 0 | 3 | 21845 |
| 46 | 21845 | 0 | 4 | 21845 |
| 46 | 21845 | 0 | 5 | 21845 |
| 46 | 21845 | 0 | 6 | 21845 |
| 46 | 21845 | 0 | 7 | 21845 |

29
projects/03/a/RAM8.hdl Normal file
View File

@@ -0,0 +1,29 @@
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/03/a/RAM8.hdl
/**
* Memory of 8 registers, each 16 bit-wide. Out holds the value
* stored at the memory location specified by address. If load==1, then
* the in value is loaded into the memory location specified by address
* (the loaded value will be emitted to out from the next time step onward).
*/
CHIP RAM8 {
IN in[16], load, address[3];
OUT out[16];
PARTS:
Register(in=in, load=reg0l, out=reg0);
Register(in=in, load=reg1l, out=reg1);
Register(in=in, load=reg2l, out=reg2);
Register(in=in, load=reg3l, out=reg3);
Register(in=in, load=reg4l, out=reg4);
Register(in=in, load=reg5l, out=reg5);
Register(in=in, load=reg6l, out=reg6);
Register(in=in, load=reg7l, out=reg7);
DMux8Way(in=load, sel=address, a=reg0l, b=reg1l, c=reg2l, d=reg3l, e=reg4l, f=reg5l, g=reg6l, h=reg7l);
Mux8Way16(a=reg0, b=reg1, c=reg2, d=reg3, e=reg4, f=reg5, g=reg6, h=reg7, sel=address, out=out);
}

560
projects/03/a/RAM8.tst Normal file
View File

@@ -0,0 +1,560 @@
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/03/a/RAM8.tst
load RAM8.hdl,
output-file RAM8.out,
compare-to RAM8.cmp,
output-list time%S1.4.1 in%D1.6.1 load%B2.1.2 address%D3.1.3 out%D1.6.1;
set in 0,
set load 0,
set address 0,
tick,
output;
tock,
output;
set load 1,
tick,
output;
tock,
output;
set in 11111,
set load 0,
tick,
output;
tock,
output;
set load 1,
set address 1,
tick,
output;
tock,
output;
set load 0,
set address 0,
tick,
output;
tock,
output;
set in 3333,
set address 3,
tick,
output;
tock,
output;
set load 1,
tick,
output;
tock,
output;
set load 0,
tick,
output;
tock,
output;
set address 1,
eval,
output;
set in 7777,
tick,
output;
tock,
output;
set load 1,
set address 7,
tick,
output;
tock,
output;
set load 0,
tick,
output;
tock,
output;
set address 3,
eval,
output;
set address 7,
eval,
output;
set load 0,
set address 0,
tick,
output;
tock,
output;
set address 1,
eval,
output;
set address 2,
eval,
output;
set address 3,
eval,
output;
set address 4,
eval,
output;
set address 5,
eval,
output;
set address 6,
eval,
output;
set address 7,
eval,
output;
set load 1,
set in %B0101010101010101,
set address 0,
tick,
output;
tock,
output;
set address 1,
tick,
output,
tock,
output;
set address 2,
tick,
output,
tock,
output;
set address 3,
tick,
output,
tock,
output;
set address 4,
tick,
output,
tock,
output;
set address 5,
tick,
output,
tock,
output;
set address 6,
tick,
output,
tock,
output;
set address 7,
tick,
output,
tock,
output;
set load 0,
set address 0,
tick,
output;
tock,
output;
set address 1,
eval,
output;
set address 2,
eval,
output;
set address 3,
eval,
output;
set address 4,
eval,
output;
set address 5,
eval,
output;
set address 6,
eval,
output;
set address 7,
eval,
output;
set load 1,
set address 0,
set in %B1010101010101010,
tick,
output;
tock,
output;
set load 0,
set address 0,
tick,
output;
tock,
output;
set address 1,
eval,
output;
set address 2,
eval,
output;
set address 3,
eval,
output;
set address 4,
eval,
output;
set address 5,
eval,
output;
set address 6,
eval,
output;
set address 7,
eval,
output;
set load 1,
set address 0,
set in %B0101010101010101,
tick,
output,
tock,
output;
set address 1,
set in %B1010101010101010,
tick,
output;
tock,
output;
set load 0,
set address 0,
tick,
output;
tock,
output;
set address 1,
eval,
output;
set address 2,
eval,
output;
set address 3,
eval,
output;
set address 4,
eval,
output;
set address 5,
eval,
output;
set address 6,
eval,
output;
set address 7,
eval,
output;
set load 1,
set address 1,
set in %B0101010101010101,
tick,
output,
tock,
output;
set address 2,
set in %B1010101010101010,
tick,
output;
tock,
output;
set load 0,
set address 0,
tick,
output;
tock,
output;
set address 1,
eval,
output;
set address 2,
eval,
output;
set address 3,
eval,
output;
set address 4,
eval,
output;
set address 5,
eval,
output;
set address 6,
eval,
output;
set address 7,
eval,
output;
set load 1,
set address 2,
set in %B0101010101010101,
tick,
output,
tock,
output;
set address 3,
set in %B1010101010101010,
tick,
output;
tock,
output;
set load 0,
set address 0,
tick,
output;
tock,
output;
set address 1,
eval,
output;
set address 2,
eval,
output;
set address 3,
eval,
output;
set address 4,
eval,
output;
set address 5,
eval,
output;
set address 6,
eval,
output;
set address 7,
eval,
output;
set load 1,
set address 3,
set in %B0101010101010101,
tick,
output,
tock,
output;
set address 4,
set in %B1010101010101010,
tick,
output;
tock,
output;
set load 0,
set address 0,
tick,
output;
tock,
output;
set address 1,
eval,
output;
set address 2,
eval,
output;
set address 3,
eval,
output;
set address 4,
eval,
output;
set address 5,
eval,
output;
set address 6,
eval,
output;
set address 7,
eval,
output;
set load 1,
set address 4,
set in %B0101010101010101,
tick,
output,
tock,
output;
set address 5,
set in %B1010101010101010,
tick,
output;
tock,
output;
set load 0,
set address 0,
tick,
output;
tock,
output;
set address 1,
eval,
output;
set address 2,
eval,
output;
set address 3,
eval,
output;
set address 4,
eval,
output;
set address 5,
eval,
output;
set address 6,
eval,
output;
set address 7,
eval,
output;
set load 1,
set address 5,
set in %B0101010101010101,
tick,
output,
tock,
output;
set address 6,
set in %B1010101010101010,
tick,
output;
tock,
output;
set load 0,
set address 0,
tick,
output;
tock,
output;
set address 1,
eval,
output;
set address 2,
eval,
output;
set address 3,
eval,
output;
set address 4,
eval,
output;
set address 5,
eval,
output;
set address 6,
eval,
output;
set address 7,
eval,
output;
set load 1,
set address 6,
set in %B0101010101010101,
tick,
output,
tock,
output;
set address 7,
set in %B1010101010101010,
tick,
output;
tock,
output;
set load 0,
set address 0,
tick,
output;
tock,
output;
set address 1,
eval,
output;
set address 2,
eval,
output;
set address 3,
eval,
output;
set address 4,
eval,
output;
set address 5,
eval,
output;
set address 6,
eval,
output;
set address 7,
eval,
output;
set load 1,
set address 7,
set in %B0101010101010101,
tick,
output,
tock,
output;
set load 0,
set address 0,
tick,
output;
tock,
output;
set address 1,
eval,
output;
set address 2,
eval,
output;
set address 3,
eval,
output;
set address 4,
eval,
output;
set address 5,
eval,
output;
set address 6,
eval,
output;
set address 7,
eval,
output;

149
projects/03/a/Register.cmp Normal file
View File

@@ -0,0 +1,149 @@
| time | in |load | out |
| 0+ | 0 | 0 | 0 |
| 1 | 0 | 0 | 0 |
| 1+ | 0 | 1 | 0 |
| 2 | 0 | 1 | 0 |
| 2+ | -32123 | 0 | 0 |
| 3 | -32123 | 0 | 0 |
| 3+ | 11111 | 0 | 0 |
| 4 | 11111 | 0 | 0 |
| 4+ | -32123 | 1 | 0 |
| 5 | -32123 | 1 | -32123 |
| 5+ | -32123 | 1 | -32123 |
| 6 | -32123 | 1 | -32123 |
| 6+ | -32123 | 0 | -32123 |
| 7 | -32123 | 0 | -32123 |
| 7+ | 12345 | 1 | -32123 |
| 8 | 12345 | 1 | 12345 |
| 8+ | 0 | 0 | 12345 |
| 9 | 0 | 0 | 12345 |
| 9+ | 0 | 1 | 12345 |
| 10 | 0 | 1 | 0 |
| 10+ | 1 | 0 | 0 |
| 11 | 1 | 0 | 0 |
| 11+ | 1 | 1 | 0 |
| 12 | 1 | 1 | 1 |
| 12+ | 2 | 0 | 1 |
| 13 | 2 | 0 | 1 |
| 13+ | 2 | 1 | 1 |
| 14 | 2 | 1 | 2 |
| 14+ | 4 | 0 | 2 |
| 15 | 4 | 0 | 2 |
| 15+ | 4 | 1 | 2 |
| 16 | 4 | 1 | 4 |
| 16+ | 8 | 0 | 4 |
| 17 | 8 | 0 | 4 |
| 17+ | 8 | 1 | 4 |
| 18 | 8 | 1 | 8 |
| 18+ | 16 | 0 | 8 |
| 19 | 16 | 0 | 8 |
| 19+ | 16 | 1 | 8 |
| 20 | 16 | 1 | 16 |
| 20+ | 32 | 0 | 16 |
| 21 | 32 | 0 | 16 |
| 21+ | 32 | 1 | 16 |
| 22 | 32 | 1 | 32 |
| 22+ | 64 | 0 | 32 |
| 23 | 64 | 0 | 32 |
| 23+ | 64 | 1 | 32 |
| 24 | 64 | 1 | 64 |
| 24+ | 128 | 0 | 64 |
| 25 | 128 | 0 | 64 |
| 25+ | 128 | 1 | 64 |
| 26 | 128 | 1 | 128 |
| 26+ | 256 | 0 | 128 |
| 27 | 256 | 0 | 128 |
| 27+ | 256 | 1 | 128 |
| 28 | 256 | 1 | 256 |
| 28+ | 512 | 0 | 256 |
| 29 | 512 | 0 | 256 |
| 29+ | 512 | 1 | 256 |
| 30 | 512 | 1 | 512 |
| 30+ | 1024 | 0 | 512 |
| 31 | 1024 | 0 | 512 |
| 31+ | 1024 | 1 | 512 |
| 32 | 1024 | 1 | 1024 |
| 32+ | 2048 | 0 | 1024 |
| 33 | 2048 | 0 | 1024 |
| 33+ | 2048 | 1 | 1024 |
| 34 | 2048 | 1 | 2048 |
| 34+ | 4096 | 0 | 2048 |
| 35 | 4096 | 0 | 2048 |
| 35+ | 4096 | 1 | 2048 |
| 36 | 4096 | 1 | 4096 |
| 36+ | 8192 | 0 | 4096 |
| 37 | 8192 | 0 | 4096 |
| 37+ | 8192 | 1 | 4096 |
| 38 | 8192 | 1 | 8192 |
| 38+ | 16384 | 0 | 8192 |
| 39 | 16384 | 0 | 8192 |
| 39+ | 16384 | 1 | 8192 |
| 40 | 16384 | 1 | 16384 |
| 40+ | -32768 | 0 | 16384 |
| 41 | -32768 | 0 | 16384 |
| 41+ | -32768 | 1 | 16384 |
| 42 | -32768 | 1 | -32768 |
| 42+ | -2 | 0 | -32768 |
| 43 | -2 | 0 | -32768 |
| 43+ | -2 | 1 | -32768 |
| 44 | -2 | 1 | -2 |
| 44+ | -3 | 0 | -2 |
| 45 | -3 | 0 | -2 |
| 45+ | -3 | 1 | -2 |
| 46 | -3 | 1 | -3 |
| 46+ | -5 | 0 | -3 |
| 47 | -5 | 0 | -3 |
| 47+ | -5 | 1 | -3 |
| 48 | -5 | 1 | -5 |
| 48+ | -9 | 0 | -5 |
| 49 | -9 | 0 | -5 |
| 49+ | -9 | 1 | -5 |
| 50 | -9 | 1 | -9 |
| 50+ | -17 | 0 | -9 |
| 51 | -17 | 0 | -9 |
| 51+ | -17 | 1 | -9 |
| 52 | -17 | 1 | -17 |
| 52+ | -33 | 0 | -17 |
| 53 | -33 | 0 | -17 |
| 53+ | -33 | 1 | -17 |
| 54 | -33 | 1 | -33 |
| 54+ | -65 | 0 | -33 |
| 55 | -65 | 0 | -33 |
| 55+ | -65 | 1 | -33 |
| 56 | -65 | 1 | -65 |
| 56+ | -129 | 0 | -65 |
| 57 | -129 | 0 | -65 |
| 57+ | -129 | 1 | -65 |
| 58 | -129 | 1 | -129 |
| 58+ | -257 | 0 | -129 |
| 59 | -257 | 0 | -129 |
| 59+ | -257 | 1 | -129 |
| 60 | -257 | 1 | -257 |
| 60+ | -513 | 0 | -257 |
| 61 | -513 | 0 | -257 |
| 61+ | -513 | 1 | -257 |
| 62 | -513 | 1 | -513 |
| 62+ | -1025 | 0 | -513 |
| 63 | -1025 | 0 | -513 |
| 63+ | -1025 | 1 | -513 |
| 64 | -1025 | 1 | -1025 |
| 64+ | -2049 | 0 | -1025 |
| 65 | -2049 | 0 | -1025 |
| 65+ | -2049 | 1 | -1025 |
| 66 | -2049 | 1 | -2049 |
| 66+ | -4097 | 0 | -2049 |
| 67 | -4097 | 0 | -2049 |
| 67+ | -4097 | 1 | -2049 |
| 68 | -4097 | 1 | -4097 |
| 68+ | -8193 | 0 | -4097 |
| 69 | -8193 | 0 | -4097 |
| 69+ | -8193 | 1 | -4097 |
| 70 | -8193 | 1 | -8193 |
| 70+ | -16385 | 0 | -8193 |
| 71 | -16385 | 0 | -8193 |
| 71+ | -16385 | 1 | -8193 |
| 72 | -16385 | 1 | -16385 |
| 72+ | 32767 | 0 | -16385 |
| 73 | 32767 | 0 | -16385 |
| 73+ | 32767 | 1 | -16385 |
| 74 | 32767 | 1 | 32767 |

View File

@@ -0,0 +1,33 @@
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/03/a/Register.hdl
/**
* 16-bit register:
* If load[t] == 1 then out[t+1] = in[t]
* else out does not change
*/
CHIP Register {
IN in[16], load;
OUT out[16];
PARTS:
Bit(in=in[0], load=load, out=out[0]);
Bit(in=in[1], load=load, out=out[1]);
Bit(in=in[2], load=load, out=out[2]);
Bit(in=in[3], load=load, out=out[3]);
Bit(in=in[4], load=load, out=out[4]);
Bit(in=in[5], load=load, out=out[5]);
Bit(in=in[6], load=load, out=out[6]);
Bit(in=in[7], load=load, out=out[7]);
Bit(in=in[8], load=load, out=out[8]);
Bit(in=in[9], load=load, out=out[9]);
Bit(in=in[10], load=load, out=out[10]);
Bit(in=in[11], load=load, out=out[11]);
Bit(in=in[12], load=load, out=out[12]);
Bit(in=in[13], load=load, out=out[13]);
Bit(in=in[14], load=load, out=out[14]);
Bit(in=in[15], load=load, out=out[15]);
}

569
projects/03/a/Register.tst Normal file
View File

@@ -0,0 +1,569 @@
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/03/a/Register.tst
load Register.hdl,
output-file Register.out,
compare-to Register.cmp,
output-list time%S1.4.1 in%D1.6.1 load%B2.1.2 out%D1.6.1;
set in 0,
set load 0,
tick,
output;
tock,
output;
set in 0,
set load 1,
tick,
output;
tock,
output;
set in -32123,
set load 0,
tick,
output;
tock,
output;
set in 11111,
set load 0,
tick,
output;
tock,
output;
set in -32123,
set load 1,
tick,
output;
tock,
output;
set in -32123,
set load 1,
tick,
output;
tock,
output;
set in -32123,
set load 0,
tick,
output;
tock,
output;
set in 12345,
set load 1,
tick,
output;
tock,
output;
set in 0,
set load 0,
tick,
output;
tock,
output;
set in 0,
set load 1,
tick,
output;
tock,
output;
set in %B0000000000000001,
set load 0,
tick,
output;
tock,
output;
set load 1,
tick,
output;
tock,
output;
set in %B0000000000000010,
set load 0,
tick,
output;
tock,
output;
set load 1,
tick,
output;
tock,
output;
set in %B0000000000000100,
set load 0,
tick,
output;
tock,
output;
set load 1,
tick,
output;
tock,
output;
set in %B0000000000001000,
set load 0,
tick,
output;
tock,
output;
set load 1,
tick,
output;
tock,
output;
set in %B0000000000010000,
set load 0,
tick,
output;
tock,
output;
set load 1,
tick,
output;
tock,
output;
set in %B0000000000100000,
set load 0,
tick,
output;
tock,
output;
set load 1,
tick,
output;
tock,
output;
set in %B0000000001000000,
set load 0,
tick,
output;
tock,
output;
set load 1,
tick,
output;
tock,
output;
set in %B0000000010000000,
set load 0,
tick,
output;
tock,
output;
set load 1,
tick,
output;
tock,
output;
set in %B0000000100000000,
set load 0,
tick,
output;
tock,
output;
set load 1,
tick,
output;
tock,
output;
set in %B0000001000000000,
set load 0,
tick,
output;
tock,
output;
set load 1,
tick,
output;
tock,
output;
set in %B0000010000000000,
set load 0,
tick,
output;
tock,
output;
set load 1,
tick,
output;
tock,
output;
set in %B0000100000000000,
set load 0,
tick,
output;
tock,
output;
set load 1,
tick,
output;
tock,
output;
set in %B0001000000000000,
set load 0,
tick,
output;
tock,
output;
set load 1,
tick,
output;
tock,
output;
set in %B0010000000000000,
set load 0,
tick,
output;
tock,
output;
set load 1,
tick,
output;
tock,
output;
set in %B0100000000000000,
set load 0,
tick,
output;
tock,
output;
set load 1,
tick,
output;
tock,
output;
set in %B1000000000000000,
set load 0,
tick,
output;
tock,
output;
set load 1,
tick,
output;
tock,
output;
set in %B1111111111111110,
set load 0,
tick,
output;
tock,
output;
set load 1,
tick,
output;
tock,
output;
set in %B1111111111111101,
set load 0,
tick,
output;
tock,
output;
set load 1,
tick,
output;
tock,
output;
set in %B1111111111111011,
set load 0,
tick,
output;
tock,
output;
set load 1,
tick,
output;
tock,
output;
set in %B1111111111110111,
set load 0,
tick,
output;
tock,
output;
set load 1,
tick,
output;
tock,
output;
set in %B1111111111101111,
set load 0,
tick,
output;
tock,
output;
set load 1,
tick,
output;
tock,
output;
set in %B1111111111011111,
set load 0,
tick,
output;
tock,
output;
set load 1,
tick,
output;
tock,
output;
set in %B1111111110111111,
set load 0,
tick,
output;
tock,
output;
set load 1,
tick,
output;
tock,
output;
set in %B1111111101111111,
set load 0,
tick,
output;
tock,
output;
set load 1,
tick,
output;
tock,
output;
set in %B1111111011111111,
set load 0,
tick,
output;
tock,
output;
set load 1,
tick,
output;
tock,
output;
set in %B1111110111111111,
set load 0,
tick,
output;
tock,
output;
set load 1,
tick,
output;
tock,
output;
set in %B1111101111111111,
set load 0,
tick,
output;
tock,
output;
set load 1,
tick,
output;
tock,
output;
set in %B1111011111111111,
set load 0,
tick,
output;
tock,
output;
set load 1,
tick,
output;
tock,
output;
set in %B1110111111111111,
set load 0,
tick,
output;
tock,
output;
set load 1,
tick,
output;
tock,
output;
set in %B1101111111111111,
set load 0,
tick,
output;
tock,
output;
set load 1,
tick,
output;
tock,
output;
set in %B1011111111111111,
set load 0,
tick,
output;
tock,
output;
set load 1,
tick,
output;
tock,
output;
set in %B0111111111111111,
set load 0,
tick,
output;
tock,
output;
set load 1,
tick,
output;
tock,
output;

320
projects/03/b/RAM16K.cmp Normal file
View File

@@ -0,0 +1,320 @@
| time | in |load | address | out |
| 0+ | 0 | 0 | 0 | 0 |
| 1 | 0 | 0 | 0 | 0 |
| 1+ | 0 | 1 | 0 | 0 |
| 2 | 0 | 1 | 0 | 0 |
| 2+ | 4321 | 0 | 0 | 0 |
| 3 | 4321 | 0 | 0 | 0 |
| 3+ | 4321 | 1 | 4321 | 0 |
| 4 | 4321 | 1 | 4321 | 4321 |
| 4+ | 4321 | 0 | 0 | 0 |
| 5 | 4321 | 0 | 0 | 0 |
| 5+ | 12345 | 0 | 12345 | 0 |
| 6 | 12345 | 0 | 12345 | 0 |
| 6+ | 12345 | 1 | 12345 | 0 |
| 7 | 12345 | 1 | 12345 | 12345 |
| 7+ | 12345 | 0 | 12345 | 12345 |
| 8 | 12345 | 0 | 12345 | 12345 |
| 8 | 12345 | 0 | 4321 | 4321 |
| 8+ | 16383 | 0 | 4321 | 4321 |
| 9 | 16383 | 0 | 4321 | 4321 |
| 9+ | 16383 | 1 | 16383 | 0 |
| 10 | 16383 | 1 | 16383 | 16383 |
| 10+ | 16383 | 0 | 16383 | 16383 |
| 11 | 16383 | 0 | 16383 | 16383 |
| 11 | 16383 | 0 | 12345 | 12345 |
| 11 | 16383 | 0 | 16383 | 16383 |
| 11+ | 16383 | 0 | 10920 | 0 |
| 12 | 16383 | 0 | 10920 | 0 |
| 12 | 16383 | 0 | 10921 | 0 |
| 12 | 16383 | 0 | 10922 | 0 |
| 12 | 16383 | 0 | 10923 | 0 |
| 12 | 16383 | 0 | 10924 | 0 |
| 12 | 16383 | 0 | 10925 | 0 |
| 12 | 16383 | 0 | 10926 | 0 |
| 12 | 16383 | 0 | 10927 | 0 |
| 12+ | 21845 | 1 | 10920 | 0 |
| 13 | 21845 | 1 | 10920 | 21845 |
| 13+ | 21845 | 1 | 10921 | 0 |
| 14 | 21845 | 1 | 10921 | 21845 |
| 14+ | 21845 | 1 | 10922 | 0 |
| 15 | 21845 | 1 | 10922 | 21845 |
| 15+ | 21845 | 1 | 10923 | 0 |
| 16 | 21845 | 1 | 10923 | 21845 |
| 16+ | 21845 | 1 | 10924 | 0 |
| 17 | 21845 | 1 | 10924 | 21845 |
| 17+ | 21845 | 1 | 10925 | 0 |
| 18 | 21845 | 1 | 10925 | 21845 |
| 18+ | 21845 | 1 | 10926 | 0 |
| 19 | 21845 | 1 | 10926 | 21845 |
| 19+ | 21845 | 1 | 10927 | 0 |
| 20 | 21845 | 1 | 10927 | 21845 |
| 20+ | 21845 | 0 | 10920 | 21845 |
| 21 | 21845 | 0 | 10920 | 21845 |
| 21 | 21845 | 0 | 10921 | 21845 |
| 21 | 21845 | 0 | 10922 | 21845 |
| 21 | 21845 | 0 | 10923 | 21845 |
| 21 | 21845 | 0 | 10924 | 21845 |
| 21 | 21845 | 0 | 10925 | 21845 |
| 21 | 21845 | 0 | 10926 | 21845 |
| 21 | 21845 | 0 | 10927 | 21845 |
| 21+ | -21846 | 1 | 10920 | 21845 |
| 22 | -21846 | 1 | 10920 | -21846 |
| 22+ | -21846 | 0 | 10920 | -21846 |
| 23 | -21846 | 0 | 10920 | -21846 |
| 23 | -21846 | 0 | 10921 | 21845 |
| 23 | -21846 | 0 | 10922 | 21845 |
| 23 | -21846 | 0 | 10923 | 21845 |
| 23 | -21846 | 0 | 10924 | 21845 |
| 23 | -21846 | 0 | 10925 | 21845 |
| 23 | -21846 | 0 | 10926 | 21845 |
| 23 | -21846 | 0 | 10927 | 21845 |
| 23+ | 21845 | 1 | 10920 | -21846 |
| 24 | 21845 | 1 | 10920 | 21845 |
| 24+ | -21846 | 1 | 10921 | 21845 |
| 25 | -21846 | 1 | 10921 | -21846 |
| 25+ | -21846 | 0 | 10920 | 21845 |
| 26 | -21846 | 0 | 10920 | 21845 |
| 26 | -21846 | 0 | 10921 | -21846 |
| 26 | -21846 | 0 | 10922 | 21845 |
| 26 | -21846 | 0 | 10923 | 21845 |
| 26 | -21846 | 0 | 10924 | 21845 |
| 26 | -21846 | 0 | 10925 | 21845 |
| 26 | -21846 | 0 | 10926 | 21845 |
| 26 | -21846 | 0 | 10927 | 21845 |
| 26+ | 21845 | 1 | 10921 | -21846 |
| 27 | 21845 | 1 | 10921 | 21845 |
| 27+ | -21846 | 1 | 10922 | 21845 |
| 28 | -21846 | 1 | 10922 | -21846 |
| 28+ | -21846 | 0 | 10920 | 21845 |
| 29 | -21846 | 0 | 10920 | 21845 |
| 29 | -21846 | 0 | 10921 | 21845 |
| 29 | -21846 | 0 | 10922 | -21846 |
| 29 | -21846 | 0 | 10923 | 21845 |
| 29 | -21846 | 0 | 10924 | 21845 |
| 29 | -21846 | 0 | 10925 | 21845 |
| 29 | -21846 | 0 | 10926 | 21845 |
| 29 | -21846 | 0 | 10927 | 21845 |
| 29+ | 21845 | 1 | 10922 | -21846 |
| 30 | 21845 | 1 | 10922 | 21845 |
| 30+ | -21846 | 1 | 10923 | 21845 |
| 31 | -21846 | 1 | 10923 | -21846 |
| 31+ | -21846 | 0 | 10920 | 21845 |
| 32 | -21846 | 0 | 10920 | 21845 |
| 32 | -21846 | 0 | 10921 | 21845 |
| 32 | -21846 | 0 | 10922 | 21845 |
| 32 | -21846 | 0 | 10923 | -21846 |
| 32 | -21846 | 0 | 10924 | 21845 |
| 32 | -21846 | 0 | 10925 | 21845 |
| 32 | -21846 | 0 | 10926 | 21845 |
| 32 | -21846 | 0 | 10927 | 21845 |
| 32+ | 21845 | 1 | 10923 | -21846 |
| 33 | 21845 | 1 | 10923 | 21845 |
| 33+ | -21846 | 1 | 10924 | 21845 |
| 34 | -21846 | 1 | 10924 | -21846 |
| 34+ | -21846 | 0 | 10920 | 21845 |
| 35 | -21846 | 0 | 10920 | 21845 |
| 35 | -21846 | 0 | 10921 | 21845 |
| 35 | -21846 | 0 | 10922 | 21845 |
| 35 | -21846 | 0 | 10923 | 21845 |
| 35 | -21846 | 0 | 10924 | -21846 |
| 35 | -21846 | 0 | 10925 | 21845 |
| 35 | -21846 | 0 | 10926 | 21845 |
| 35 | -21846 | 0 | 10927 | 21845 |
| 35+ | 21845 | 1 | 10924 | -21846 |
| 36 | 21845 | 1 | 10924 | 21845 |
| 36+ | -21846 | 1 | 10925 | 21845 |
| 37 | -21846 | 1 | 10925 | -21846 |
| 37+ | -21846 | 0 | 10920 | 21845 |
| 38 | -21846 | 0 | 10920 | 21845 |
| 38 | -21846 | 0 | 10921 | 21845 |
| 38 | -21846 | 0 | 10922 | 21845 |
| 38 | -21846 | 0 | 10923 | 21845 |
| 38 | -21846 | 0 | 10924 | 21845 |
| 38 | -21846 | 0 | 10925 | -21846 |
| 38 | -21846 | 0 | 10926 | 21845 |
| 38 | -21846 | 0 | 10927 | 21845 |
| 38+ | 21845 | 1 | 10925 | -21846 |
| 39 | 21845 | 1 | 10925 | 21845 |
| 39+ | -21846 | 1 | 10926 | 21845 |
| 40 | -21846 | 1 | 10926 | -21846 |
| 40+ | -21846 | 0 | 10920 | 21845 |
| 41 | -21846 | 0 | 10920 | 21845 |
| 41 | -21846 | 0 | 10921 | 21845 |
| 41 | -21846 | 0 | 10922 | 21845 |
| 41 | -21846 | 0 | 10923 | 21845 |
| 41 | -21846 | 0 | 10924 | 21845 |
| 41 | -21846 | 0 | 10925 | 21845 |
| 41 | -21846 | 0 | 10926 | -21846 |
| 41 | -21846 | 0 | 10927 | 21845 |
| 41+ | 21845 | 1 | 10926 | -21846 |
| 42 | 21845 | 1 | 10926 | 21845 |
| 42+ | -21846 | 1 | 10927 | 21845 |
| 43 | -21846 | 1 | 10927 | -21846 |
| 43+ | -21846 | 0 | 10920 | 21845 |
| 44 | -21846 | 0 | 10920 | 21845 |
| 44 | -21846 | 0 | 10921 | 21845 |
| 44 | -21846 | 0 | 10922 | 21845 |
| 44 | -21846 | 0 | 10923 | 21845 |
| 44 | -21846 | 0 | 10924 | 21845 |
| 44 | -21846 | 0 | 10925 | 21845 |
| 44 | -21846 | 0 | 10926 | 21845 |
| 44 | -21846 | 0 | 10927 | -21846 |
| 44+ | 21845 | 1 | 10927 | -21846 |
| 45 | 21845 | 1 | 10927 | 21845 |
| 45+ | 21845 | 0 | 10920 | 21845 |
| 46 | 21845 | 0 | 10920 | 21845 |
| 46 | 21845 | 0 | 10921 | 21845 |
| 46 | 21845 | 0 | 10922 | 21845 |
| 46 | 21845 | 0 | 10923 | 21845 |
| 46 | 21845 | 0 | 10924 | 21845 |
| 46 | 21845 | 0 | 10925 | 21845 |
| 46 | 21845 | 0 | 10926 | 21845 |
| 46 | 21845 | 0 | 10927 | 21845 |
| 46+ | 21845 | 0 | 1365 | 0 |
| 47 | 21845 | 0 | 1365 | 0 |
| 47 | 21845 | 0 | 3413 | 0 |
| 47 | 21845 | 0 | 5461 | 0 |
| 47 | 21845 | 0 | 7509 | 0 |
| 47 | 21845 | 0 | 9557 | 0 |
| 47 | 21845 | 0 | 11605 | 0 |
| 47 | 21845 | 0 | 13653 | 0 |
| 47 | 21845 | 0 | 15701 | 0 |
| 47+ | 21845 | 1 | 1365 | 0 |
| 48 | 21845 | 1 | 1365 | 21845 |
| 48+ | 21845 | 1 | 3413 | 0 |
| 49 | 21845 | 1 | 3413 | 21845 |
| 49+ | 21845 | 1 | 5461 | 0 |
| 50 | 21845 | 1 | 5461 | 21845 |
| 50+ | 21845 | 1 | 7509 | 0 |
| 51 | 21845 | 1 | 7509 | 21845 |
| 51+ | 21845 | 1 | 9557 | 0 |
| 52 | 21845 | 1 | 9557 | 21845 |
| 52+ | 21845 | 1 | 11605 | 0 |
| 53 | 21845 | 1 | 11605 | 21845 |
| 53+ | 21845 | 1 | 13653 | 0 |
| 54 | 21845 | 1 | 13653 | 21845 |
| 54+ | 21845 | 1 | 15701 | 0 |
| 55 | 21845 | 1 | 15701 | 21845 |
| 55+ | 21845 | 0 | 1365 | 21845 |
| 56 | 21845 | 0 | 1365 | 21845 |
| 56 | 21845 | 0 | 3413 | 21845 |
| 56 | 21845 | 0 | 5461 | 21845 |
| 56 | 21845 | 0 | 7509 | 21845 |
| 56 | 21845 | 0 | 9557 | 21845 |
| 56 | 21845 | 0 | 11605 | 21845 |
| 56 | 21845 | 0 | 13653 | 21845 |
| 56 | 21845 | 0 | 15701 | 21845 |
| 56+ | -21846 | 1 | 1365 | 21845 |
| 57 | -21846 | 1 | 1365 | -21846 |
| 57+ | -21846 | 0 | 1365 | -21846 |
| 58 | -21846 | 0 | 1365 | -21846 |
| 58 | -21846 | 0 | 3413 | 21845 |
| 58 | -21846 | 0 | 5461 | 21845 |
| 58 | -21846 | 0 | 7509 | 21845 |
| 58 | -21846 | 0 | 9557 | 21845 |
| 58 | -21846 | 0 | 11605 | 21845 |
| 58 | -21846 | 0 | 13653 | 21845 |
| 58 | -21846 | 0 | 15701 | 21845 |
| 58+ | 21845 | 1 | 1365 | -21846 |
| 59 | 21845 | 1 | 1365 | 21845 |
| 59+ | -21846 | 1 | 3413 | 21845 |
| 60 | -21846 | 1 | 3413 | -21846 |
| 60+ | -21846 | 0 | 1365 | 21845 |
| 61 | -21846 | 0 | 1365 | 21845 |
| 61 | -21846 | 0 | 3413 | -21846 |
| 61 | -21846 | 0 | 5461 | 21845 |
| 61 | -21846 | 0 | 7509 | 21845 |
| 61 | -21846 | 0 | 9557 | 21845 |
| 61 | -21846 | 0 | 11605 | 21845 |
| 61 | -21846 | 0 | 13653 | 21845 |
| 61 | -21846 | 0 | 15701 | 21845 |
| 61+ | 21845 | 1 | 3413 | -21846 |
| 62 | 21845 | 1 | 3413 | 21845 |
| 62+ | -21846 | 1 | 5461 | 21845 |
| 63 | -21846 | 1 | 5461 | -21846 |
| 63+ | -21846 | 0 | 1365 | 21845 |
| 64 | -21846 | 0 | 1365 | 21845 |
| 64 | -21846 | 0 | 3413 | 21845 |
| 64 | -21846 | 0 | 5461 | -21846 |
| 64 | -21846 | 0 | 7509 | 21845 |
| 64 | -21846 | 0 | 9557 | 21845 |
| 64 | -21846 | 0 | 11605 | 21845 |
| 64 | -21846 | 0 | 13653 | 21845 |
| 64 | -21846 | 0 | 15701 | 21845 |
| 64+ | 21845 | 1 | 5461 | -21846 |
| 65 | 21845 | 1 | 5461 | 21845 |
| 65+ | -21846 | 1 | 7509 | 21845 |
| 66 | -21846 | 1 | 7509 | -21846 |
| 66+ | -21846 | 0 | 1365 | 21845 |
| 67 | -21846 | 0 | 1365 | 21845 |
| 67 | -21846 | 0 | 3413 | 21845 |
| 67 | -21846 | 0 | 5461 | 21845 |
| 67 | -21846 | 0 | 7509 | -21846 |
| 67 | -21846 | 0 | 9557 | 21845 |
| 67 | -21846 | 0 | 11605 | 21845 |
| 67 | -21846 | 0 | 13653 | 21845 |
| 67 | -21846 | 0 | 15701 | 21845 |
| 67+ | 21845 | 1 | 7509 | -21846 |
| 68 | 21845 | 1 | 7509 | 21845 |
| 68+ | -21846 | 1 | 9557 | 21845 |
| 69 | -21846 | 1 | 9557 | -21846 |
| 69+ | -21846 | 0 | 1365 | 21845 |
| 70 | -21846 | 0 | 1365 | 21845 |
| 70 | -21846 | 0 | 3413 | 21845 |
| 70 | -21846 | 0 | 5461 | 21845 |
| 70 | -21846 | 0 | 7509 | 21845 |
| 70 | -21846 | 0 | 9557 | -21846 |
| 70 | -21846 | 0 | 11605 | 21845 |
| 70 | -21846 | 0 | 13653 | 21845 |
| 70 | -21846 | 0 | 15701 | 21845 |
| 70+ | 21845 | 1 | 9557 | -21846 |
| 71 | 21845 | 1 | 9557 | 21845 |
| 71+ | -21846 | 1 | 11605 | 21845 |
| 72 | -21846 | 1 | 11605 | -21846 |
| 72+ | -21846 | 0 | 1365 | 21845 |
| 73 | -21846 | 0 | 1365 | 21845 |
| 73 | -21846 | 0 | 3413 | 21845 |
| 73 | -21846 | 0 | 5461 | 21845 |
| 73 | -21846 | 0 | 7509 | 21845 |
| 73 | -21846 | 0 | 9557 | 21845 |
| 73 | -21846 | 0 | 11605 | -21846 |
| 73 | -21846 | 0 | 13653 | 21845 |
| 73 | -21846 | 0 | 15701 | 21845 |
| 73+ | 21845 | 1 | 11605 | -21846 |
| 74 | 21845 | 1 | 11605 | 21845 |
| 74+ | -21846 | 1 | 13653 | 21845 |
| 75 | -21846 | 1 | 13653 | -21846 |
| 75+ | -21846 | 0 | 1365 | 21845 |
| 76 | -21846 | 0 | 1365 | 21845 |
| 76 | -21846 | 0 | 3413 | 21845 |
| 76 | -21846 | 0 | 5461 | 21845 |
| 76 | -21846 | 0 | 7509 | 21845 |
| 76 | -21846 | 0 | 9557 | 21845 |
| 76 | -21846 | 0 | 11605 | 21845 |
| 76 | -21846 | 0 | 13653 | -21846 |
| 76 | -21846 | 0 | 15701 | 21845 |
| 76+ | 21845 | 1 | 13653 | -21846 |
| 77 | 21845 | 1 | 13653 | 21845 |
| 77+ | -21846 | 1 | 15701 | 21845 |
| 78 | -21846 | 1 | 15701 | -21846 |
| 78+ | -21846 | 0 | 1365 | 21845 |
| 79 | -21846 | 0 | 1365 | 21845 |
| 79 | -21846 | 0 | 3413 | 21845 |
| 79 | -21846 | 0 | 5461 | 21845 |
| 79 | -21846 | 0 | 7509 | 21845 |
| 79 | -21846 | 0 | 9557 | 21845 |
| 79 | -21846 | 0 | 11605 | 21845 |
| 79 | -21846 | 0 | 13653 | 21845 |
| 79 | -21846 | 0 | 15701 | -21846 |
| 79+ | 21845 | 1 | 15701 | -21846 |
| 80 | 21845 | 1 | 15701 | 21845 |
| 80+ | 21845 | 0 | 1365 | 21845 |
| 81 | 21845 | 0 | 1365 | 21845 |
| 81 | 21845 | 0 | 3413 | 21845 |
| 81 | 21845 | 0 | 5461 | 21845 |
| 81 | 21845 | 0 | 7509 | 21845 |
| 81 | 21845 | 0 | 9557 | 21845 |
| 81 | 21845 | 0 | 11605 | 21845 |
| 81 | 21845 | 0 | 13653 | 21845 |
| 81 | 21845 | 0 | 15701 | 21845 |

29
projects/03/b/RAM16K.hdl Normal file
View File

@@ -0,0 +1,29 @@
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/03/b/RAM16K.hdl
/**
* Memory of 16K registers, each 16 bit-wide. Out holds the value
* stored at the memory location specified by address. If load==1, then
* the in value is loaded into the memory location specified by address
* (the loaded value will be emitted to out from the next time step onward).
*/
CHIP RAM16K {
IN in[16], load, address[14];
OUT out[16];
PARTS:
RAM4K(in=in, load=load1, address=address[0..11], out=out1);
RAM4K(in=in, load=load2, address=address[0..11], out=out2);
RAM4K(in=in, load=load3, address=address[0..11], out=out3);
RAM4K(in=in, load=load4, address=address[0..11], out=out4);
RAM4K(in=in, load=load5, address=address[0..11], out=out5);
RAM4K(in=in, load=load6, address=address[0..11], out=out6);
RAM4K(in=in, load=load7, address=address[0..11], out=out7);
RAM4K(in=in, load=load8, address=address[0..11], out=out8);
DMux8Way(in=load, sel=address[11..13], a=load1, b=load2, c=load3, d=load4, e=load5, f=load6, g=load7, h=load8);
Mux8Way16(a=out1, b=out2, c=out3, d=out4, e=out5, f=out6, g=out7, h=out8, sel=address[11..13], out=out);
}

1026
projects/03/b/RAM16K.tst Normal file

File diff suppressed because it is too large Load Diff

320
projects/03/b/RAM4K.cmp Normal file
View File

@@ -0,0 +1,320 @@
| time | in |load |address | out |
| 0+ | 0 | 0 | 0 | 0 |
| 1 | 0 | 0 | 0 | 0 |
| 1+ | 0 | 1 | 0 | 0 |
| 2 | 0 | 1 | 0 | 0 |
| 2+ | 1111 | 0 | 0 | 0 |
| 3 | 1111 | 0 | 0 | 0 |
| 3+ | 1111 | 1 | 1111 | 0 |
| 4 | 1111 | 1 | 1111 | 1111 |
| 4+ | 1111 | 0 | 0 | 0 |
| 5 | 1111 | 0 | 0 | 0 |
| 5+ | 3513 | 0 | 3513 | 0 |
| 6 | 3513 | 0 | 3513 | 0 |
| 6+ | 3513 | 1 | 3513 | 0 |
| 7 | 3513 | 1 | 3513 | 3513 |
| 7+ | 3513 | 0 | 3513 | 3513 |
| 8 | 3513 | 0 | 3513 | 3513 |
| 8 | 3513 | 0 | 1111 | 1111 |
| 8+ | 4095 | 0 | 1111 | 1111 |
| 9 | 4095 | 0 | 1111 | 1111 |
| 9+ | 4095 | 1 | 4095 | 0 |
| 10 | 4095 | 1 | 4095 | 4095 |
| 10+ | 4095 | 0 | 4095 | 4095 |
| 11 | 4095 | 0 | 4095 | 4095 |
| 11 | 4095 | 0 | 3513 | 3513 |
| 11 | 4095 | 0 | 4095 | 4095 |
| 11+ | 4095 | 0 | 2728 | 0 |
| 12 | 4095 | 0 | 2728 | 0 |
| 12 | 4095 | 0 | 2729 | 0 |
| 12 | 4095 | 0 | 2730 | 0 |
| 12 | 4095 | 0 | 2731 | 0 |
| 12 | 4095 | 0 | 2732 | 0 |
| 12 | 4095 | 0 | 2733 | 0 |
| 12 | 4095 | 0 | 2734 | 0 |
| 12 | 4095 | 0 | 2735 | 0 |
| 12+ | 21845 | 1 | 2728 | 0 |
| 13 | 21845 | 1 | 2728 | 21845 |
| 13+ | 21845 | 1 | 2729 | 0 |
| 14 | 21845 | 1 | 2729 | 21845 |
| 14+ | 21845 | 1 | 2730 | 0 |
| 15 | 21845 | 1 | 2730 | 21845 |
| 15+ | 21845 | 1 | 2731 | 0 |
| 16 | 21845 | 1 | 2731 | 21845 |
| 16+ | 21845 | 1 | 2732 | 0 |
| 17 | 21845 | 1 | 2732 | 21845 |
| 17+ | 21845 | 1 | 2733 | 0 |
| 18 | 21845 | 1 | 2733 | 21845 |
| 18+ | 21845 | 1 | 2734 | 0 |
| 19 | 21845 | 1 | 2734 | 21845 |
| 19+ | 21845 | 1 | 2735 | 0 |
| 20 | 21845 | 1 | 2735 | 21845 |
| 20+ | 21845 | 0 | 2728 | 21845 |
| 21 | 21845 | 0 | 2728 | 21845 |
| 21 | 21845 | 0 | 2729 | 21845 |
| 21 | 21845 | 0 | 2730 | 21845 |
| 21 | 21845 | 0 | 2731 | 21845 |
| 21 | 21845 | 0 | 2732 | 21845 |
| 21 | 21845 | 0 | 2733 | 21845 |
| 21 | 21845 | 0 | 2734 | 21845 |
| 21 | 21845 | 0 | 2735 | 21845 |
| 21+ | -21846 | 1 | 2728 | 21845 |
| 22 | -21846 | 1 | 2728 | -21846 |
| 22+ | -21846 | 0 | 2728 | -21846 |
| 23 | -21846 | 0 | 2728 | -21846 |
| 23 | -21846 | 0 | 2729 | 21845 |
| 23 | -21846 | 0 | 2730 | 21845 |
| 23 | -21846 | 0 | 2731 | 21845 |
| 23 | -21846 | 0 | 2732 | 21845 |
| 23 | -21846 | 0 | 2733 | 21845 |
| 23 | -21846 | 0 | 2734 | 21845 |
| 23 | -21846 | 0 | 2735 | 21845 |
| 23+ | 21845 | 1 | 2728 | -21846 |
| 24 | 21845 | 1 | 2728 | 21845 |
| 24+ | -21846 | 1 | 2729 | 21845 |
| 25 | -21846 | 1 | 2729 | -21846 |
| 25+ | -21846 | 0 | 2728 | 21845 |
| 26 | -21846 | 0 | 2728 | 21845 |
| 26 | -21846 | 0 | 2729 | -21846 |
| 26 | -21846 | 0 | 2730 | 21845 |
| 26 | -21846 | 0 | 2731 | 21845 |
| 26 | -21846 | 0 | 2732 | 21845 |
| 26 | -21846 | 0 | 2733 | 21845 |
| 26 | -21846 | 0 | 2734 | 21845 |
| 26 | -21846 | 0 | 2735 | 21845 |
| 26+ | 21845 | 1 | 2729 | -21846 |
| 27 | 21845 | 1 | 2729 | 21845 |
| 27+ | -21846 | 1 | 2730 | 21845 |
| 28 | -21846 | 1 | 2730 | -21846 |
| 28+ | -21846 | 0 | 2728 | 21845 |
| 29 | -21846 | 0 | 2728 | 21845 |
| 29 | -21846 | 0 | 2729 | 21845 |
| 29 | -21846 | 0 | 2730 | -21846 |
| 29 | -21846 | 0 | 2731 | 21845 |
| 29 | -21846 | 0 | 2732 | 21845 |
| 29 | -21846 | 0 | 2733 | 21845 |
| 29 | -21846 | 0 | 2734 | 21845 |
| 29 | -21846 | 0 | 2735 | 21845 |
| 29+ | 21845 | 1 | 2730 | -21846 |
| 30 | 21845 | 1 | 2730 | 21845 |
| 30+ | -21846 | 1 | 2731 | 21845 |
| 31 | -21846 | 1 | 2731 | -21846 |
| 31+ | -21846 | 0 | 2728 | 21845 |
| 32 | -21846 | 0 | 2728 | 21845 |
| 32 | -21846 | 0 | 2729 | 21845 |
| 32 | -21846 | 0 | 2730 | 21845 |
| 32 | -21846 | 0 | 2731 | -21846 |
| 32 | -21846 | 0 | 2732 | 21845 |
| 32 | -21846 | 0 | 2733 | 21845 |
| 32 | -21846 | 0 | 2734 | 21845 |
| 32 | -21846 | 0 | 2735 | 21845 |
| 32+ | 21845 | 1 | 2731 | -21846 |
| 33 | 21845 | 1 | 2731 | 21845 |
| 33+ | -21846 | 1 | 2732 | 21845 |
| 34 | -21846 | 1 | 2732 | -21846 |
| 34+ | -21846 | 0 | 2728 | 21845 |
| 35 | -21846 | 0 | 2728 | 21845 |
| 35 | -21846 | 0 | 2729 | 21845 |
| 35 | -21846 | 0 | 2730 | 21845 |
| 35 | -21846 | 0 | 2731 | 21845 |
| 35 | -21846 | 0 | 2732 | -21846 |
| 35 | -21846 | 0 | 2733 | 21845 |
| 35 | -21846 | 0 | 2734 | 21845 |
| 35 | -21846 | 0 | 2735 | 21845 |
| 35+ | 21845 | 1 | 2732 | -21846 |
| 36 | 21845 | 1 | 2732 | 21845 |
| 36+ | -21846 | 1 | 2733 | 21845 |
| 37 | -21846 | 1 | 2733 | -21846 |
| 37+ | -21846 | 0 | 2728 | 21845 |
| 38 | -21846 | 0 | 2728 | 21845 |
| 38 | -21846 | 0 | 2729 | 21845 |
| 38 | -21846 | 0 | 2730 | 21845 |
| 38 | -21846 | 0 | 2731 | 21845 |
| 38 | -21846 | 0 | 2732 | 21845 |
| 38 | -21846 | 0 | 2733 | -21846 |
| 38 | -21846 | 0 | 2734 | 21845 |
| 38 | -21846 | 0 | 2735 | 21845 |
| 38+ | 21845 | 1 | 2733 | -21846 |
| 39 | 21845 | 1 | 2733 | 21845 |
| 39+ | -21846 | 1 | 2734 | 21845 |
| 40 | -21846 | 1 | 2734 | -21846 |
| 40+ | -21846 | 0 | 2728 | 21845 |
| 41 | -21846 | 0 | 2728 | 21845 |
| 41 | -21846 | 0 | 2729 | 21845 |
| 41 | -21846 | 0 | 2730 | 21845 |
| 41 | -21846 | 0 | 2731 | 21845 |
| 41 | -21846 | 0 | 2732 | 21845 |
| 41 | -21846 | 0 | 2733 | 21845 |
| 41 | -21846 | 0 | 2734 | -21846 |
| 41 | -21846 | 0 | 2735 | 21845 |
| 41+ | 21845 | 1 | 2734 | -21846 |
| 42 | 21845 | 1 | 2734 | 21845 |
| 42+ | -21846 | 1 | 2735 | 21845 |
| 43 | -21846 | 1 | 2735 | -21846 |
| 43+ | -21846 | 0 | 2728 | 21845 |
| 44 | -21846 | 0 | 2728 | 21845 |
| 44 | -21846 | 0 | 2729 | 21845 |
| 44 | -21846 | 0 | 2730 | 21845 |
| 44 | -21846 | 0 | 2731 | 21845 |
| 44 | -21846 | 0 | 2732 | 21845 |
| 44 | -21846 | 0 | 2733 | 21845 |
| 44 | -21846 | 0 | 2734 | 21845 |
| 44 | -21846 | 0 | 2735 | -21846 |
| 44+ | 21845 | 1 | 2735 | -21846 |
| 45 | 21845 | 1 | 2735 | 21845 |
| 45+ | 21845 | 0 | 2728 | 21845 |
| 46 | 21845 | 0 | 2728 | 21845 |
| 46 | 21845 | 0 | 2729 | 21845 |
| 46 | 21845 | 0 | 2730 | 21845 |
| 46 | 21845 | 0 | 2731 | 21845 |
| 46 | 21845 | 0 | 2732 | 21845 |
| 46 | 21845 | 0 | 2733 | 21845 |
| 46 | 21845 | 0 | 2734 | 21845 |
| 46 | 21845 | 0 | 2735 | 21845 |
| 46+ | 21845 | 0 | 341 | 0 |
| 47 | 21845 | 0 | 341 | 0 |
| 47 | 21845 | 0 | 853 | 0 |
| 47 | 21845 | 0 | 1365 | 0 |
| 47 | 21845 | 0 | 1877 | 0 |
| 47 | 21845 | 0 | 2389 | 0 |
| 47 | 21845 | 0 | 2901 | 0 |
| 47 | 21845 | 0 | 3413 | 0 |
| 47 | 21845 | 0 | 3925 | 0 |
| 47+ | 21845 | 1 | 341 | 0 |
| 48 | 21845 | 1 | 341 | 21845 |
| 48+ | 21845 | 1 | 853 | 0 |
| 49 | 21845 | 1 | 853 | 21845 |
| 49+ | 21845 | 1 | 1365 | 0 |
| 50 | 21845 | 1 | 1365 | 21845 |
| 50+ | 21845 | 1 | 1877 | 0 |
| 51 | 21845 | 1 | 1877 | 21845 |
| 51+ | 21845 | 1 | 2389 | 0 |
| 52 | 21845 | 1 | 2389 | 21845 |
| 52+ | 21845 | 1 | 2901 | 0 |
| 53 | 21845 | 1 | 2901 | 21845 |
| 53+ | 21845 | 1 | 3413 | 0 |
| 54 | 21845 | 1 | 3413 | 21845 |
| 54+ | 21845 | 1 | 3925 | 0 |
| 55 | 21845 | 1 | 3925 | 21845 |
| 55+ | 21845 | 0 | 341 | 21845 |
| 56 | 21845 | 0 | 341 | 21845 |
| 56 | 21845 | 0 | 853 | 21845 |
| 56 | 21845 | 0 | 1365 | 21845 |
| 56 | 21845 | 0 | 1877 | 21845 |
| 56 | 21845 | 0 | 2389 | 21845 |
| 56 | 21845 | 0 | 2901 | 21845 |
| 56 | 21845 | 0 | 3413 | 21845 |
| 56 | 21845 | 0 | 3925 | 21845 |
| 56+ | -21846 | 1 | 341 | 21845 |
| 57 | -21846 | 1 | 341 | -21846 |
| 57+ | -21846 | 0 | 341 | -21846 |
| 58 | -21846 | 0 | 341 | -21846 |
| 58 | -21846 | 0 | 853 | 21845 |
| 58 | -21846 | 0 | 1365 | 21845 |
| 58 | -21846 | 0 | 1877 | 21845 |
| 58 | -21846 | 0 | 2389 | 21845 |
| 58 | -21846 | 0 | 2901 | 21845 |
| 58 | -21846 | 0 | 3413 | 21845 |
| 58 | -21846 | 0 | 3925 | 21845 |
| 58+ | 21845 | 1 | 341 | -21846 |
| 59 | 21845 | 1 | 341 | 21845 |
| 59+ | -21846 | 1 | 853 | 21845 |
| 60 | -21846 | 1 | 853 | -21846 |
| 60+ | -21846 | 0 | 341 | 21845 |
| 61 | -21846 | 0 | 341 | 21845 |
| 61 | -21846 | 0 | 853 | -21846 |
| 61 | -21846 | 0 | 1365 | 21845 |
| 61 | -21846 | 0 | 1877 | 21845 |
| 61 | -21846 | 0 | 2389 | 21845 |
| 61 | -21846 | 0 | 2901 | 21845 |
| 61 | -21846 | 0 | 3413 | 21845 |
| 61 | -21846 | 0 | 3925 | 21845 |
| 61+ | 21845 | 1 | 853 | -21846 |
| 62 | 21845 | 1 | 853 | 21845 |
| 62+ | -21846 | 1 | 1365 | 21845 |
| 63 | -21846 | 1 | 1365 | -21846 |
| 63+ | -21846 | 0 | 341 | 21845 |
| 64 | -21846 | 0 | 341 | 21845 |
| 64 | -21846 | 0 | 853 | 21845 |
| 64 | -21846 | 0 | 1365 | -21846 |
| 64 | -21846 | 0 | 1877 | 21845 |
| 64 | -21846 | 0 | 2389 | 21845 |
| 64 | -21846 | 0 | 2901 | 21845 |
| 64 | -21846 | 0 | 3413 | 21845 |
| 64 | -21846 | 0 | 3925 | 21845 |
| 64+ | 21845 | 1 | 1365 | -21846 |
| 65 | 21845 | 1 | 1365 | 21845 |
| 65+ | -21846 | 1 | 1877 | 21845 |
| 66 | -21846 | 1 | 1877 | -21846 |
| 66+ | -21846 | 0 | 341 | 21845 |
| 67 | -21846 | 0 | 341 | 21845 |
| 67 | -21846 | 0 | 853 | 21845 |
| 67 | -21846 | 0 | 1365 | 21845 |
| 67 | -21846 | 0 | 1877 | -21846 |
| 67 | -21846 | 0 | 2389 | 21845 |
| 67 | -21846 | 0 | 2901 | 21845 |
| 67 | -21846 | 0 | 3413 | 21845 |
| 67 | -21846 | 0 | 3925 | 21845 |
| 67+ | 21845 | 1 | 1877 | -21846 |
| 68 | 21845 | 1 | 1877 | 21845 |
| 68+ | -21846 | 1 | 2389 | 21845 |
| 69 | -21846 | 1 | 2389 | -21846 |
| 69+ | -21846 | 0 | 341 | 21845 |
| 70 | -21846 | 0 | 341 | 21845 |
| 70 | -21846 | 0 | 853 | 21845 |
| 70 | -21846 | 0 | 1365 | 21845 |
| 70 | -21846 | 0 | 1877 | 21845 |
| 70 | -21846 | 0 | 2389 | -21846 |
| 70 | -21846 | 0 | 2901 | 21845 |
| 70 | -21846 | 0 | 3413 | 21845 |
| 70 | -21846 | 0 | 3925 | 21845 |
| 70+ | 21845 | 1 | 2389 | -21846 |
| 71 | 21845 | 1 | 2389 | 21845 |
| 71+ | -21846 | 1 | 2901 | 21845 |
| 72 | -21846 | 1 | 2901 | -21846 |
| 72+ | -21846 | 0 | 341 | 21845 |
| 73 | -21846 | 0 | 341 | 21845 |
| 73 | -21846 | 0 | 853 | 21845 |
| 73 | -21846 | 0 | 1365 | 21845 |
| 73 | -21846 | 0 | 1877 | 21845 |
| 73 | -21846 | 0 | 2389 | 21845 |
| 73 | -21846 | 0 | 2901 | -21846 |
| 73 | -21846 | 0 | 3413 | 21845 |
| 73 | -21846 | 0 | 3925 | 21845 |
| 73+ | 21845 | 1 | 2901 | -21846 |
| 74 | 21845 | 1 | 2901 | 21845 |
| 74+ | -21846 | 1 | 3413 | 21845 |
| 75 | -21846 | 1 | 3413 | -21846 |
| 75+ | -21846 | 0 | 341 | 21845 |
| 76 | -21846 | 0 | 341 | 21845 |
| 76 | -21846 | 0 | 853 | 21845 |
| 76 | -21846 | 0 | 1365 | 21845 |
| 76 | -21846 | 0 | 1877 | 21845 |
| 76 | -21846 | 0 | 2389 | 21845 |
| 76 | -21846 | 0 | 2901 | 21845 |
| 76 | -21846 | 0 | 3413 | -21846 |
| 76 | -21846 | 0 | 3925 | 21845 |
| 76+ | 21845 | 1 | 3413 | -21846 |
| 77 | 21845 | 1 | 3413 | 21845 |
| 77+ | -21846 | 1 | 3925 | 21845 |
| 78 | -21846 | 1 | 3925 | -21846 |
| 78+ | -21846 | 0 | 341 | 21845 |
| 79 | -21846 | 0 | 341 | 21845 |
| 79 | -21846 | 0 | 853 | 21845 |
| 79 | -21846 | 0 | 1365 | 21845 |
| 79 | -21846 | 0 | 1877 | 21845 |
| 79 | -21846 | 0 | 2389 | 21845 |
| 79 | -21846 | 0 | 2901 | 21845 |
| 79 | -21846 | 0 | 3413 | 21845 |
| 79 | -21846 | 0 | 3925 | -21846 |
| 79+ | 21845 | 1 | 3925 | -21846 |
| 80 | 21845 | 1 | 3925 | 21845 |
| 80+ | 21845 | 0 | 341 | 21845 |
| 81 | 21845 | 0 | 341 | 21845 |
| 81 | 21845 | 0 | 853 | 21845 |
| 81 | 21845 | 0 | 1365 | 21845 |
| 81 | 21845 | 0 | 1877 | 21845 |
| 81 | 21845 | 0 | 2389 | 21845 |
| 81 | 21845 | 0 | 2901 | 21845 |
| 81 | 21845 | 0 | 3413 | 21845 |
| 81 | 21845 | 0 | 3925 | 21845 |

29
projects/03/b/RAM4K.hdl Normal file
View File

@@ -0,0 +1,29 @@
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/03/b/RAM4K.hdl
/**
* Memory of 4K registers, each 16 bit-wide. Out holds the value
* stored at the memory location specified by address. If load==1, then
* the in value is loaded into the memory location specified by address
* (the loaded value will be emitted to out from the next time step onward).
*/
CHIP RAM4K {
IN in[16], load, address[12];
OUT out[16];
PARTS:
RAM512(in=in, load=load1, address=address[0..8], out=out1);
RAM512(in=in, load=load2, address=address[0..8], out=out2);
RAM512(in=in, load=load3, address=address[0..8], out=out3);
RAM512(in=in, load=load4, address=address[0..8], out=out4);
RAM512(in=in, load=load5, address=address[0..8], out=out5);
RAM512(in=in, load=load6, address=address[0..8], out=out6);
RAM512(in=in, load=load7, address=address[0..8], out=out7);
RAM512(in=in, load=load8, address=address[0..8], out=out8);
DMux8Way(in=load, sel=address[9..11], a=load1, b=load2, c=load3, d=load4, e=load5, f=load6, g=load7, h=load8);
Mux8Way16(a=out1, b=out2, c=out3, d=out4, e=out5, f=out6, g=out7, h=out8, sel=address[9..11], out=out);
}

1026
projects/03/b/RAM4K.tst Normal file

File diff suppressed because it is too large Load Diff

320
projects/03/b/RAM512.cmp Normal file
View File

@@ -0,0 +1,320 @@
| time | in |load |address| out |
| 0+ | 0 | 0 | 0 | 0 |
| 1 | 0 | 0 | 0 | 0 |
| 1+ | 0 | 1 | 0 | 0 |
| 2 | 0 | 1 | 0 | 0 |
| 2+ | 13099 | 0 | 0 | 0 |
| 3 | 13099 | 0 | 0 | 0 |
| 3+ | 13099 | 1 | 130 | 0 |
| 4 | 13099 | 1 | 130 | 13099 |
| 4+ | 13099 | 0 | 0 | 0 |
| 5 | 13099 | 0 | 0 | 0 |
| 5+ | 4729 | 0 | 472 | 0 |
| 6 | 4729 | 0 | 472 | 0 |
| 6+ | 4729 | 1 | 472 | 0 |
| 7 | 4729 | 1 | 472 | 4729 |
| 7+ | 4729 | 0 | 472 | 4729 |
| 8 | 4729 | 0 | 472 | 4729 |
| 8 | 4729 | 0 | 130 | 13099 |
| 8+ | 5119 | 0 | 130 | 13099 |
| 9 | 5119 | 0 | 130 | 13099 |
| 9+ | 5119 | 1 | 511 | 0 |
| 10 | 5119 | 1 | 511 | 5119 |
| 10+ | 5119 | 0 | 511 | 5119 |
| 11 | 5119 | 0 | 511 | 5119 |
| 11 | 5119 | 0 | 472 | 4729 |
| 11 | 5119 | 0 | 511 | 5119 |
| 11+ | 5119 | 0 | 168 | 0 |
| 12 | 5119 | 0 | 168 | 0 |
| 12 | 5119 | 0 | 169 | 0 |
| 12 | 5119 | 0 | 170 | 0 |
| 12 | 5119 | 0 | 171 | 0 |
| 12 | 5119 | 0 | 172 | 0 |
| 12 | 5119 | 0 | 173 | 0 |
| 12 | 5119 | 0 | 174 | 0 |
| 12 | 5119 | 0 | 175 | 0 |
| 12+ | 21845 | 1 | 168 | 0 |
| 13 | 21845 | 1 | 168 | 21845 |
| 13+ | 21845 | 1 | 169 | 0 |
| 14 | 21845 | 1 | 169 | 21845 |
| 14+ | 21845 | 1 | 170 | 0 |
| 15 | 21845 | 1 | 170 | 21845 |
| 15+ | 21845 | 1 | 171 | 0 |
| 16 | 21845 | 1 | 171 | 21845 |
| 16+ | 21845 | 1 | 172 | 0 |
| 17 | 21845 | 1 | 172 | 21845 |
| 17+ | 21845 | 1 | 173 | 0 |
| 18 | 21845 | 1 | 173 | 21845 |
| 18+ | 21845 | 1 | 174 | 0 |
| 19 | 21845 | 1 | 174 | 21845 |
| 19+ | 21845 | 1 | 175 | 0 |
| 20 | 21845 | 1 | 175 | 21845 |
| 20+ | 21845 | 0 | 168 | 21845 |
| 21 | 21845 | 0 | 168 | 21845 |
| 21 | 21845 | 0 | 169 | 21845 |
| 21 | 21845 | 0 | 170 | 21845 |
| 21 | 21845 | 0 | 171 | 21845 |
| 21 | 21845 | 0 | 172 | 21845 |
| 21 | 21845 | 0 | 173 | 21845 |
| 21 | 21845 | 0 | 174 | 21845 |
| 21 | 21845 | 0 | 175 | 21845 |
| 21+ | -21846 | 1 | 168 | 21845 |
| 22 | -21846 | 1 | 168 | -21846 |
| 22+ | -21846 | 0 | 168 | -21846 |
| 23 | -21846 | 0 | 168 | -21846 |
| 23 | -21846 | 0 | 169 | 21845 |
| 23 | -21846 | 0 | 170 | 21845 |
| 23 | -21846 | 0 | 171 | 21845 |
| 23 | -21846 | 0 | 172 | 21845 |
| 23 | -21846 | 0 | 173 | 21845 |
| 23 | -21846 | 0 | 174 | 21845 |
| 23 | -21846 | 0 | 175 | 21845 |
| 23+ | 21845 | 1 | 168 | -21846 |
| 24 | 21845 | 1 | 168 | 21845 |
| 24+ | -21846 | 1 | 169 | 21845 |
| 25 | -21846 | 1 | 169 | -21846 |
| 25+ | -21846 | 0 | 168 | 21845 |
| 26 | -21846 | 0 | 168 | 21845 |
| 26 | -21846 | 0 | 169 | -21846 |
| 26 | -21846 | 0 | 170 | 21845 |
| 26 | -21846 | 0 | 171 | 21845 |
| 26 | -21846 | 0 | 172 | 21845 |
| 26 | -21846 | 0 | 173 | 21845 |
| 26 | -21846 | 0 | 174 | 21845 |
| 26 | -21846 | 0 | 175 | 21845 |
| 26+ | 21845 | 1 | 169 | -21846 |
| 27 | 21845 | 1 | 169 | 21845 |
| 27+ | -21846 | 1 | 170 | 21845 |
| 28 | -21846 | 1 | 170 | -21846 |
| 28+ | -21846 | 0 | 168 | 21845 |
| 29 | -21846 | 0 | 168 | 21845 |
| 29 | -21846 | 0 | 169 | 21845 |
| 29 | -21846 | 0 | 170 | -21846 |
| 29 | -21846 | 0 | 171 | 21845 |
| 29 | -21846 | 0 | 172 | 21845 |
| 29 | -21846 | 0 | 173 | 21845 |
| 29 | -21846 | 0 | 174 | 21845 |
| 29 | -21846 | 0 | 175 | 21845 |
| 29+ | 21845 | 1 | 170 | -21846 |
| 30 | 21845 | 1 | 170 | 21845 |
| 30+ | -21846 | 1 | 171 | 21845 |
| 31 | -21846 | 1 | 171 | -21846 |
| 31+ | -21846 | 0 | 168 | 21845 |
| 32 | -21846 | 0 | 168 | 21845 |
| 32 | -21846 | 0 | 169 | 21845 |
| 32 | -21846 | 0 | 170 | 21845 |
| 32 | -21846 | 0 | 171 | -21846 |
| 32 | -21846 | 0 | 172 | 21845 |
| 32 | -21846 | 0 | 173 | 21845 |
| 32 | -21846 | 0 | 174 | 21845 |
| 32 | -21846 | 0 | 175 | 21845 |
| 32+ | 21845 | 1 | 171 | -21846 |
| 33 | 21845 | 1 | 171 | 21845 |
| 33+ | -21846 | 1 | 172 | 21845 |
| 34 | -21846 | 1 | 172 | -21846 |
| 34+ | -21846 | 0 | 168 | 21845 |
| 35 | -21846 | 0 | 168 | 21845 |
| 35 | -21846 | 0 | 169 | 21845 |
| 35 | -21846 | 0 | 170 | 21845 |
| 35 | -21846 | 0 | 171 | 21845 |
| 35 | -21846 | 0 | 172 | -21846 |
| 35 | -21846 | 0 | 173 | 21845 |
| 35 | -21846 | 0 | 174 | 21845 |
| 35 | -21846 | 0 | 175 | 21845 |
| 35+ | 21845 | 1 | 172 | -21846 |
| 36 | 21845 | 1 | 172 | 21845 |
| 36+ | -21846 | 1 | 173 | 21845 |
| 37 | -21846 | 1 | 173 | -21846 |
| 37+ | -21846 | 0 | 168 | 21845 |
| 38 | -21846 | 0 | 168 | 21845 |
| 38 | -21846 | 0 | 169 | 21845 |
| 38 | -21846 | 0 | 170 | 21845 |
| 38 | -21846 | 0 | 171 | 21845 |
| 38 | -21846 | 0 | 172 | 21845 |
| 38 | -21846 | 0 | 173 | -21846 |
| 38 | -21846 | 0 | 174 | 21845 |
| 38 | -21846 | 0 | 175 | 21845 |
| 38+ | 21845 | 1 | 173 | -21846 |
| 39 | 21845 | 1 | 173 | 21845 |
| 39+ | -21846 | 1 | 174 | 21845 |
| 40 | -21846 | 1 | 174 | -21846 |
| 40+ | -21846 | 0 | 168 | 21845 |
| 41 | -21846 | 0 | 168 | 21845 |
| 41 | -21846 | 0 | 169 | 21845 |
| 41 | -21846 | 0 | 170 | 21845 |
| 41 | -21846 | 0 | 171 | 21845 |
| 41 | -21846 | 0 | 172 | 21845 |
| 41 | -21846 | 0 | 173 | 21845 |
| 41 | -21846 | 0 | 174 | -21846 |
| 41 | -21846 | 0 | 175 | 21845 |
| 41+ | 21845 | 1 | 174 | -21846 |
| 42 | 21845 | 1 | 174 | 21845 |
| 42+ | -21846 | 1 | 175 | 21845 |
| 43 | -21846 | 1 | 175 | -21846 |
| 43+ | -21846 | 0 | 168 | 21845 |
| 44 | -21846 | 0 | 168 | 21845 |
| 44 | -21846 | 0 | 169 | 21845 |
| 44 | -21846 | 0 | 170 | 21845 |
| 44 | -21846 | 0 | 171 | 21845 |
| 44 | -21846 | 0 | 172 | 21845 |
| 44 | -21846 | 0 | 173 | 21845 |
| 44 | -21846 | 0 | 174 | 21845 |
| 44 | -21846 | 0 | 175 | -21846 |
| 44+ | 21845 | 1 | 175 | -21846 |
| 45 | 21845 | 1 | 175 | 21845 |
| 45+ | 21845 | 0 | 168 | 21845 |
| 46 | 21845 | 0 | 168 | 21845 |
| 46 | 21845 | 0 | 169 | 21845 |
| 46 | 21845 | 0 | 170 | 21845 |
| 46 | 21845 | 0 | 171 | 21845 |
| 46 | 21845 | 0 | 172 | 21845 |
| 46 | 21845 | 0 | 173 | 21845 |
| 46 | 21845 | 0 | 174 | 21845 |
| 46 | 21845 | 0 | 175 | 21845 |
| 46+ | 21845 | 0 | 42 | 0 |
| 47 | 21845 | 0 | 42 | 0 |
| 47 | 21845 | 0 | 106 | 0 |
| 47 | 21845 | 0 | 170 | 21845 |
| 47 | 21845 | 0 | 234 | 0 |
| 47 | 21845 | 0 | 298 | 0 |
| 47 | 21845 | 0 | 362 | 0 |
| 47 | 21845 | 0 | 426 | 0 |
| 47 | 21845 | 0 | 490 | 0 |
| 47+ | 21845 | 1 | 42 | 0 |
| 48 | 21845 | 1 | 42 | 21845 |
| 48+ | 21845 | 1 | 106 | 0 |
| 49 | 21845 | 1 | 106 | 21845 |
| 49+ | 21845 | 1 | 170 | 21845 |
| 50 | 21845 | 1 | 170 | 21845 |
| 50+ | 21845 | 1 | 234 | 0 |
| 51 | 21845 | 1 | 234 | 21845 |
| 51+ | 21845 | 1 | 298 | 0 |
| 52 | 21845 | 1 | 298 | 21845 |
| 52+ | 21845 | 1 | 362 | 0 |
| 53 | 21845 | 1 | 362 | 21845 |
| 53+ | 21845 | 1 | 426 | 0 |
| 54 | 21845 | 1 | 426 | 21845 |
| 54+ | 21845 | 1 | 490 | 0 |
| 55 | 21845 | 1 | 490 | 21845 |
| 55+ | 21845 | 0 | 42 | 21845 |
| 56 | 21845 | 0 | 42 | 21845 |
| 56 | 21845 | 0 | 106 | 21845 |
| 56 | 21845 | 0 | 170 | 21845 |
| 56 | 21845 | 0 | 234 | 21845 |
| 56 | 21845 | 0 | 298 | 21845 |
| 56 | 21845 | 0 | 362 | 21845 |
| 56 | 21845 | 0 | 426 | 21845 |
| 56 | 21845 | 0 | 490 | 21845 |
| 56+ | -21846 | 1 | 42 | 21845 |
| 57 | -21846 | 1 | 42 | -21846 |
| 57+ | -21846 | 0 | 42 | -21846 |
| 58 | -21846 | 0 | 42 | -21846 |
| 58 | -21846 | 0 | 106 | 21845 |
| 58 | -21846 | 0 | 170 | 21845 |
| 58 | -21846 | 0 | 234 | 21845 |
| 58 | -21846 | 0 | 298 | 21845 |
| 58 | -21846 | 0 | 362 | 21845 |
| 58 | -21846 | 0 | 426 | 21845 |
| 58 | -21846 | 0 | 490 | 21845 |
| 58+ | 21845 | 1 | 42 | -21846 |
| 59 | 21845 | 1 | 42 | 21845 |
| 59+ | -21846 | 1 | 106 | 21845 |
| 60 | -21846 | 1 | 106 | -21846 |
| 60+ | -21846 | 0 | 42 | 21845 |
| 61 | -21846 | 0 | 42 | 21845 |
| 61 | -21846 | 0 | 106 | -21846 |
| 61 | -21846 | 0 | 170 | 21845 |
| 61 | -21846 | 0 | 234 | 21845 |
| 61 | -21846 | 0 | 298 | 21845 |
| 61 | -21846 | 0 | 362 | 21845 |
| 61 | -21846 | 0 | 426 | 21845 |
| 61 | -21846 | 0 | 490 | 21845 |
| 61+ | 21845 | 1 | 106 | -21846 |
| 62 | 21845 | 1 | 106 | 21845 |
| 62+ | -21846 | 1 | 170 | 21845 |
| 63 | -21846 | 1 | 170 | -21846 |
| 63+ | -21846 | 0 | 42 | 21845 |
| 64 | -21846 | 0 | 42 | 21845 |
| 64 | -21846 | 0 | 106 | 21845 |
| 64 | -21846 | 0 | 170 | -21846 |
| 64 | -21846 | 0 | 234 | 21845 |
| 64 | -21846 | 0 | 298 | 21845 |
| 64 | -21846 | 0 | 362 | 21845 |
| 64 | -21846 | 0 | 426 | 21845 |
| 64 | -21846 | 0 | 490 | 21845 |
| 64+ | 21845 | 1 | 170 | -21846 |
| 65 | 21845 | 1 | 170 | 21845 |
| 65+ | -21846 | 1 | 234 | 21845 |
| 66 | -21846 | 1 | 234 | -21846 |
| 66+ | -21846 | 0 | 42 | 21845 |
| 67 | -21846 | 0 | 42 | 21845 |
| 67 | -21846 | 0 | 106 | 21845 |
| 67 | -21846 | 0 | 170 | 21845 |
| 67 | -21846 | 0 | 234 | -21846 |
| 67 | -21846 | 0 | 298 | 21845 |
| 67 | -21846 | 0 | 362 | 21845 |
| 67 | -21846 | 0 | 426 | 21845 |
| 67 | -21846 | 0 | 490 | 21845 |
| 67+ | 21845 | 1 | 234 | -21846 |
| 68 | 21845 | 1 | 234 | 21845 |
| 68+ | -21846 | 1 | 298 | 21845 |
| 69 | -21846 | 1 | 298 | -21846 |
| 69+ | -21846 | 0 | 42 | 21845 |
| 70 | -21846 | 0 | 42 | 21845 |
| 70 | -21846 | 0 | 106 | 21845 |
| 70 | -21846 | 0 | 170 | 21845 |
| 70 | -21846 | 0 | 234 | 21845 |
| 70 | -21846 | 0 | 298 | -21846 |
| 70 | -21846 | 0 | 362 | 21845 |
| 70 | -21846 | 0 | 426 | 21845 |
| 70 | -21846 | 0 | 490 | 21845 |
| 70+ | 21845 | 1 | 298 | -21846 |
| 71 | 21845 | 1 | 298 | 21845 |
| 71+ | -21846 | 1 | 362 | 21845 |
| 72 | -21846 | 1 | 362 | -21846 |
| 72+ | -21846 | 0 | 42 | 21845 |
| 73 | -21846 | 0 | 42 | 21845 |
| 73 | -21846 | 0 | 106 | 21845 |
| 73 | -21846 | 0 | 170 | 21845 |
| 73 | -21846 | 0 | 234 | 21845 |
| 73 | -21846 | 0 | 298 | 21845 |
| 73 | -21846 | 0 | 362 | -21846 |
| 73 | -21846 | 0 | 426 | 21845 |
| 73 | -21846 | 0 | 490 | 21845 |
| 73+ | 21845 | 1 | 362 | -21846 |
| 74 | 21845 | 1 | 362 | 21845 |
| 74+ | -21846 | 1 | 426 | 21845 |
| 75 | -21846 | 1 | 426 | -21846 |
| 75+ | -21846 | 0 | 42 | 21845 |
| 76 | -21846 | 0 | 42 | 21845 |
| 76 | -21846 | 0 | 106 | 21845 |
| 76 | -21846 | 0 | 170 | 21845 |
| 76 | -21846 | 0 | 234 | 21845 |
| 76 | -21846 | 0 | 298 | 21845 |
| 76 | -21846 | 0 | 362 | 21845 |
| 76 | -21846 | 0 | 426 | -21846 |
| 76 | -21846 | 0 | 490 | 21845 |
| 76+ | 21845 | 1 | 426 | -21846 |
| 77 | 21845 | 1 | 426 | 21845 |
| 77+ | -21846 | 1 | 490 | 21845 |
| 78 | -21846 | 1 | 490 | -21846 |
| 78+ | -21846 | 0 | 42 | 21845 |
| 79 | -21846 | 0 | 42 | 21845 |
| 79 | -21846 | 0 | 106 | 21845 |
| 79 | -21846 | 0 | 170 | 21845 |
| 79 | -21846 | 0 | 234 | 21845 |
| 79 | -21846 | 0 | 298 | 21845 |
| 79 | -21846 | 0 | 362 | 21845 |
| 79 | -21846 | 0 | 426 | 21845 |
| 79 | -21846 | 0 | 490 | -21846 |
| 79+ | 21845 | 1 | 490 | -21846 |
| 80 | 21845 | 1 | 490 | 21845 |
| 80+ | 21845 | 0 | 42 | 21845 |
| 81 | 21845 | 0 | 42 | 21845 |
| 81 | 21845 | 0 | 106 | 21845 |
| 81 | 21845 | 0 | 170 | 21845 |
| 81 | 21845 | 0 | 234 | 21845 |
| 81 | 21845 | 0 | 298 | 21845 |
| 81 | 21845 | 0 | 362 | 21845 |
| 81 | 21845 | 0 | 426 | 21845 |
| 81 | 21845 | 0 | 490 | 21845 |

29
projects/03/b/RAM512.hdl Normal file
View File

@@ -0,0 +1,29 @@
// This file is part of the materials accompanying the book
// "The Elements of Computing Systems" by Nisan and Schocken,
// MIT Press. Book site: www.idc.ac.il/tecs
// File name: projects/03/b/RAM512.hdl
/**
* Memory of 512 registers, each 16 bit-wide. Out holds the value
* stored at the memory location specified by address. If load==1, then
* the in value is loaded into the memory location specified by address
* (the loaded value will be emitted to out from the next time step onward).
*/
CHIP RAM512 {
IN in[16], load, address[9];
OUT out[16];
PARTS:
RAM64(in=in, load=load1, address=address[0..5], out=out1);
RAM64(in=in, load=load2, address=address[0..5], out=out2);
RAM64(in=in, load=load3, address=address[0..5], out=out3);
RAM64(in=in, load=load4, address=address[0..5], out=out4);
RAM64(in=in, load=load5, address=address[0..5], out=out5);
RAM64(in=in, load=load6, address=address[0..5], out=out6);
RAM64(in=in, load=load7, address=address[0..5], out=out7);
RAM64(in=in, load=load8, address=address[0..5], out=out8);
DMux8Way(in=load, sel=address[6..8], a=load1, b=load2, c=load3, d=load4, e=load5, f=load6, g=load7, h=load8);
Mux8Way16(a=out1, b=out2, c=out3, d=out4, e=out5, f=out6, g=out7, h=out8, sel=address[6..8], out=out);
}

1027
projects/03/b/RAM512.tst Normal file

File diff suppressed because it is too large Load Diff

85
projects/04/Fill.asm Normal file
View File

@@ -0,0 +1,85 @@
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/04/Fill.asm
// Runs an infinite loop that listens to the keyboard input.
// When a key is pressed (any key), the program blackens the screen,
// i.e. writes "black" in every pixel;
// the screen should remain fully black as long as the key is pressed.
// When no key is pressed, the program clears the screen, i.e. writes
// "white" in every pixel;
// the screen should remain fully clear as long as no key is pressed.
// Put your code here.
@SCREEN
D=A
@PTR
M=D
(WHITE)
@KBD
D=M
@BLACK
D;JNE
@SCREEN
D=A
@PTR
M=D
(WLOOP)
@PTR
D=M
@R0
M=D
@KBD
D=A
@R0
D=D-M
@WHITE
D;JEQ
@PTR
A=M
M=0
@PTR
M=M+1
@WLOOP
0;JMP
(BLACK)
@KBD
D=M
@WHITE
D;JEQ
@SCREEN
D=A
@PTR
M=D
(BLOOP)
@PTR
D=M
@R0
M=D
@KBD
D=A
@R0
D=D-M
@BLACK
D;JEQ
@PTR
A=M
M=-1
@PTR
M=M+1
@BLOOP
0;JMP

35
projects/04/Mult.asm Normal file
View File

@@ -0,0 +1,35 @@
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/04/Mult.asm
// Multiplies R0 and R1 and stores the result in R2.
// (R0, R1, R2 refer to RAM[0], RAM[1], and RAM[2], respectively.)
// Put your code here.
@R2
M=0
(LOOP)
@R1
D=M
@END
D;JEQ
@R0
D=M
@R2
M=M+D
@R1
M=M-1
@LOOP
0;JEQ
(END)
@END
0;JMP

85
projects/04/fill/Fill.asm Normal file
View File

@@ -0,0 +1,85 @@
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/04/Fill.asm
// Runs an infinite loop that listens to the keyboard input.
// When a key is pressed (any key), the program blackens the screen,
// i.e. writes "black" in every pixel;
// the screen should remain fully black as long as the key is pressed.
// When no key is pressed, the program clears the screen, i.e. writes
// "white" in every pixel;
// the screen should remain fully clear as long as no key is pressed.
// Put your code here.
@SCREEN
D=A
@PTR
M=D
(WHITE)
@KBD
D=M
@BLACK
D;JNE
@SCREEN
D=A
@PTR
M=D
(WLOOP)
@PTR
D=M
@R0
M=D
@KBD
D=A
@R0
D=D-M
@WHITE
D;JEQ
@PTR
A=M
M=0
@PTR
M=M+1
@WLOOP
0;JMP
(BLACK)
@KBD
D=M
@WHITE
D;JEQ
@SCREEN
D=A
@PTR
M=D
(BLOOP)
@PTR
D=M
@R0
M=D
@KBD
D=A
@R0
D=D-M
@BLACK
D;JEQ
@PTR
A=M
M=-1
@PTR
M=M+1
@BLOOP
0;JMP

11
projects/04/fill/Fill.tst Normal file
View File

@@ -0,0 +1,11 @@
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/04/fill/Fill.tst
load Fill.asm;
echo "Make sure that 'No Animation' is selected. Then, select the keyboard, press any key for some time, and inspect the screen.";
repeat {
ticktock;
}

View File

@@ -0,0 +1,4 @@
|RAM[16384]|RAM[17648]|RAM[18349]|RAM[19444]|RAM[20771]|RAM[21031]|RAM[22596]|RAM[23754]|RAM[24575]|
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| -1 | -1 | -1 | -1 | -1 | -1 | -1 | -1 | -1 |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |

View File

@@ -0,0 +1,37 @@
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/04/fill/FillAutomatic
// This script can be used to test the Fill program automatically,
// rather than interactively. Specifically, the script sets the keyboard
// memory map (RAM[24576]) to 0, 1, and then again to 0. This simulates the
// acts of leaving the keyboard untouched, pressing some key, and then releasing
// the key. After each on of these simulated events, the script outputs the values
// of some selected registers from the screen memory map (RAM[16384]-RAM[24576]).
// This is done in order to test that these registers are set to 000...0 or 111....1,
// as mandated by how the Fill program should react to the keyboard events.
load Fill.asm,
output-file FillAutomatic.out,
compare-to FillAutomatic.cmp,
output-list RAM[16384]%D2.6.2 RAM[17648]%D2.6.2 RAM[18349]%D2.6.2 RAM[19444]%D2.6.2 RAM[20771]%D2.6.2 RAM[21031]%D2.6.2 RAM[22596]%D2.6.2 RAM[23754]%D2.6.2 RAM[24575]%D2.6.2;
set RAM[24576] 0, // the keyboard is untouched
repeat 1000000 {
ticktock;
}
output; // test that the screen is white
set RAM[24576] 1, // a keyboard key is pressed
repeat 1000000 {
ticktock;
}
output; // test that the screen is black
set RAM[24576] 0, // they keyboard in untouched
repeat 1000000 {
ticktock;
}
output; // test that the screen is white

35
projects/04/mult/Mult.asm Normal file
View File

@@ -0,0 +1,35 @@
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/04/Mult.asm
// Multiplies R0 and R1 and stores the result in R2.
// (R0, R1, R2 refer to RAM[0], RAM[1], and RAM[2], respectively.)
// Put your code here.
@R2
M=0
(LOOP)
@R1
D=M
@END
D;JEQ
@R0
D=M
@R2
M=M+D
@R1
M=M-1
@LOOP
0;JEQ
(END)
@END
0;JMP

View File

@@ -0,0 +1,7 @@
| RAM[0] | RAM[1] | RAM[2] |
| 0 | 0 | 0 |
| 1 | 0 | 0 |
| 0 | 2 | 0 |
| 3 | 1 | 3 |
| 2 | 4 | 8 |
| 6 | 7 | 42 |

Some files were not shown because too many files have changed in this diff Show More