Yorkville High School Computer Science Department
Yorkville High School Computer Science Department on Facebook  Yorkville High School Computer Science Department Twitter Feed  Yorkville High School Computer Science Department on Instagram

Yorkville High School Computer Science

ASSIGNMENTS: Mobile App - May 10, 2019 :: UI Project - May 10, 2019 :: Web App - May 15, 2019 >>

Operating System Design :: Projects :: Jack Program

Due: Nov 8


Jack is a simple, modern, Java-like, object-based programming language. In the next two projects you will build a Jack compiler. Before setting out to do so, it makes sense to become familiar with the language itself.

Your task is to adopt or invent an application idea like a simple computer game or some other interactive program. Then design the application and implement it in Jack.


Writing Jack programs requires working with the Jack OS, just like writing Java programs requires working with the Java class library. The Jack OS can be viewed as a collection of software services, designed to extend the language's capabilities and close gaps between the computer's hardware and application software. For example, if you wish to compute the square root of a user-supplied number, you can write Jack statements like let x = Keyboard.readInt("Enter a number: "); followed by let y = Math.sqrt(x);

In the above example, the functions Keyboard.readInt and Math.sqrt are parts of the Keyboard and Math libraries, respectively, which are part of the Jack OS. The Jack OS includes eight such libraries, named Math, Screen, Output, Keyboard, Memory, String, Array, and Sys.

The Nand2tetris Software Suite includes two implementations of the Jack OS. One was written several years ago by Yaron Ukrainitz in the Jack language and translated using the Jack compiler into a set of 8 class files named Math.vm, Screen.vm, Output.vm, Keyboard.vm, Memory.vm, String.vm, Array.vm, and Sys.vm. These eight files are stored in your tools/os directory.

When you develop a Jack application, you end up writing and compiling one or more class files. The compiled code will most likely include various calls to OS routines. Thus, one natural way to integrate your app code with the OS code is to create a directory, say, MyApp, and put in it both your *.vm files as well as the eight *.vm OS files. Next, you can load MyApp into the supplied VM Emulator, and you're in business: as far as the emulator is concerned, your *.vm files and the OS *.vm files will run at the same level, and that's just fine.

Recently, Yannai Gunczarowski wrote the Jack OS in Java, and made it an integral and ubiquitous part of the supplied VM Emulator. Following this extension, you no longer have to put the eight OS *.vm files in your app directory; when your translated code will make a call to an OS routine, the call will be serviced by the supplied VM Emulator. This built-in implementation has two advantages: first, you don't have to include the eight OS files in your app directory; second, the built-in OS implementation is more efficient, and thus your app will run faster.

In short, you may ignore what the book says about integrating your files with the OS files. Instead, simply load your app directory into the supplied VM Emulator. There will be a warning message that you can ignore, and following that you can proceed to run and debug your app.

Running the Compiler at School

The batch file used to run the compiler tries to open command prompt, but it is blocked at school. If you are trying to run the compiler at school, follow these instructions written by Kurtis Bowen.

Using the jack compiler through the command prompt is blocked at school, typically one can run a command passing the directory as an argument. like this:

JackCompiler.bat /path/to/some/file

To circumvent this, you can modify the JackCompiler.bat file to use the directory you want to compile. You can either download the provided batch file, or copy and paste it from here (changing the last paramter to your directory):

//change the last parameter to the directory with your .jack files
java -classpath "%CLASSPATH%;bin/classes;bin/lib/Hack.jar;bin/lib/Compilers.jar" ^  Hack.Compiler.JackCompiler "C:\Users\kurti\Google Drive\Programs\NAND2\Operating-System-Design\09\Square"
echo Complete.


A Jack application is a set of one or more *.jack files. You can write these files in any text editor that generates plain text files. It is easier though to use a source code editor, like Notepad++, which can be customized to support different programming languages. For your convenience, we supply below a customization file that includes the Jack grammar conventions. So, you can follow these steps:

The relevant reading for this project is Chapter 9. You will need three tools, as follows: a text editor, to write your Jack program, the supplied JackCompiler, to compile it, and the supplied VM Emulator, to run and test it. Your app will most likely use the services of the Jack OS. Here is the Jack OS API, and a list of the Jack OS error codes.

To compile and run your Jack application you must do the following:

Yorkville High School Computer Science Department on Facebook Yorkville High School Computer Science Department Twitter Feed Yorkville High School Computer Science Department on Instagram