CPSC 213: Assignment 1

Due Mon Sep 17 6pm

Goal

The goals of this assignment are for you to get some of the preliminary stuff under your belt:

SimpleMachine Installation

The first part of the assignment is to create an Eclipse (or similar) development environment for the SM213 simulator that you will gradually implement over several assignments. Included in the lab material on the course home page is a zipped file of the incomplete simulator code (sm213-a1-Sep11.zip), an external jar file (SimpleMachineStudent.jar), and some test programs (snippets.zip).

Note that you must be use Java version 1.6 or later; Java 1.5 or 1.4 will not work.

At this point, opening any of the snippet programs from the provided snippets.zip should throw an exception since the memory access methods are unimplemented!

Reference Implementation For Testing

SimpleMachine213.jar contains the complete simulator for the SM213 machine. You may download and run this reference simulator. The simulator will help you understand better the machine architecture and the assembly language we use in the class. You can also use it to check how your assignment code should work.

As some of the assignments ask you to develop some parts of the program that is included in this jar, the jar does not contain the java code. Even though there are tools that could produce the java code from this jar, you are not allowed to use any of these tools and recover the code of this jar. Viewing the java code of this jar will be considered as an academic misconduct. Please use the jar only in the way that is described below.

The simulator is a jar file which can run from the command line using: java -jar <filename> Once the simulator starts running, test it by doing the following: You can also use the reference implementation to run any of the snippets from the provided snippets.zip file if you want a sneak preview of SM213 assembly; we will be going through these in detail over the next several weeks, so don't worry if they don't make sense to you yet.

Implementation of Memory Class

Implement the missing methods of the Memory class, in MainMemory.java (arch/sm213/machine/student/MainMemory.java). In doing so, you will implement accessor methods for access to memory (set and get), implement a method that determines whether an address is aligned, and implement methods that convert between an array of bytes and four-byte Big Endian integers. This class will be used for all memory access in subsequent assignments. Clarification Fri 9/14: you should also implement the MainMemory constructor and the length methods, as the comments say in the file.

To do these things, modify the class MainMemory in the package arch.sm213.machine.student. The full simulator has a large number of other classes that you can completely ignore for this assignment.

The get and set methods read and write directly to the given memory location and do not need to check for alignment. However, they should check for out-of-bounds accesses.

Implementing Big Endian conversion requires the use of Java's bit shifting operators (>>, >>>, and <<) and bit-wise logical operators (| and/or &). You can tell Java that you only want the low order byte of an integer by casting it to a byte (e.g., byte b = (byte) (i)).

One caution is that Java bytes are signed numbers and so shifting to the right or assigning byte into an int will sign extend the number, which might not be what you want. For example:

byte b = (byte) 0xff;
int i = b;


results in i storing -1 which in hex is 0xffffffff, not 0x000000ff.

You should test your code! Create a main function inside MainMemory.java and use it to test out your code thoroughly. Think back to what you learned in CPSC 210 about testing strategies - for example, carefully consider and test boundary conditions.

Material Provided

  1. sm213-a1-Sep11.zip
  2. SimpleMachineStudent.jar
  3. snippets.zip
  4. SimpleMachine213.jar
  5. test.s

What to hand in

The handin assignment directory name for this assignment is a1. Use the handin program at the command line (not the web version) to hand in the following:

  1. A single file called README.txt that includes your name, student number, and four-character cs-department undergraduate id (e.g., the one that's something like a0b1). It should also include the statement "I have read and understood the plagiarism policies at http://www.ugrad.cs.ubc.ca/~cs213/winter12t1/cheat.html". Of course, make sure that's true!

  2. Your implementation of the arch.sm213.machine.student.MainMemory class, in the file MainMemory.java.

Do not include any other files, such as other .java files or any class files.


Up to: UBC CS 213 Sep 2012