\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}

\begin{document}

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

\textbf{Directions: 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.
In order to get full credit, SHOW YOUR WORK.}

{\bf 1.} (10) Consider what happens when the instruction {\bf popl \%edx}
is executed.  Circle all that are true:

\begin{itemize}

\item [(i)] EDX changes.

\item [(ii)] ESP changes.

\item [(iii)] A word in memory changes.

\end{itemize}

{\bf 2.} Look at the second GDB session printout covered by May in the
discussion section.  (It consists of an assembly language program
adapted from the example in Sec. 7 of our PLN unit on subroutines;
output from {\bf as -a}; and a GDB session.)

\begin{itemize}

\item [(a)] (10) Look at the lines

\begin{verbatim}
(gdb) p/x $esp
$4 = 0xbfffcec4
\end{verbatim}

Suppose this subroutine had had three arguments instead of two.\footnote{This
condition applies only to this part, not the other parts in this
problem.}  What value would have been printed out for ESP? 

\item [(b)] (10) Suppose we were to push {\bf \$x+16} instead of {\bf
\$x+4} on line 22.\footnote{This condition applies only to this part,
not the other parts in this problem.}  Choose one:

\begin{itemize}

\item [(i)] The assembler would announce an error.

\item [(ii)] The linker would announce an error.

\item [(iii)] GDB would announce an error.

\item [(iv)] A seg fault would occur.

\item [(v)] The program would run, and the final value in {\bf sum}
would be \_\_\_\_\_\_\_\_\_.

\end{itemize}

\item [(c)] (10) At what address does the {\bf .text} segment begin?

\end{itemize}

{\bf 3.} (10) In the ``{\bf u/v/w} story'' in Sec. 4.2 of our PLN unit on
OS, suppose that in the absence of timesharing, the programs {\bf u},
{\bf v} and {\bf w} would need 2 minutes, 5 hours and 4 hours to run,
respectively.  Then with timesharing, the total time by which {\bf v}
and {\bf w} would delay the completion of {\bf u} would be
\_\_\_\_\_\_\_\_\_\_\_\_.

{\bf 4.} (30) The assembly language subroutine {\bf preabx}, callable from
any assembly language code, will print out the value in EAX at the time
of the call.  The code is in the file {\bf preabx.s} (shown below),
which consists of a total of 9 lines.  Fill in the blanks: 

\begin{verbatim}
.text
________  
preabx:
      ________  
      ________  
      call printf
      addl ________, %esp  
      ret
z:    ________  
\end{verbatim}

{\bf 5.} (10) Fill in the blanks with numbers, possibly including 0:
When an interrupt occurs, the CPU's interrupt-response circuitry will
read \_\_\_\_\_\_\_\_ words from memory and write \_\_\_\_\_\_\_\_ words
to memory.  (Do not include the fetch of the first instruction of the
ISR.)
 
{\bf 6.} (10) Based on our class materials, deduce the machine language
instruction format of the CALL instruction we've been using.  Your
answer must consist only of 1s, 0s, IMMs, DDDs and SSSs \underline{and}
must \underline{fully} state the roles of the fields, similar to the
statement in our PLN unit on machine language:  ``[The] format for
immediate-to-register move [is] 10111DDDIMM4, where 10111 is the op
code, DDD denotes the destination register and IMM4 denotes a 4-byte
immediate constant.''  It is required that you supply a full explanation
of how you got your answer.

{\bf Solutions:}

{\bf 1.}  (i) and (ii)

{\bf 2.a}  0xbfffcec0

{\bf 2.b}  (v), 9059

{\bf 2.c}  0x8048074

{\bf 3.}  4 minutes

{\bf 4.}

\begin{verbatim}
.globl preax
push %eax
$8
.string "%x"
\end{verbatim}

{\bf 5.}  2, 3

{\bf 6.}  11101000IMM4, where IMM4 is the distance to the subroutine
from the instruction following the call

\end{document}

