\documentclass[twocolumn]{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}

\setlength\columnsep{25pt}

\usepackage{fancyvrb}
\usepackage{relsize}
\usepackage{hyperref}

\usepackage{listings}
\usepackage{amsmath}

\begin{document}

\lstset{xleftmargin=5mm,framexleftmargin=10mm,basicstyle=\footnotesize}

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

Directions: {\bf \Large Work only on this sheet} (on both sides, if
needed).  MAKE SURE TO COPY YOUR ANSWERS TO A SEPARATE SHEET FOR SENDING
ME AN ELECTRONIC COPY LATER.

{\bf 1.} (20) Fill in the blank:  A \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_ is
located either in or near the CPU, and contains a copy of part of
memory.

{\bf 2.} (20) What will be printed out?

\begin{lstlisting}
char z = 'L';
printf("%c",z + 0x11);
\end{lstlisting}

{\bf 3.} (20) Suppose we are a 32-bit Intel machine.  Say {\bf z} is
declared as {\bf int}, {\bf \&z = 200} and {\bf z} contains $1 \cdot
16^5 +2 \cdot 16^4 + 3 \cdot 16^3 + 4 \cdot 16^2 + 5 \cdot 16 + 6$.  
State the contents (as a base-10 number) of Byte 202.

{\bf 4.} The function below finds the sum of the elements in column {\bf
colnum} of a two-dimensional array {\bf x} having {\bf nrow} rows and
{\bf ncol} columns.

\begin{lstlisting}
int colsum(int *x, int colnum, int nrow, int ncol)
{  
   int sum = 0, m, *p;
   p = ______________________;  // (a)
   for (m = 0; m < nrow; m++) {
      sum += *p;
      p += _______________________;  // (b)
   }
   return sum;
}
\end{lstlisting}

State what code should go in the blanks:

\begin{itemize}

\item [(a)] (10) Blank (a).

\item [(b)] (10) Blank (b).

\end{itemize}

{\bf 5.} (20) Consider a machine with 24-bit words and addresses.  We will
be storing numbers in the range 0,1,...,15; I'll call such numbers {\it
glonks}.  We want to store as many glonks as possible, so of course we
will store multiple glonks per word.  How many can we store in all of
memory?  Your answer must consist of an R expression.  Assume that our
machine has as much memory as possible, and that the operating system
etc. take up only negligible space.

{\bf Solutions:}

{\bf 1.} cache

{\bf 2.}  ']'

{\bf 3.} c({\bf z}) = 0x123456, and we are on a little-endian machine,
so 0x56 is in Byte 200, 0x34 in Byte 201 and 0x12 = 18 is in Byte 202.

{\bf 4.a} {\bf x + colnum}

{\bf 4.b}  {\bf ncol}

{\bf 5.} \lstinline{2 * 2^24}

\end{document}

