Laboratory assignment ยท 27 August
Lab 4: Hack Machine Language
Write and test two Hack assembly programs. When executed on the CPU emulator, your programs should generate the results required by the supplied project test scripts.
Back to course homePrograms
What to submit
Complete both source files with the exact required names and locations.
Mult.asm: multiplication
- File
projects/04/mult/Mult.asm- Inputs
- The current values stored in
R0andR1. - Output
- Compute
R0 * R1and store the result inR2. - Assume
R0 >= 0,R1 >= 0, andR0 * R1 < 32768. Your program need not test these conditions.- Test
- Run
Mult.tst. The output is checked againstMult.cmpon representative values.
Fill.asm: keyboard and screen I/O
- File
projects/04/fill/Fill.asm- Loop
- Run continuously in an infinite loop that listens to the keyboard.
- Key pressed
- Blacken the screen by writing black in every pixel.
- No key
- Clear the screen by writing white in every pixel.
- Order
- You may process pixels in any spatial order, as long as holding or releasing a key long enough eventually gives a fully blackened or cleared screen.
- Test
- Run
Fill.tst. There is no compare file, so inspect the simulated screen visually.
Workflow
Recommended procedure
Write, assemble, test, debug, and repeat until the emulator behavior is correct.
Steps
- Go to the assembler tab of the emulator.
- Click the "Load File" button. Open the file
projects/04/mult/Mult.asmorprojects/04/fill/Fill.asm. - Write your assembly code in the editor.
- Use the assembler to translate your program. If there are syntax errors, fix the source file and assemble again.
- After successful assembly, the assembler will produce
Mult.hackorFill.hack. You can either download the file or use the emulator's "Load in CPU Emulator" button to open it directly. - Use the CPU emulator to test
Mult.hackorFill.hack, either interactively or with the suppliedMult.tstorFill.tstscript. - To load the test script, click the "Load a test script" button and select the appropriate test file.
- If there are run-time errors or wrong results, edit
Mult.asmorFill.asm, assemble again, and rerun the emulator test. - Repeat the same process for
projects/04/fill/Fill.asmusing theprojects/04/filldirectory.