Project 5 | ||
In this part of the course you will have to read chapter 5 of the book (Computer Architecture), after reading the chapter you will have to read the following instructions to be able to implement project 5. Instructions Project 5a: Assembly Programming Objectives: To give you a taste of low-level programming in assembly language, and to introduce you to the Hack computer platform. In the process, you will get a hands-on understanding of the assembly process, and you will appreciate visually how the target platform executes the translated binary code on the hardware. The contract: Write and test the two programs described below. The first program carries out a typical processing task. The second program illustrates how computers handle keyboard input and screen output. Guidelines
The Multiplication Program (mult) The program's inputs are R0 and R1. The program computes the product R0*R1 and stores the result in R2. The algorithm can be iterative addition. Recall that the Hack platform maps R0, R1, and R2 on RAM addresses 0x0000, 0x0001, and 0x0002, respectively. The contract (in this program) is such that R0>=0, R1>=0, and R0 * R1<32768 . Your program need not test these conditions, but rather assume that they hold. To test the mult.bin on the CPU Emulator, you may use the test scripts mult.tst and mult.cmp. As usual, all these files should be in the same directory (e.g. ...hack/programs/mult on your computer). The IO-Handling Program (fill) 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 screen should be cleared. To
test fill.bin on the CPU Emulator, you may use the
fill.tst script. This script
loads fill.bin into the simulator and tells the user how to test the program
interactively.
Objectives: To develop an assembler that translates programs written in the Hack assembly language into Hack machine code. Your assembler must implement the languages specified in the "Hack Architecture and Assembler Language Specification" document. The contract: when loaded into your assembler, an xxx.asm file containing a Hack assembly language program should be translated into its corresponding Hack machine code and stored in an xxx.bin file. When loaded into the CPU Emulator, your translated xxx.bin program should effect the behavior described in the program's documentation. Proposed implementation plan Start by running our assembler on some of the test programs given below, and inspect the generated code. You can also execute the resulting *.bin programs in the CPU Emulator. This will give you a feeling on what your assembler is supposed to do. Then write the assembler, in three stages. First, write an assembler that can translate symbol-less programs. Then extend your assembler to handle symbols. Remember: if your assembler is not perfect, it's not the end of the world. Attach a document explaining what your assembler can and cannot do. You will get partial credit for any work that you do. Test programs Add: This program adds the numbers 2 and 3 and puts the result (5) in ram[0].
Max: This program performs the following operation: ram[2]=max(ram[0], ram[1]). Before executing it, put some values in ram[0] and ram[1]. Rect: This program draws a rectangle at the top left corner of the screen. The rectangle is 16 pixels wide and ram[0] pixels high. Before executing it, put some value in ram[0]. Pong: 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. Note 1: this program was written in the Jack programming language and translated by the Jack compiler into the assembly programs given below. Note 2: running this game in the CPU Emulator is a very slow affair, so don't expect a high-powered Pong game. In fact, this slowness is a virtue, since it enables your eye to track the graphical operations of the software. Later in the course this game will run much faster. Resources
|
||