Assignment 4

Due Date: 2015-2-15, 11:59pm

Objective

Write assembly code for the three programs below so that the tests are successful and/or they work as described.
  1. Multiplication - (Mult.asm) - Multiplies R0 and R1 and stores the result in R2. (R0, R1, R2 refer to RAM[0], RAM[1], and RAM[3], respectively.)
  2. Fill - (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. When no key is pressed, the program clears the screen, i.e. writes "white" in every pixel.
  3. Difference Engine - (Diff.asm) - Simulates the running of the difference engine.

Important Note: Starting with this assignment, some points will be given based on code style and efficiency. For assembly programs, you should indent all non-label lines and use meaningful variable names.

Tips and Resources

  • There's a Handy Dandy Assembly Code Guide for you to reference.
  • It may be useful to write your programs in the regular programming language of your choice first. To make things clearer, one version of the Difference Engine code has been provided: DifferenceEngine.java.
  • The general workflow for this assignment is:
    1. Write the programs in assembly.
    2. Use the supplied Assembler to create a .hack file, which contains the machine code.
    3. Load the .hack file into the supplied CPUEmulator, either manually or using the test files.
  • Note that the assembly is case sensitive.
  • Mult and Diff have the standard associated test and compare files, but Fill.asm only has the test. You need to visually confirm that it works.
  • For the multiplication program, you can assume that both numbers are positive integers, and the product of the two of them are less than 32768 (i.e. will not overflow). You do NOT have to check for this. Just assume the input will meet these conditions.
  • For the fill program, it does not matter what order you blacken or clear the screen, as long as you get the desired effect after keeping the same keyboard input for long enough. However, you should write the program in such a way that the screen is drawn efficiently without flickering.
  • To ensure your code is slightly more robust, your Diff code will be tested on additional inputs beyond the one in the test case.
  • Chapter 4 has more on the assembly language.