Beruflich Dokumente
Kultur Dokumente
Monash University
Semester Two Mid Semester Test 2016
During an exam, you must not have in your possession, a book, notes, paper, electronic device/s, calculator,
pencil case, mobile phone or other material/item which has not been authorised for the exam or specifically
permitted as noted below. Any material or item on your desk, chair or person will be deemed to be in your
possession. You are reminded that possession of unauthorised materials in an exam is a discipline offence under
Monash Statute 4.1.
AUTHORISED MATERIALS
CALCULATORS o YES ü NO
OPEN BOOK o YES ü NO
SPECIFICALLY PERMITTED ITEMS o YES ü NO
STUDENT ID __ __ __ __ __ __ __ __
Page Mark
3
5
7
9
Total
Page 1 of 9
This page intentionally left blank, use if needed but it will not be
marked.
Page 2 of 9
Question 1 [3 marks]
This question is about MIPS programming. Translate the following Python code faith-
fully into MIPS assembly language. Note that in this piece of code all variables are
global variables. Add comments to your MIPS code to facilitate readability. Use only
instructions or pseudo-instructions in the MIPS reference sheet.
a = 3
b = 5
c = 0
while b > a :
if b % 2 == 0:
c = c + b
else :
c = c -b
b = b -1
Page 3 of 9
3
This page intentionally left blank, use if needed but it will not be
marked.
Page 4 of 9
Question 2 [2 marks]
For each function below, provide best and worst case complexity in Big O notation.
Explain your answer – no explanation means no marks.
Page 5 of 9
2
This page intentionally left blank, use if needed but it will not be
marked.
Page 6 of 9
Question 3 [3 marks]
A quick-sort implementation is given below:
def quick_sort ( a_list ):
start = 0
end = len ( a_list ) -1
quick_sort_aux ( a_list , start , end )
Page 7 of 9
3
This page intentionally left blank, use if needed but it will not be
marked.
Page 8 of 9
Question 4 [2 marks]
Consider the following python code, which you wish to translate into MIPS.
a = 2
b = 3
def my_function (a , b ):
i = a
# HERE
while i < b :
a = a + b
i +=1
return a
my_function (a , b )
Draw the memory diagram of the stack segment when code execution reaches the line
marked with the comment HERE. The diagram should show, the stack pointer and frame
pointer and any information that may be stored as part of the function calling convention
discussed in the lectures. Global variables are not on the stack, so they are not to be
shown. Before reaching my_function, ra = 0x00400000 and fp = 0x7FFFB3114.
Page 9 of 9
3
FIT1008 Supplementary Material - MIPS Reference Sheet
Page 2