23.08.2015 Views

EECS 370 – Introduction to Computer Organization – Exam 1 w

EECS 370 – Introduction to Computer Organization – Exam 1 w

EECS 370 – Introduction to Computer Organization – Exam 1 w

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

8. Caller/Callee [19 pts]You are given the following two C functions:int foo(int a) {int w=2, x=3, y=4, z=5, v;w = a + x;w += bar(w, x);y = w + z;for (v = 0; v < 5; v++) {z += bar(w, y);}if (y > 20) return y;return w;}int bar(int a, int b) {int p=a, q=b, r, s=1;s += abs(-4);printf(“Values: %d,%d”, p, q);for (r = 0; r < 10; r++) {q = q + p;printf(“New q: %d”, q);}return q;}a) [4 points] Assume that in the function foo variables w, x, and y are all mapped <strong>to</strong> calleesavedregisters. How many s<strong>to</strong>re/load instructions will the compiler insert in the assemblycode of foo for saving and res<strong>to</strong>ring these three registers? [Note: we want <strong>to</strong> know howmany lw/sw instructions the compiler inserts, not how many would be executed] Indicate onthe code of foo where these instructions are inserted and then report the <strong>to</strong>tal below <strong>to</strong>receive any credit for your answer.1 sw instruction for each of w,x,y before “w=a+x”.1 lw instruction for each of w,x,y before “return y”1 lw instruction for each of w,x,y before “return w”sw instructions: _____3______lw instructions: ____6_______b) [11 points] To answer this question, fill the tables in the next page. You must show yourwork on the copy of the code at the bot<strong>to</strong>m of the next page <strong>to</strong> receive any credit.Assume that the function foo is called only once. How many s<strong>to</strong>re/load operations areexecuted for each variable in foo and bar? Do the analysis assuming for each variableboth a caller-saved and a callee-saved mapping, and consider the single call <strong>to</strong> foo and the<strong>to</strong>tal of all the resulting call(s) <strong>to</strong> bar. Assume that parameters a and b are s<strong>to</strong>red inspecial input parameter registers.Page 8 of 12

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!