The Elements of Computing Systems (From NAND to Tetris)
The Elements of Computing Systems (From NAND to Tetris) : Building an Assembler for the assembly language we created
The first half of this coursewe focussed on building a hardware platform. From now on, we will focus on the computer’s software hierarchy, culminating in the development of a compiler and a basic operating system for a simple, object-based programming language.
The first and most basic module in this software hierarchy is the assembler. In particular, chapter 4 presented machine languages in both their assembly and binary representations. This section describes how assemblers can systematically translate programs written in the former into programs written in the latter. As the chapter unfolds, we explain how to develop a Hack assembler—a program that generates binary code that can run as is on the hardware platform built in chapter 5.
If you have the book, then proceed to read chapter 6. Alternately you can read the contents from this pdf.
Submitting Responses to Activities
At diycomputerscience.com, we normally encourage participants to blog their solutions to various course activities, and submit links to their blog posts for peer review. However, this course is based on a book, which is often used in university courses. For that reason, as well as for preserving the experience of future learners, the authors have requested that we follow the code sharing guidelines stated below. I request all course participants to co-operate with the code sharing policy stated below. Very soon I will create a private pastebin for this course where everyone is encouraged to post their solution code for peer review.
Code Sharing Policy: We developed this course and made all its materials freely available because we want as many people in the world to learn computer science on their own terms. We believe that students and self-learners who set out to do the hardware and software projects should have the benefit and challenge of doing original work, without seeing published solutions. Therefore, we request that you don't post solutions publicly on the web, e.g. in blogs or forums. If your course instructor or organizer creates a private space in which students can share their work outside the public domain, that's fine. Likewise, you can share your work with others using a password-protected space. Please use your judgment and help ensure that many more students, like you, will be able to fully benefit from this learning experience. Thx – Noam Nisan and Shimon Schocken
Activities
This session has the following activities. Please complete them and submit links to your work. A good place to publish your activities is your blog, website, some wiki, or any publicly accessible page on the Internet.
Activity 1 : TECS - Build an assembler
The Problem: Develop an assembler that translates programs written in Hack assembly language into the binary code understood by the Hack hardware platform. The assembler must implement the Translation Specification described in Chapter 6, Section 2. (If you remember, in an earlier activity, we had used the in-built assembler, whereas in this activity, we will create an assembler, similar to the in0built assembler which comes with the hardware simulator software).
You can implement your assembler in any programming language. You may also find the following two tools useful: the assembler and CPU Emulator supplied with the book. These tools allow you to experiment with a working assembler before you set out to build one yourself. In addition, the supplied assembler provides a visual line-by-line translation GUI, and allows online code comparisons with the outputs that your assembler will generate. For more information about these capabilities, refer to the Assembler Tutorial.
In the course of implementing the CPU, it is allowed (but not necessarily recommended) to specify and build some internal chips of your own. This is up to you. If you choose to create new chips not mentioned in the book, be sure to document and test them carefully before you plug them into the architecture.
We suggest building the assembler in two stages. First write a symbol-less assembler, i.e. an assembler that can only translate programs that contain no symbols. Then extend your assembler with symbol handling capabilities. The test programs that we supply for this project come in two such versions (without and with symbols), to help you test your assembler incrementally.
Steps:
- Create a directory named projects/06 on your computer and extract project 06.zip to it (preserving the directory structure embedded in the zip file).
- Write and test your assembler program in the two stages described above.
- You can use the following *.asm programs for testing your assembler. Run your assembler on each of these programs, and verify if the output is correct. Some of these programs come with a symbol-less version as well, to help you test your symbol-less assembler.
- This program should add the constants 2 and 3 and puts the result in R0 - Add.asm
- This program computes max(R0,R1) and puts the result in R2 - Max.asm, and the symbol-less version, MaxL.asm
- This program Draws a rectangle at the top left corner of the screen. The rectangle is 16 pixels wide and R0 pixels high - Rect.asm, and the symbol-less version, RectL.asm
- This program is a a single-player ping-pong game. A ball bounces constantly off the screen's “walls.” The player attempts to hit the ball with a bat by pressing the left and right arrow keys. For every successful hit, the player gains one point and the bat shrinks a little to make the game harder. If the player misses the ball, the game is over. To quit the game, press ESC. - Pong.asm, and the symbol-less version, PongL.asm
Blog your efforts, and submit a link to your blog post, using the submit form below.
If you are enrolled in this course, then please login to submit your response to this activity
- http://twitter.com/iamfritch submitted an activity response for activity 'TECS - Build a 16 bit OR' ... 13 days ago
- http://twitter.com/iamfritch submitted an activity response for activity 'TECS - Build a 16 bit AND' ... 14 days ago
- http://twitter.com/iamfritch submitted an activity response for activity 'TECS - Build a 16 bit NOT' ... 14 days ago
- http://twitter.com/iamfritch submitted an activity response for activity 'TECS - Build an XOR gate' ... 14 days ago
- http://twitter.com/iamfritch submitted an activity response for activity 'TECS - Build an OR gate' ... 14 days ago
- http://twitter.com/iamfritch submitted an activity response for activity 'TECS - Build an AND gate' ... 16 days ago
- http://twitter.com/iamfritch submitted an activity response for activity 'TECS - Build a NOT gate' ... 17 days ago
- http://twitter.com/iamfritch submitted an activity response for activity 'Download and install the TECS Hardware Simulator' ... 17 days ago
- http://twitter.com/iamfritch submitted an activity response for activity 'Download and install the TECS Hardware Simulator' ... 17 days ago
- http://twitter.com/AdamMBritt submitted an activity response for activity 'TECS - Build a 16 bit Incrementer' ... Feb 5, 2013
- http://twitter.com/AdamMBritt submitted an activity response for activity 'TECS - Build a 16 bit Adder' ... Feb 5, 2013
- http://twitter.com/AdamMBritt submitted an activity response for activity 'TECS - Build a Full Adder' ... Feb 5, 2013
- http://twitter.com/AdamMBritt submitted an activity response for activity 'TECS - Build a Half Adder' ... Feb 5, 2013
- http://twitter.com/AdamMBritt submitted an activity response for activity 'TECS - Build an 8 Way DMUX' ... Feb 4, 2013
- http://twitter.com/AdamMBritt submitted an activity response for activity 'TECS - Build a 4 Way DMUX' ... Feb 4, 2013
- http://twitter.com/AdamMBritt submitted an activity response for activity 'TECS - Build a 16 bit / 8 Way MUX' ... Feb 4, 2013
- http://twitter.com/AdamMBritt submitted an activity response for activity 'TECS - Build a 16 bit / 4 Way MUX' ... Feb 4, 2013
- http://twitter.com/AdamMBritt submitted an activity response for activity 'TECS - Build an 8 Way OR' ... Feb 4, 2013
- http://twitter.com/AdamMBritt submitted an activity response for activity 'TECS - Build a 16 bit MUX' ... Feb 4, 2013
- http://twitter.com/AdamMBritt submitted an activity response for activity 'TECS - Build a 16 bit OR' ... Feb 4, 2013
- http://twitter.com/AdamMBritt submitted an activity response for activity 'TECS - Build a 16 bit AND' ... Feb 4, 2013
- http://twitter.com/AdamMBritt submitted an activity response for activity 'TECS - Build a 16 bit NOT' ... Feb 4, 2013
- http://twitter.com/AdamMBritt submitted an activity response for activity 'TECS - Build a DMUX' ... Feb 4, 2013
- http://twitter.com/AdamMBritt submitted an activity response for activity 'TECS - Build a MUX' ... Feb 4, 2013
- http://twitter.com/AdamMBritt submitted an activity response for activity 'TECS - Build an XOR gate' ... Feb 4, 2013
- http://twitter.com/AdamMBritt submitted an activity response for activity 'TECS - Build an OR gate' ... Feb 4, 2013
- http://twitter.com/AdamMBritt submitted an activity response for activity 'TECS - Build an AND gate' ... Feb 4, 2013
- http://twitter.com/AdamMBritt submitted an activity response for activity 'TECS - Build a NOT gate' ... Feb 4, 2013
- http://twitter.com/AdamMBritt submitted an activity response for activity 'Download and install the TECS Hardware Simulator' ... Feb 4, 2013
- http://twitter.com/nimbledodo submitted an activity response for activity 'TECS - Build an ALU' ... Dec 12, 2012
- http://twitter.com/nimbledodo submitted an activity response for activity 'TECS - Build a 16 bit Incrementer' ... Dec 12, 2012
- http://twitter.com/nimbledodo submitted an activity response for activity 'TECS - Build a 16 bit Adder' ... Dec 12, 2012
- http://twitter.com/nimbledodo submitted an activity response for activity 'TECS - Build a Full Adder' ... Dec 12, 2012
- http://twitter.com/nimbledodo submitted an activity response for activity 'TECS - Build a Half Adder' ... Dec 12, 2012
- http://twitter.com/nimbledodo submitted an activity response for activity 'TECS - Build an 8 Way DMUX' ... Dec 5, 2012
- http://twitter.com/nimbledodo submitted an activity response for activity 'TECS - Build a 4 Way DMUX' ... Dec 5, 2012
- http://twitter.com/nimbledodo submitted an activity response for activity 'TECS - Build a 16 bit / 8 Way MUX' ... Dec 5, 2012
- http://twitter.com/nimbledodo submitted an activity response for activity 'TECS - Build a 16 bit / 4 Way MUX' ... Dec 5, 2012
- http://twitter.com/nimbledodo submitted an activity response for activity 'TECS - Build an 8 Way OR' ... Dec 5, 2012
- http://twitter.com/nimbledodo submitted an activity response for activity 'TECS - Build a 16 bit MUX' ... Dec 5, 2012
- http://twitter.com/nimbledodo submitted an activity response for activity 'TECS - Build a 16 bit OR' ... Dec 5, 2012
- http://twitter.com/nimbledodo submitted an activity response for activity 'TECS - Build a 16 bit AND' ... Dec 5, 2012
- http://twitter.com/nimbledodo submitted an activity response for activity 'TECS - Build a 16 bit NOT' ... Dec 5, 2012
- http://twitter.com/nimbledodo submitted an activity response for activity 'TECS - Build a DMUX' ... Dec 5, 2012
- http://twitter.com/nimbledodo submitted an activity response for activity 'TECS - Build a MUX' ... Dec 5, 2012
- http://twitter.com/nimbledodo submitted an activity response for activity 'TECS - Build an XOR gate' ... Dec 5, 2012
- http://twitter.com/nimbledodo submitted an activity response for activity 'TECS - Build an OR gate' ... Dec 5, 2012
- http://twitter.com/nimbledodo submitted an activity response for activity 'TECS - Build an AND gate' ... Dec 5, 2012
- http://twitter.com/nimbledodo submitted an activity response for activity 'TECS - Build a NOT gate' ... Dec 5, 2012
- http://twitter.com/nimbledodo submitted an activity response for activity 'Download and install the TECS Hardware Simulator' ... Dec 5, 2012
- http://twitter.com/davidosmith submitted an activity response for activity 'TECS - Write an IO bound program using our assembly language' ... Dec 2, 2012
- http://twitter.com/rvdkooy submitted an activity response for activity 'TECS - Build an ALU' ... Nov 28, 2012
- http://twitter.com/rvdkooy submitted an activity response for activity 'TECS - Build a 16 bit Incrementer' ... Nov 28, 2012
- http://twitter.com/rvdkooy submitted an activity response for activity 'TECS - Build a 16 bit Adder' ... Nov 28, 2012
- http://twitter.com/rvdkooy submitted an activity response for activity 'TECS - Build a Full Adder' ... Nov 28, 2012
- http://twitter.com/rvdkooy submitted an activity response for activity 'TECS - Build a Half Adder' ... Nov 28, 2012
- http://twitter.com/davidosmith submitted an activity response for activity 'TECS - Write a assembly language program to multiply two numbers' ... Nov 23, 2012
- http://twitter.com/davidosmith submitted an activity response for activity 'TECS - Get familiar with the assembler and CPU emulator' ... Nov 23, 2012
- http://twitter.com/davidosmith submitted an activity response for activity 'TECS - Build a 16-bit Program Counter' ... Nov 23, 2012
- http://twitter.com/davidosmith submitted an activity response for activity 'TECS - Build a 16-bit / 16384-register memory' ... Nov 23, 2012
- http://twitter.com/davidosmith submitted an activity response for activity 'TECS - Build a 16-bit / 4096-register memory' ... Nov 23, 2012
- http://twitter.com/davidosmith submitted an activity response for activity 'TECS - Build a 16-bit / 512-register memory' ... Nov 22, 2012
- http://twitter.com/davidosmith submitted an activity response for activity 'TECS - Build a 16-bit / 64-register memory' ... Nov 22, 2012
- http://twitter.com/davidosmith submitted an activity response for activity 'TECS - Build a 16-bit / 8-register memory' ... Nov 22, 2012
- http://twitter.com/davidosmith submitted an activity response for activity 'TECS - Build a 16 bit register' ... Nov 22, 2012
- http://twitter.com/davidosmith submitted an activity response for activity 'TECS - Build a 1 bit binary cell' ... Nov 22, 2012
- http://twitter.com/sairajeshwari submitted an activity response for activity 'TECS - Build an 8 Way DMUX' ... Nov 22, 2012
- http://twitter.com/sairajeshwari submitted an activity response for activity 'TECS - Build a 4 Way DMUX' ... Nov 22, 2012
- http://twitter.com/davidosmith submitted an activity response for activity 'TECS - Build an ALU' ... Nov 21, 2012
- http://twitter.com/davidosmith submitted an activity response for activity 'TECS - Build a 16 bit Incrementer' ... Nov 21, 2012
- http://twitter.com/davidosmith submitted an activity response for activity 'TECS - Build a 16 bit Adder' ... Nov 21, 2012
- http://twitter.com/davidosmith submitted an activity response for activity 'TECS - Build a Full Adder' ... Nov 21, 2012
- http://twitter.com/davidosmith submitted an activity response for activity 'TECS - Build a Half Adder' ... Nov 21, 2012
- http://twitter.com/davidosmith submitted an activity response for activity 'TECS - Build an 8 Way DMUX' ... Nov 21, 2012
- http://twitter.com/davidosmith submitted an activity response for activity 'TECS - Build a 4 Way DMUX' ... Nov 21, 2012
- http://twitter.com/davidosmith submitted an activity response for activity 'TECS - Build a 16 bit / 8 Way MUX' ... Nov 21, 2012
- http://twitter.com/davidosmith submitted an activity response for activity 'TECS - Build a 16 bit / 4 Way MUX' ... Nov 21, 2012
- http://twitter.com/davidosmith submitted an activity response for activity 'TECS - Build an 8 Way OR' ... Nov 21, 2012
- http://twitter.com/davidosmith submitted an activity response for activity 'TECS - Build a 16 bit MUX' ... Nov 21, 2012
- http://twitter.com/davidosmith submitted an activity response for activity 'TECS - Build a 16 bit OR' ... Nov 21, 2012
- http://twitter.com/davidosmith submitted an activity response for activity 'TECS - Build a 16 bit AND' ... Nov 21, 2012
- http://twitter.com/davidosmith submitted an activity response for activity 'TECS - Build a 16 bit NOT' ... Nov 21, 2012
- http://twitter.com/davidosmith submitted an activity response for activity 'TECS - Build a DMUX' ... Nov 21, 2012
- http://twitter.com/davidosmith submitted an activity response for activity 'TECS - Build a MUX' ... Nov 21, 2012
- http://twitter.com/davidosmith submitted an activity response for activity 'TECS - Build an XOR gate' ... Nov 21, 2012
- http://twitter.com/davidosmith submitted an activity response for activity 'TECS - Build an OR gate' ... Nov 21, 2012
- http://twitter.com/davidosmith submitted an activity response for activity 'TECS - Build an AND gate' ... Nov 21, 2012
- http://twitter.com/davidosmith submitted an activity response for activity 'TECS - Build a NOT gate' ... Nov 21, 2012
- http://twitter.com/davidosmith submitted an activity response for activity 'Download and install the TECS Hardware Simulator' ... Nov 21, 2012
- http://twitter.com/sairajeshwari reviewed a response submitted for activity 'TECS - Build a 4 Way DMUX' ... Nov 21, 2012
- http://twitter.com/sairajeshwari submitted an activity response for activity 'TECS - Build a 16 bit / 8 Way MUX' ... Nov 21, 2012
- http://twitter.com/sairajeshwari submitted an activity response for activity 'TECS - Build a 16 bit / 4 Way MUX' ... Nov 21, 2012
- http://twitter.com/sairajeshwari submitted an activity response for activity 'TECS - Build an 8 Way OR' ... Nov 21, 2012
- http://twitter.com/sairajeshwari submitted an activity response for activity 'TECS - Build a 16 bit MUX' ... Nov 21, 2012
- http://twitter.com/sairajeshwari submitted an activity response for activity 'TECS - Build a 16 bit OR' ... Nov 21, 2012
- http://twitter.com/sairajeshwari submitted an activity response for activity 'TECS - Build a 16 bit AND' ... Nov 21, 2012
- http://twitter.com/sairajeshwari submitted an activity response for activity 'TECS - Build a 16 bit NOT' ... Nov 21, 2012
- http://twitter.com/sairajeshwari submitted an activity response for activity 'TECS - Build a DMUX' ... Nov 21, 2012
- http://twitter.com/sairajeshwari submitted an activity response for activity 'TECS - Build a MUX' ... Nov 20, 2012
- http://twitter.com/sairajeshwari submitted an activity response for activity 'TECS - Build an XOR gate' ... Nov 20, 2012




