CPSC 213: Assignment 2

Due Mon Sep 24 2012, 6pm


The goal of this assignment is to become familiar with how simple expression statements in a high-level language (HLL) like C or Java are translated into sequences of multiple machine-level instructions in assembly language. In your previous experience of programming with an HLL this translation was performed by a piece of software known as a compiler --- but for this assignment, you will be the compiler.

Provided Code

Download the example code snippets for this assignment and carefully inspect them, comparing the HLL (.c) versions with the SM213 Assembly (.s) version. They contain examples of the types of expressions you will be expected to be able to translate into SM213 assembly language: global variables, arrays, assignment, and ALU operations. Using the reference simulator, step through and convince yourself of the correspondence between the high-level expression and the instructions the machine executes.

Your Task

Download the code snippets to implement and carefully inspect them. Your task for this assignment is to produce commented SM213 Assembly versions for each of these four code snippets. They are ordered in increasing complexity so you are strongly encouraged to start with the first and progress in order. When writing your solutions, refer to the provided examples and keep in mind the following points:

Provided Materials

Handing In

Use the handin program. The assignment directory is a2. Please hand in exactly and only the following files with the specified names.

  1. README.txt that contains
  2. a2_1.s containing your solution for a2_1.c
  3. a2_2.s containing your solution for a2_2.c
  4. a2_3.s containing your solution for a2_3.c
  5. a2_4.s containing your solution for a2_4.c

File Format Requirements

All files that you hand in, as specified above, must be in plain text format (ASCII) and should not contain any line longer than 128 characters. Make sure that you have a few blank lines at the end of each file to avoid cross-platform compatability problems with newlines. You should use editors that work well with source code to create your SM 213 Assembly (.s) files and README.txt files. Eclipse is a good choice that works on all platforms: even though you cannot run the assembly files directly from Eclipse, you can open and edit them within it, and then after saving them you can load them from your workspace directory into the simulator. On Macs, TextEdit is fine, and so is the XCode programming environment. On Windows, Notepad++ is fine. Definitely do not use Microsoft Word! You should also avoid Microsoft Visual Studio for creating assembly files, because the .s file suffix could lead the system to show you confusing error messages that are not relevant for you. If you're feeling adventurous, you can get started using Unix editors like emacs or vi; these are very powerful, but have a large learning curve.

In order to check that your files are formatted correctly on the department Linux servers, use the command cat [filename] to show the entire contents of a file in the terminal window, or less [filename] to scroll through a file page by page (using the space key to scroll).

Last modified: Mon Sep 17 06:16:07 PDT 2012