\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 In all Test problems, assume 32-bit words unless stated otherwise.}

{\bf 1.} (20) Fill in the blanks:  During the execution of the jump
instruction in line 24, p.94, the jump will be done if the 
\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_ Flag and the
\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_ Flag bits satisfy certain
conditions.

{\bf 2.}   Consider the following code, which multiples each element in
an array of 4 words by 28.  It is assumed that {\bf x} is a label in the
{\bf .data} segment (not shown), that all elements of {\bf x} are
considered unsigned, and that no product will need more than 32-bits.

\begin{lstlisting}
.text
.globl _start
_start:
   blank (a) (entire line)
   movl $28, %ebx
   movl $4, %ecx
top:
   movl x(%edi), %eax
   imul blank (b)
   movl %eax, x(%edi)
   decl %ecx
   jz done
   blank (c) (entire line)
   blank (d) (entire line)
done:  movl $0, %edi
\end{lstlisting}

\begin{itemize}

\item [(a)] (10) State what goes in blank (a).

\item [(b)] (10) State what goes in blank (b).

\item [(c)] (10) State what goes in blank (c).

\item [(d)] (10) State what goes in blank (d).

\item [(e)] (15) Suppose that the initial values in {\bf x} are 2, 5, 1 and 8,
and that we had used EDX instead of EDI in the above code.  State the
final values in {\bf x}.

\end{itemize}

{\bf 3.} (25) List all lines in the letter-counting code, Section 3.14,
that access memory during the execution (not fetch) cycle.

{\bf Solutions:}

{\bf 1.} Sign, Overflow

{\bf 2.a-d}

\begin{lstlisting}
.text
.globl _start
_start:
   movl $0, %edi
   movl $28, %ebx
   movl $4, %ecx
top:
   movl x(%edi), %eax
   imul %ebx
   movl %eax, x(%edi)
   decl %ecx
   jz done
   addl $4, %edi
   jmp top
done:  movl $0, %edi
\end{lstlisting}

{\bf 2.e}  Even though we know the product is unsigned and will fit in
EAX, IMUL won't know that, and will sign-extend in EDX.  That will wipe
out our value of expressions like \lstinline{x(%edx)}.  So, only the
first element of {\bf x} will be changed, and the final values in that
array will be 140, 5, 1, 8.

{\bf 3.} 16, 30

\end{document}

CODE TO MULTIPLY X BY 28:


PART (E) OF THE MUL28 PROBLEM:  56, 5, 1, 8 (EDX gets wiped out by IMUL)

CODE TO MULTIPLY 8 BY 9:

.text
.globl _start
_start:
   movl x, %edx
   movl %edx, %ecx
   shll $3, %edx
   addl %ecx, %edx
   movl %edx, x

FLAGS PROBLEM:  Sign, Overflow Flags

MEMORY ACCESSES BY LETTER-COUNTING CODE: 16, 30

OFFSET OF SECOND 'c':  6

PLACE 1S IN POS. 0, 1, 4 OF EAX:

orl $13, %eax


