CPSC 213: Assignment 6
Due Mon 29 October 2012, 6pm
The goal of this assignment is to explore the use of indirect jumps for the
implementation of switch statements and polymorphic dispatch. You will read 4
examples, and implement as well as decompile code that uses these constructs.
Download the example code snippets for this assignment
and carefully inspect them, comparing the HLL (.c and .java) versions with the
SM213 Assembly (.s) version. They contain examples of the types of statements
you will be expected to be able to translate to and from SM213 assembly language:
everything from the previous assignment, plus switch() and polymorphic
objects. Using the reference simulator, step through and convince yourself of the
correspondence between the high-level expression and the instructions the machine
executes. In particular, experiment with supplying different values to the switch
statement and modifying the function pointers in the method table.
Download the code snippets to work on and carefully
inspect them. Your task for this assignment is to produce commented SM213 Assembly
versions for the first two code snippets, produce a C version of the third, and
produce both C and Java versions of the fourth. When writing your solutions,
refer to the provided examples and keep in mind the following points:
- Do not assume any initial value for the registers.
- Follow the SM213 stack-based calling convention
and insert the this pointer as a parameter in front of all others for
methods. (E.g. a method void bar(int a, int b) in a class foo
would have a C-like declaration of void foo_bar(struct foo *this, int a, int b).
- These are snippets, not complete programs, and thus you should not
attempt to compile and run them. The syntax is mostly valid C or Java but there
are many places where things like memory allocation or pointer type agreement
have been glossed over in the interest of exposition clarity.
- For the third snippet, as with the examples, you do not need to provide the
constructors for the various classes.
- For the fourth snippet, do not attempt to go from Asm to Java directly;
write the C version first, then derive the Java from it. You do not need to
add constructors to the Java classes, although you are allowed to if you wish.
Use the handin program. The assignment directory is a6.
Please hand in exactly and only the following files with the specified names.
- README.txt that contains
- The first three lines should be your name, student number, and 4-character CS account
name, with each on a separate line, like:
- The statement "I have read and understood the plagiarism policies at
Of course, make sure that's true!
- Any additional assumptions or comments you would like to make.
Following the academic conduct guidelines, if you discussed the
assignment in detail with anybody besides the instructor or TAs, say
so explicitly and list their names here.
- a6_1.s containing your solution to a6_1.c
- a6_2.s containing your solution to a6_2.c/a6_2.java
- a6_3.c containing your solution to a6_3.s
- a6_4.c containing your C solution to a6_4.s
- a6_4.java containing your Java solution to a6_4.s
File Format Requirements
the section of the same name in the second assignment for the file format
requirements. All files you handin MUST be plain ASCII text, and all
SM213 code MUST load in the simulator in order to receive credit for it.
Last modified 2012-10-22 07:09