\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 On all Tests, 32-bit word size on Intel machines running Linux is
assumed unless otherwise stated.}

{\bf 1.} (20) The reason that the CPU, memory and I/O devices are able to
communicate with each other is that they are all connected to the 
\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_.

{\bf 2.} (20) Threads communicate with each other via
\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_ variables.

{\bf 3.} (15) Consider the ISR in pp.172-173.  Suppose we wish to give
this device the highest priority, in the sense of not allowing the ISR
to be interrupted.  Then we would insert a(n)
\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_
instruction after line
\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_.

{\bf 4.}  Here is a portion of the file {\bf PrimeThreads.s}, the
assembly language code produced by running {\bf gcc -S} on the  primes
counter, pp.201-203:

\begin{lstlisting}
 movl    $nextbaselock, (%esp)
 call    pthread_mutex_unlock
 movl    -20(%ebp), %eax
 cmpl    -16(%ebp), %eax
 jg      .L7
 movl    -20(%ebp), %eax
 movl    prime(,%eax,4), %eax
\end{lstlisting}

I then assembled and linked that to create an executable file {\bf prime1}.

\begin{itemize}

\item [(a)] (15) Show the full command that I used to create {\bf prime1}.

\end{itemize}

Problems (b) and (c) concern a subsequent GDB session I went through,
part of which was

\begin{lstlisting}
Breakpoint 1, worker () at PrimeThreads.s:87
87              jg      .L7
(gdb) info regs
Undefined info command: "regs".  Try "help info".
(gdb) info reg
eax            0x5      5
ecx            0x0      0
edx            0x1      1
ebx            0x144ff4 1331188
esp            0xb77e1360       0xb77e1360
ebp            0xb77e1398       0xb77e1398
esi            0xb77e1b70       -1216472208
edi            0x3d0f00 4001536
eip            0x804865f        0x804865f <worker+130>
eflags         0x283    [ CF SF IF ]
cs             0x73     115
ss             0x7b     123
ds             0x7b     123
es             0x7b     123
fs             0x0      0
gs             0x33     51
\end{lstlisting}

(You may find the tables on p.69 and p.104 to be helpful.)

\begin{itemize}

\item [(b)] (15) Will the jump be taken, i.e. will we jump to {\bf .L7}?
Briefly state why or why not (all your answer must be in a single line).

\item [(c)] (15) Where is the variable {\bf base} stored during the time
this function is active?  Answer in terms of registers (including
dereferencing etc., if appropriate).

\end{itemize}

{\bf Solutions:}

{\bf 1.} bus

{\bf 2.} global

{\bf 3.} CLI, 1

{\bf 4.a}

\begin{lstlisting}
gcc -g -o prime1 PrimeThreads.s -lpthread -lm
\end{lstlisting}

{\bf 4.b} no, since SF is 1 but OF is 0

{\bf 4.c}

\begin{lstlisting}
-20(%ebp)
\end{lstlisting}

\end{document}


