\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.} (20) Fill in the blanks:  Consider two instructions, which we'll
call i1 and i2, with i2 immediately following i1, and with i1 not being
a jump of any kind.  Then just before i1 is finished executing, the
\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_ will contain the address of
\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_.  Just after i1 finishes, that address
will be copied to the \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_ bus.   Assume no
caches or instruction queues.

{\bf 2.} Consider the following code fragment:

\begin{Verbatim}[fontsize=\relsize{-2}]
...
     jnz aplace
     movl $0x7fffffff, %eax
aplace:
     movl $0x7fffffff, %ebx
     shll $2, %eax
     sall $2, %ebx
     addl %ecx,%edx
     ______________ ohhhhnoooo
...
\end{Verbatim}

\begin{itemize}

\item [(a)] (15) Suppose, both here and in subsequent parts, that the
offset of the first {\bf movl}, listed in the output of {\bf as -a},
turns out to be 0028.  At what offset will the second {\bf movl} begin?

\item [(b)] (15) In the output of {\bf as -a} in assembling this code,
what will be the machine language code generated for that second {\bf
movl}?

\item [(c)] (20) What will be the machine language code generated for 
{\bf jnz aplace}?

\item [(d)] (15) In the instruction following the second {\bf addl}, we'd
like to jump to {\bf ohhhhnoooo} if the last instruction produced a
situation in which the sum of two positive numbers came out
``negative.''  List all possible instructions that we could put in the
blank.

\item [(e)] (15) Suppose in running this code under GDB, we issue the
commands

\begin{Verbatim}[fontsize=\relsize{-2}]
(gdb) b aplace
(gdb) run
(gdb) p/x %eip
\end{Verbatim}

Say the output of the last command is 0x80400000.  Give a numerical
expression (hex numbers are OK), for the memory address of the beginning
of the {\bf .text} segment.

\end{itemize}

{\bf Solutions:}

{\bf 1.}  PC; i2, address

{\bf 2a.} The instruction will assemble to 5 bytes, so the next offset
will be 0x28 + 5 = 0x2d.

{\bf 2b.} bbffffff7f

{\bf 2c.} 7505

{\bf 2d.} {\bf js} or {\bf jo}

{\bf 2e.} 0x80400000 - (28+5)

\end{document}

