\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 On all Tests, 32-bit word size on Intel machines running Linux is
assumed unless otherwise stated.}

{\bf 1.} (15) Say we have a multicore machine.  Among the registers EAX,
EBP, EFLAGS, ESP, ESI, IDT and PTR, state which must have separate
versions in each core.  For example, if you state EAX has such a
property, that means that each core must have its own separate EAX
register, rather than one EAX register serving all cores.  Hint:  There
will be at least one register in the list with this property.

{\bf 2.} (20) How many times will the hardware consult the page table
(assume no TLB or other cache) during the execution (not decode) of each
of the following instructions:

\begin{itemize}

\item [(a)] ()

\begin{lstlisting}
incl %eax
\end{lstlisting}

\item [(b)] ()

\begin{lstlisting}
addl (%eax), %ebx
\end{lstlisting}

\item [(c)] ()

\begin{lstlisting}
movl x, %ebx
\end{lstlisting}

\item [(d)] ()

\begin{lstlisting}
movl $x, %ebx
\end{lstlisting}

\end{itemize}

{\bf 3.} Consider the code

\begin{lstlisting}
int colsum(int *x, int nrow, int ncol, 
   int whichcol)
{
   int i, sum = 0;
   for (i = 0; i < nrow; i++) {
      sum += x[nrow*i + whichcol];
   }
   return sum;
}
\end{lstlisting}

Running this through {\bf gcc -S} yields:\footnote{I've removed some
extraneous material.} 

\begin{lstlisting}
colsum:
	pushl	%ebp
	movl	%esp, %ebp
	subl	$16, %esp
	movl	$0, -8(%ebp)
	movl	$0, -4(%ebp)
	jmp	.L2
.L3:
	movl	12(%ebp), %eax
	imull	blank(a)(%ebp), %eax
	addl	20(%ebp), %eax
	sall	$blank(b), %eax
	addl	8(%ebp), %eax
	movl	(%eax), %eax
	addl	%eax, -8(%ebp)
	addl	blank(c), -4(%ebp)
.L2:
	movl	-4(%ebp), %eax
	cmpl	12(%ebp), %eax
	jl	blank(d)
	movl	-8(%ebp), blank(e)
	leave
	ret
\end{lstlisting}

\begin{itemize}

\item [(a)] (15) Fill blank (a).

\item [(b)] (15) Fill blank (b).

\item [(c)] (15) Fill blank (c).

\item [(d)] (15) Fill blank (d).

\item [(e)] (5) Fill blank (e).

\end{itemize}

{\bf Solutions:}

{\bf 1.} all but IDT

{\bf 2.} 0, 1, 1, 0

{\bf 3.}

\begin{lstlisting}
colsum:
	pushl	%ebp
	movl	%esp, %ebp
	subl	$16, %esp
	movl	$0, -8(%ebp)
	movl	$0, -4(%ebp)
	jmp	.L2
.L3:
	movl	12(%ebp), %eax
	imull	-4(%ebp), %eax
	addl	20(%ebp), %eax
	sall	$2, %eax
	addl	8(%ebp), %eax
	movl	(%eax), %eax
	addl	%eax, -8(%ebp)
	addl	$1, -4(%ebp)
.L2:
	movl	-4(%ebp), %eax
	cmpl	12(%ebp), %eax
	jl	.L3
	movl	-8(%ebp), %eax
	leave
	ret
\end{lstlisting}

\end{document}

