\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) Consider the code

\begin{lstlisting}
.data
.rept 2
.string "abc"
.endr
\end{lstlisting}

At what offset will the second 'c' be stored?

{\bf 2.} Consider the following code, which multiplies a word labeled
{\bf x} in the {\bf .data} segment by 9.

\begin{lstlisting}
.text
.globl _start
_start:
   movl blank (a), %edx
   movl blank (b), %ecx
   shll blank (c), %edx
   addl blank (d)
   movl %edx, blank (e)
\end{lstlisting}

\begin{itemize}

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

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

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

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

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

\end{itemize}

{\bf 3.} (20) Give a single assembly instruction that places 1s in bit
positions 0, 1 and 4 of EAX.

\end{document}

CODE TO MULTIPLY X BY 28:

.text
.globl _start
_start:
   movl $0, %edx
   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

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


