



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




The exam is open book, and open notes. There are 3 questions, and each question is
worth 35 points; 100 points total is full credit. You will have 75 minutes (from 1:15 to
2:30) to take the exam. Pace yourself; if you find you are spending more than 25 minutes
on a problem, come back and finish it later. If a question is ambiguously worded, raise
your hand and I will come give you a clarification if appropriate. Important clarifications
will be written on the board. Time remaining will be announced periodically.
Suppose you are working for a software company whose main product is a complex,
expensive application program “A” that users run on a certain brand “W” of high-end
engineering workstations. You are in charge of reengineering the tool flow for the
company’s build process for its software releases, and you are considering whether the
company should switch to a new compiler that was just announced by the workstation
vendor. Your goal is for the application A, as seen by each individual user, to have the
best performance possible. The brochure from the vendor describing the new compiler
claims that it increases workstation W’s MIPS rating when running floating-point (FP)
code by 300%. You already know that, when compiled using the old compiler,
application “A” currently spends 60% of its time executing floating-point code.
1a. Identify the true nature of the problem to be solved, as an engineering problem. In
the specific scenario described, which of the following quantities is it your job to
be trying to optimize, and for each one that’s appropriate, should you be trying to
maximize or minimize that particular quantity? Circle one choice in each row.
i. Execution time of program A Maximize / minimize / neither
ii. Clock frequency of workstation W Maximize / minimize / neither
iii. CPI of program A on workstation W Maximize / minimize / neither
iv. MIPS rating of W when running A Maximize / minimize / neither
v. Performance of W on program A Maximize / minimize / neither
vi. Cost of the workstation W Maximize / minimize / neither
1b. Formulate the problem to be solved, as an engineering problem. For one of the
quantities from part A that you identified that you were trying to maximize or
minimize in this situation, compose an algebraic expression that gives the factor by
which that quantity would be improved if you were to switch to the new compiler.
You may use the following variables in your expression. If you need to use any
additional variables, please clearly state their definitions. (But, do not yet worry
about whether you know the values of all these variables for this problem or not!)
old,fp
code in program A that was compiled with the old compiler.
new,fp
old,fp
new,fp
the old/new compilers, measured over the course of an average run of
program A.
old,int
new,int
old,int
new,int
(non floating-point) code.
1c. Formulate the vendor’s claim about the MIPS rating in the form of an algebraic
expression that relates (some subset of) the above variables to each other.
1d. Formulate the information that you are given about the fraction of time spent running
floating point code as an algebraic expression in the above variables.
1e. At minimum, what additional information do you need that is not already given in the
problem statement if you are going to solve the problem?
1f. Now, assuming that the IC and CPI of integer code remains unchanged with the new
compiler, and that the IC of the floating-point code becomes 10× larger with the
new compiler, solve the problem. What is the value of your expression from part
(1b)? Should you switch to the new compiler? Why or why not?
Question #2 (CIO 2 / POs a,k,o) – Assembly to ML
Hand-assemble the following (Mini-)MIPS assembly-language code fragment to correct
machine language. Fill in your answer in binary in the table below. Also, annotate the
table with lines and labels that clearly delineate all of the fields of each instruction.
add $t1, $s0, $t
lw $t2, -4($t1)
31 0
Also, indicate the format type of each instruction (I, J, R) by writing the appropriate letter
to the left of its row.
Finally, write out the corresponding machine-language code as a pair of hexadecimal
words:
0x____________, 0x____________
Question #3 (CIO 3 / POs a,c,o)
The following C language function computes the integer square root, that is, given an
integer n ≥ 0, it returns the value r of the largest integer that is less than or equal to the
square root of n , or, in symbols,
r n
Design a correct implementation of this function in MIPS assembly language; that is,
hand-compile this C code to equivalent MIPS assembly. Use standard MIPS calling
conventions, except don’t worry about the frame pointer. Assume that an int is 32 bits.
Don’t worry about whether this particular algorithm does anything sensible when the
argument is negative (it doesn’t). It’s also not very efficient, but it works.
int sqrt(int n){ /* Find integer square root of n*/
int r=0; /* First trial square root = 0 */
while (rr <= n) / While it’s not too big, */
r++; /* keep making it bigger. */
return r-1; /* Too big, return previous. */
Please write neatly, comment your code, and draw a neat table showing any
correspondences that you may have set up between MIPS registers and C code variables.