\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 blanks:  The analog of a compiler at the
assembly language level is called a \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_.  In
our class, we refer to it metaphorically  as a human
\_\_\_\_\_\_\_\_\_\_\_.

{\bf 2.} As you know, when writing functions/subroutines, we may
originally write one for use in one program but then find we can use
it---unchanged---in another program.  Suppose that is the case for the
subroutine {\bf findmin} in Section 3.6, pp.72ff; in other words, we
simply copy lines 54-95 to the source file of another program, and use
the subroutine there.  Say the array we'll be using it on begins at a
label {\bf z} and has 12 elements.  The relevant section of code will be

\begin{lstlisting}
movl ________________________ # blank (a)
________________________ # blank (b)
call findmin
movl $168,w
\end{lstlisting}

\begin{itemize}

\item [(a)] (15) State what should go in blank (a).

\item [(b)] (15) State what should go in blank (b).

\item [(c)] (15) Suppose the address of the memory location labeled {\bf z}
turns out to be 0x100c.  What value will be in EDX when the subroutine
returns (i.e. just before we execute the instruction involving 168)?

\end{itemize}

{\bf 3.} (15) Consider an instruction

\begin{lstlisting}
addl (%ecx), (%edx)
\end{lstlisting}

Assume that the two registers point to memory locations that the program
has permission to read from and write to.  Which one of the following is true?
(Note that this is NOT a multipart problem, and will occupy only one
line in your electronic file.)

\begin{itemize}

\item [(i)] There would be no assembler error message, and execution
would work as intended.

\item [(ii)] There would be no assembler error, but execution may
produce incorrect results.

\item [(iii)] There would be no assembler error, but execution may
produce a seg fault or other execution error.

\item [(iv)] There would be an assembler error, even though the
assembler could have translated the line to machine code that would work
as intended.

\item [(v)] There would be an assembler error, because no such machine
instruction exists.

\end{itemize}

{\bf 4.} (20) Consider the program in Section 3.6, pp.72ff.  Suppose we
assemble and link, creating an executable file {\bf badsort}.  We then
try to execute it ``normally'' from the shell command line:

\begin{lstlisting}
% badsort
\end{lstlisting}

Give the line number of the instruction in this source code
that will likely be the last one to execute before the program
encounters an execution error, e.g. a seg fault.

{\bf Solutions:}

{\bf 1.} assembler, clerk

{\bf 2.a} \lstinline{movl $z, %eax}

{\bf 2.b} \lstinline{movl $11, %ebx}

{\bf 3.} (v)

{\bf 4.}  52

\end{document} 
