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 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.
4 3 2 1NOTE: It must be implemented recursively! For both CountDown.java and CountDown.s have your main routines call the countdown() method with the actual parameter 7.
class MyClass {
boolean b;
int i;
}
In the first instance set b to true and i to 42. In the second instance set b to false and i to 33. Then print the value of both fields in both object instances: one value per line.
% 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.
## 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.
tar cf PA2_groupname.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_groupname.tar
tar xf PA2_groupname.tar
cd PA2
cat stackframe-testdriver.s printint.s halloc.s localtest.s > all.s
java -jar Mars.jar all.s
javac CountDown.java
java CountDown > CountDown.java.out
java -jar Mars.jar CountDown.s > CountDown.s.out
diff CountDown.s.out CountDown.java.out
ObjectFun will be tested in the same way as CountDown.
The extra output that MARS generates:
MARS 3.8 Copyright 2003-2010 Pete Sanderson and Kenneth Vollmarwill be ignored.