\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) The execution (not fetch) of an IRET instruction makes 
\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_
\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_
\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_
(fill the first blank with a number, the second with
{\it more} or {\it fewer}, and the third with {\it read} or {\it write}
accesses to memory than does an RET.  Assume no cache.

{\bf 2.} (15) Page replacement policy is set by (i) hardware; (ii) system
software; (iii) the application programmer; (iv) a combination of (i)
and (ii); (v) a combination of (i) and (iii); (vi) a combination of (ii)
and (iii); (vii) a combination of (i), (ii) and (iii).

{\bf 3.} Consider the code

\begin{lstlisting}
int main() 
{
   int m;
   scanf("%d",&m);
   m++;
   printf("%d\n",m);
}
\end{lstlisting}

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

\begin{lstlisting}[numbers=left]
.LC0:
        .string "%d"
.LC1:
        .string "%d\n"
        .text
main:
        pushl   %ebp
        blank(a)
        andl    $-16, %esp
        subl    $32, %esp
        blank(b)    28(%esp), %eax
        movl    %eax, 4(%esp)
        blank(c)
        call    scanf
        movl    28(%esp), %eax
        addl    $1, %eax
        movl    %eax, 28(%esp)
        movl    28(%esp), %eax
        blank(d)
        movl    $.LC1, (%esp)
        call    printf
        blank(e)
        ret
\end{lstlisting}

\begin{itemize}

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

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

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

\item [(d)] (10) Fill blank (c).

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

\item [(f)] (15) Give the line numbers in the assembly code which could
cause a page fault when the instruction is executed (not fetched).  Do
NOT include any lines containing a blank, and do NOT include the
even-numbered lines.

\end{itemize}


{\bf Solutions:}

{\bf 1.}  2 more reads

{\bf 2,} (ii)

{\bf 3.a-e}

\begin{lstlisting}
.LC0:
        .string "%d"
.LC1:
        .string "%d\n"
        .text
main:
        pushl   %ebp
        movl    %esp, %ebp
        andl    $-16, %esp
        subl    $32, %esp
        leal    28(%esp), %eax
        movl    %eax, 4(%esp)
        movl    $.LC0, (%esp)
        call    scanf
        movl    28(%esp), %eax
        addl    $1, %eax
        movl    %eax, 28(%esp)
        movl    28(%esp), %eax
        movl    %eax, 4(%esp)
        movl    $.LC1, (%esp)
        call    printf
        leave
        ret
\end{lstlisting}

{\bf 3.f} 7, 15, 17, 21 23

\end{document}

