
\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}
\usepackage{fancyvrb}
\usepackage{relsize}
\usepackage{hyperref}

\begin{document}

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

Directions: {\bf 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.

{\bf 1.} (10) Fill the blank:  The sign (+, -, 0) of the result of executing
a CMPL instruction is recorded in the
\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_.

{\bf 2.} Answer the following questions as to what occurs during
the execution (not the fetch) of the instruction

\begin{Verbatim}[fontsize=\relsize{-2}]
addl %eax, (%ebx)
\end{Verbatim}

\begin{itemize}

\item [(a)] (10) How many times will a number be placed onto the address
bus?

\item [(b)] (10) Which control lines will be used?

\end{itemize}

{\bf 3.} Consider the example of counting lower-case letters, pp.93ff,
but modified so that line 2 is

\begin{Verbatim}[fontsize=\relsize{-2}]
x:  .string "c29jem"
\end{Verbatim}

\begin{itemize}

\item [(a)] (15) For each of the line numbers and operands listed below,
state what addressing mode is being used. 

\begin{tabular}{|r|r|r|}
\hline
line & operand & addressing mode \\ \hline 
\hline
11 & \verb+$x+ & \  \\ \hline 
16 & \verb+(%eax)+ & \  \\ \hline 
16 & \verb+%bl+ & \  \\ \hline 
\end{tabular}

\item [(b)] (30) Suppose {\bf x} is at address 0x500c, and consider the
situation that will exist when we reach {\bf done}.  Show (in hex) the
contents at each of these addresses:

\begin{tabular}{|r|r|}
\hline
address & contents \\ \hline 
\hline
0x500c & \  \\ \hline 
0x500d & \  \\ \hline 
0x500e & \  \\ \hline 
0x500f & \  \\ \hline 
0x5010 & \  \\ \hline 
0x5011 & \  \\ \hline 
0x5012 & \  \\ \hline 
0x5013 & \  \\ \hline   
0x5014 & \  \\ \hline 
0x5015 & \  \\ \hline 
0x5016 & \  \\ \hline 
0x5017 & \  \\ \hline 
0x5018 & \  \\ \hline 
\end{tabular}

\end{itemize}

{\bf 4.} (25) Consider the code at the top of p.93, at the line

\begin{Verbatim}[fontsize=\relsize{-2}]
andl $-16,%esp
\end{Verbatim}

Suppose that before this instruction was executed, ESP contained
0x88888168.  What will it contain afterwards?

{\bf Solutions:}

{\bf 1.} EFLAGS register

{\bf 2.a} 2:  once to read the location pointed to by EBX and once to
write to it

{\bf 2.b} MEMR, MEMW

{\bf 3.a} 

\begin{tabular}{|r|r|r|}
\hline
line & operand & addressing mode \\ \hline 
\hline
11 & \verb+$x+ & immediate  \\ \hline 
16 & \verb+(%eax)+ & indirect  \\ \hline 
16 & \verb+%bl+ & register \\ \hline 
\end{tabular}

{\bf 3.b} 

\begin{tabular}{|r|r|}
\hline
address & contents \\ \hline 
\hline
0x500c & 63  \\ \hline 
0x500d & 32  \\ \hline 
0x500e & 39  \\ \hline 
0x500f & 6a  \\ \hline 
0x5010 & 65  \\ \hline 
0x5011 & 6d  \\ \hline 
0x5012 & 0  \\ \hline 
0x5013 & 0  \\ \hline   
0x5014 & 0  \\ \hline 
0x5015 & 1  \\ \hline 
0x5016 & 0  \\ \hline 
0x5017 & 1  \\ \hline 
0x5018 & 0  \\ \hline 
\end{tabular}

{\bf 4.}  First, -16 is -0x10, i.e. 0xfffffff0.  That last 0 is four 0
bits, while the fs are each 1111.  So, the mask will set the last four
bits of ESP to 0s, while leaving the other bits intact.  So, the
0x88888168 in ESP will change to 0x88888160.

\end{document}

