Operating System Design :: Projects :: Rise of the Machine Language
Problem
This project will give you a taste of low-level programming in machine language and get you acquainted with the Hack computer platform. In the process of working on this project you will become familiar with the assembly process - translating from symbolic language to machine-language - and you will appreciate visually how native binary code executes on the target hardware platform. These lessons will be learned in the context of writing and testing the two low-level programs described below.
Program 1: Multiplication
In the Hack framework, the top 16 RAM words (RAM[0] ... RAM[15]) are also referred to as the so-called virtual registers R0 ... R15. With this terminology in mind, this program computes the value R0*R1 and stores the result in R2.
For the purpose of this program, we assume that R0>=0, R1<=0, and R0*R1<32768 (you are welcome to ponder where this value comes from). Your program need not test these conditions, but rather assume that they hold. To test your program, put some values in RAM[0] and RAM[1], run the code, and inspect RAM[2]. The supplied Mult.tst script and Mult.cmp compare file are deigned to test your program "officially", running it on several representative values supplied by us.
Program 2: I/O Handling
This program illustrates low-level handling of the screen and keyboard devices. In particulate, the program 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.
You may choose to write code that blackens and clears the screen's pixels in any spatial/visual order, as long as pressing a key continuously for long enough will result in a fully blackened screen, and not pressing any key for long enough will result in a fully cleared screen. We provide a test script (Fill.tst), but no compare file. The program should be checked visually by inspecting the simulated screen of the supplied CPU Emulator.
- Use a plain text editor to write the first assembly program. You can do it by loading and editing the supplied projects/04/mult/Mult.asm file.
- Use the supplied Assembler (in either batch or interactive mode) to translate your program. If you get syntax errors, go to step 1. If there are no syntax errors, the assembler will produce a file called projects/04/mult/Mult.hack, containing binary instructions written in the Hack machine language.
- Use the supplied CPU Emulator to load, and then test, the translated Mult.hack code. This can be done either interactively, or batch-style using the supplied Mult.tst script. If you get run-time errors, go to step 1.
- Repeat stages 1-3 for the second program (Fill.asm), working in the projects/04/fill directory.