For this assignment, you need to implement the following functions in MIPS:
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.
struct MyClass {
int i;
bool b;
};
In the first instance set i to 7 and b to true. In the second instance set i to 42 and b to false. Then print the value of both fields in both object instances: one value per line.
% 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.
## 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.
svn log and svn info with the checkin utility
~cs453/bin/checkin PA2_svnlog subversion_username.txt
tar cf PA2_username.tar PA2
svn log -r HEAD:1
svn info
svnlook tree REPOSITORY_PATH svnlook must be issued on a department machine
~cs453/bin/checkin PA2 PA2_username.tar
tar xf PA2_username.tar cd PA2 cat printint.s halloc.s localtest.s stackframe-testdriver.s > all.s spim all.s javac Factorial.java java Factorial > Factorial.java.out spim Factorial.s > Factorial.s.out diff Factorial.s.out Factorial.java.outObjectFun will be tested in the same way as Factorial. The extra output that spim generates:
SPIM Version 7.2.1 of August 28, 2005 Copyright 1990-2004 by James R. Larus (larus@cs.wisc.edu). All Rights Reserved. See the file README for a full copyright notice. Loaded: /usr/local/share/xspim/CPU/exceptions.swill be ignored.