CS 453 Programming Assignment #2 — MiniJava and MIPS warmup

Due Friday February 15th (by 6:00pm)
Preliminary Subversion Log
Due Monday, February 11th (by 11:59pm)
see below

Introduction

In this assignment you will be writing some MIPS functions so as to learn the stackframe layout we are using and to write some of the MIPS functions that will be in the MiniJava run-time library. Also you will be writing MiniJava programs and the corresponding MIPS assembly programs. This introduces you to the source and target languages for the MiniJava compiler. It also provides an opportunity for you to create a couple of MiniJava test cases.

The Assignment

Your MiniJava compiler will be generating MIPS assembly language, specifically you will be generating MIPS code that is compatible with the SPIM simulator (http://www.cs.wisc.edu/~larus/spim.html).

For this assignment, you need to implement the following functions in MIPS:

The MIPS functions will be called by the driver stackframe-testdriver.s (see stackframe-testdriver.c for an approximate C version). For grading we will use our own version of stackframe-testdriver.s, so do not modify the one given to "make things work". Put each MIPS implementation in a file named after the function, but remove the underscore. For example, _printint will be implemented in printint.s. We will be calling your routines by concatenating your .s files with stackframe-testdriver.s.

We will be using the same stack frame layout as is used in the code generated by the Wisconsin C-- Compiler. This is because in CS 553, we use the C-- compiler to help implement garbage collection for MiniJava. The stack frame layout you must implement is as follows:

$fp_main -->  |  $ra   |
              |  $fp   |
              | locals |
              | ...    |
$fp_func -->  | arg1   |
              | arg2   |
              | ...    |
              | $ra    |
              | $fp    |
              | locals |
              | ...    |
$sp  -->      | empty  |

You also need to implement the following programs in MiniJava and in MIPS. When running the MiniJava program using javac and java, you should get the same results as running the MIPS program through SPIM. These programs are so simple that we will be looking at the code to makes sure the actual computation is being done.

When writing the MiniJava program make sure to only use Java language features that are in the MiniJava grammar. You can test this by downloading the MJParser.jar and java-cup-11a-runtime.jar files and executing the following:
    % java -classpath java-cup-11a-runtime.jar -jar MJParser.jar Program.java
If you run into problems, look at the MiniJava grammar and determine whether the program you wrote can be generated by that grammar.

Getting Started

To get started, put the following MIPS program into a file called helloworld.s and run helloworld.s through spim by typing "spim helloworld.s" on any CS linux machine.
## helloworld.s
    .text
    .globl main
main:
    sw      $ra, 0($sp)     # PUSH
    subu    $sp, $sp, 4
    sw      $fp, 0($sp)     # PUSH
    subu    $sp, $sp, 4

    addu    $fp, $sp, 8     # point fp to first parameter, no params for main
    subu    $sp, $fp, 8     # size of frame = 4 + 4 + 4*numparams + 4*numlocals

    # print Hello World!

    # the number put into $v0 selects SPIM syscall
    # parameter should be passed in $a0
    la      $a0, hello_world
    li      $v0, 4
    syscall

exit_main:
    lw      $ra, 0($fp)
    move    $t0, $fp
    lw      $fp, -4($fp)
    move    $sp, $t0
    jr      $ra

        .data
hello_world:    .asciiz "Hello World!\n"
You will eventually want to start using a version of spim that provides statistics as to how many instructions are executed, etc. The path for that version is /s/bach/b/class/cs553/spim-7.2.1-keepstats/spim/spim.
  > /s/bach/b/class/cs553/spim-7.2.1-keepstats/spim/spim -keepstats helloworld.s

Some other examples to look at include sum5_all.s and readprint.s. sum5_all.s requires that you concatenate the implementation for printint to the file before running it.

Read the Appendix A: Assemblers, Linkers, and the SPIM Simulator from the third edition of Hennessy and Patterson, Computer Organization and Design: The Hardware/Software Interface for a description of various MIPS instructions and how to use SPIM system calls.

Submitting:

Preliminary Subversion Log

Assignment

Late Policy

Late assignments will be accepted up to 24 hours past the due date for a deduction of 20% and will not accepted past this period.


mstrout@cs.colostate.edu .... February 7, 2008