Assignment 5
Due Date: 2015-2-24, 11:59pm
Objective
This assignment has two parts. First you must complete HDL implementations for the following 3 gates so that the tests are successful. This will wrap up the HDL portion of the class, and give you the full computer which we'll be using in the rest of the class.
- Memory
- CPU
- Computer - Note for Computer there are three separate tests.
- ComputerAdd - Adds 2 and 3, writes result to RAM[0]
- ComputerMax - Computes maximum of RAM[0] and RAM1[], writes result to RAM[2]
- ComputerRect - Draws a rectangle 16 pixels by x pixels, where x is in RAM[0].
Second, write a program that will convert .asm assembly code to .hack machine code in the same way the built-in assembler does. There are two sets of programs to test your assembler with.
- Symbol-less Programs (in increasing complexity)
- Add.asm
- MaxL.asm
- RectL.asm
- PongL.asm
- Programs with Symbols
- Max.asm
- Rect.asm
- Pong.asm
You should write a version of the assembler that handles programs with no symbols first, and once that is working correctly, then proceed to resolving symbols.
This is the first assignment that requires you to write your own code. Please see the Writing Code page for more information. Stubs for Java and Python are provided in your repos.
Your code will be run with one of the following commands:
- Java - java Assembler Something.asm
- Python - python assembler.py Something.asm
- C/C++ - ./assembler Something.asm
Tips and Resources
- For Memory, use the chips RAM16K, Screen and Keyboard. For CPU use any of the previously made chips, but instead of Register, use ARegister and DRegister. For the Computer, use the ROM32K for your instruction memory.
- For the invalid parts of memory, it is up to you what value you return if that memory address is requested. If you happen to return the value of the keyboard for all invalid addresses, that is valid.
- Chapter 5 and Chapter 6. Note that these are the last chapters which are available for free. If you have been finding the book useful, you should consider buying it!
- Your assembler output must match the built-in assembler's output. You can test this by loading your .hack file into the built-in assembler (using the equals icon in the toolbar, or going to File-->Load Comparison File) and then running the built-in assembler. This allows you to see exactly what lines are different.
- To make parsing easier, the test examples use minimal white space, i.e. D+A instead of D + A. You may assume that the input to your parser will be the same (as it is in the test files).
- In case it's useful to you, here's a table of comp mnemonics in text form.
0 | 0101010
| 1 | 0111111
| -1 | 0111010
| D | 0001100
| A | 0110000
| !D | 0001101
| !A | 0110001
| -D | 0001111
| -A | 0110011
| D+1 | 0011111
| A+1 | 0110111
| D-1 | 0001110
| A-1 | 0110010
| D+A | 0000010
| A+D | 0000010
| D-A | 0010011
| A-D | 0000111
| D&A | 0000000
| A&D | 0000000
| D|A | 0010101
| A|D | 0010101
| M | 1110000
| !M | 1110001
| -M | 1110011
| M+1 | 1110111
| M-1 | 1110010
| D+M | 1000010
| M+D | 1000010
| D-M | 1010011
| M-D | 1000111
| D&M | 1000000
| M&D | 1000000
| D|M | 1010101
| M|D | 1010101
|
|