\documentclass{article}

\setlength{\oddsidemargin}{-0.5in}
\setlength{\evensidemargin}{-0.5in}
\setlength{\topmargin}{0.0in}
\setlength{\headheight}{0in}
\setlength{\headsep}{0in}
\setlength{\textwidth}{7.0in}
\setlength{\textheight}{9.5in}
\setlength{\parindent}{0in}
\setlength{\parskip}{0.05in}
\setlength{\columnseprule}{0.3pt}
\usepackage{fancyvrb}
\usepackage{relsize}

\begin{document}

Name: \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_

\textbf{Directions: Work only on this sheet (on both sides, if needed); do not
turn in any supplementary sheets of paper. There is actually plenty of room
for your answers, as long as you organize yourself BEFORE starting writing.
In order to get full credit, SHOW YOUR WORK.}

{\bf 1.}  Suppose a keyboard interrupt occurs during the execution of
line 27 of the full example program in Section 7 of our PLN unit on
subroutines.  Suppose also that:  c(IDT) = 50000; c(50008) = 2400; the
{\bf .data} segment starts at 1000; the {\bf .text} segment starts at
6000.

\begin{itemize}

\item [(a)] (15) The address of the keyboard ISR is \_\_\_\_\_\_\_\_\_\_.

\item [(b)] (15) Upon entry to the ISR, one value we can be sure is on the
stack is \_\_\_\_\_\_\_\_\_\_.  (Give a numerical answer.)

\end{itemize}

{\bf 2.}  (20) Consider the main example (summing elements of an array)
of macros in Section 10 of our PLN unit on subroutines.  Let Versions O,
S and M denote the original version of the code, the subroutine version,
and the macro version, respectively.  Then in terms of size of the
executable files produced, Version M has \_\_\_\_\_ more bytes than O,
and M has \_\_\_\_\_ more bytes than S.  During execution Version M
makes \_\_\_\_\_  more stack accesses than O, and M makes \_\_\_\_\_
more stack accesses than S.  (Fill in the blanks with positive or
negative integers, or 0.)

{\bf 3.}  (25) Consider the C code

\begin{Verbatim}[fontsize=\relsize{-2}]
int sum, x[1000000];
...
for (i = 0; i < n; i++)
   sum += x[i];
\end{Verbatim}

Suppose the block size is 1024 bytes, on a 32-bit machine.  What is the
smallest value of {\bf n} for which we can be sure that a {\bf
write-through} cache would do better than {\bf write-back}?

{\bf 4.}  (25) On p.5 of our PLN unit on the MIPS architecture, the code

\begin{Verbatim}[fontsize=\relsize{-2}]
x = 7;
addone(&x);
\end{Verbatim}

gets compiled to a total of \_\_\_\_\_
bytes of machine code. 

{\bf Solutions:}

{\bf 1.a}  2400

{\bf 1.b}  6000 + 0x18 = 6024

{\bf 2.}  0, -17, 0, -4

{\bf 3.}  If n = 256, write-through would write the same number of bytes
as write-back.  With n = 257, write-through is worse.

{\bf 4.}  The six pseudoinstructions expand to nine actual instructions.
Since each of the latter is four bytes long, the total size is 36 bytes.


\end{document}

