CS 453 Programming Assignment #2 — MiniJava and MIPS warmup

Due Wednesday February 17th (by 11:59pm)

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 MARS simulator (http://courses.missouristate.edu/KenVollmar/MARS/).

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 and then interpreting the full file in MARS.

We will be using the same stack frame layout as is used in the Patt and Patel book from CS 270. The calling convention is summarized in the stack frame example given to help with HW1, and we will be covering the calling convention in class.

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 MARS. 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 grabbing a copy of the MJ.jar from ~cs453/public and executing the following:
    % java -jar MJ.jar Program.java
The MJ generates a bunch of files (Program.java.*). Check them out if you would like, but they are irrelevant for this assignment. 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, download a copy of the Mars.jar file from http://courses.missouristate.edu/KenVollmar/MARS/, and run helloworld.s through MARS by typing "java -jar Mars.jar helloworld.s" on any CS linux machine.
## helloworld.s
    .text
    .globl main
main:
    # There is no need to store $ra and $fp
    # in main for MARS because execution always
    # starts at the top of the input .s file
    # and $ra and $fp always have initial 
    # values of 0.
            
            
    # print Hello World!

    # The number put into $v0 selects MARS syscall.
    # A parameter to a system call should be passed in $a0.
    li      $v0, 4
    la      $a0, hello_world
    syscall



exit_main:
    # HALT the MARS simulation.
    li      $v0, 10
    syscall

        .data
hello_world:    .asciiz "Hello World!\n"

Also make sure to check out the MARS IDE by typing "java -jar Mars.jar". Some other examples to look at include sum5.s and readprint.s. sum5.s requires that you concatenate your implementation for _printint before running it.

    % cat sum5.s printint.s > sum5_all.s
    % java -jar Mars.jar sum5_all.s

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 read the online syscalls notes for how to use MARS system calls.

Submitting the Assignment

Late Policy

Late assignments will be accepted up to 24 hours past the due date and time for a deduction of 20% and will not accepted past this period. Late means anything after 11:59pm on the day the assignment is due, including 12 midnight.


mstrout@cs.colostate.edu .... February 6, 2010