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

\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 Note:  In all problems on this exam, assume that all bits which are
not initialized by the programmer are set to 0.}

{\bf 1.}  Suppose our {\bf .data} segment begins with

\begin{verbatim}
u: .byte 11
   .byte 12
   .byte 13
   .byte 14
v:  .long 8
\end{verbatim}

Consider the instruction

\begin{verbatim}
movl $v, %edx
\end{verbatim}

\begin{verbatim}

\end{verbatim}

\begin{itemize}

\item [(a)] (10) Using official language from our course, state the addressing
modes for the source and destination operands in this instruction.

\item [(b)] (15) What machine language would the assembler produce from this
instruction?

\end{itemize}

{\bf 2.}  Consider the JVM assembly language code for {\bf
Minimum.class} in our notes.  Parts (a) and (b) are independent of
each other.  Do not consider the assumptions in one to apply to the
other.

\begin{itemize}

\item [(a)] (5) Suppose, due to a compiler error, the instruction at
offset 27 of {\bf main()} had been generated as

\begin{verbatim}
istore_1
\end{verbatim}

and we were to run

\begin{verbatim}
java Minimum 12 15
java Minimum 28 25
\end{verbatim}

What output would result?

\item [(b)] (10) Suppose the first statement in {\bf Min()},  just before
the {\bf if}, had been:

\begin{verbatim}
U = U + V;
\end{verbatim}

Show the resulting first four assembly language instructions for {\bf
Min()}.

\end{itemize}

{\bf 3.}  Answer either H (hardware), O (OS), B (both) or N (neither):

\begin{itemize}

\item [(a)]  (5) What writes to the PTR?

\item [(b)]  (5) What reads from the PTR?

\item [(c)]  (5) What writes to the page table?

\item [(d)]  (5) What reads from the page table?

\end{itemize}

{\bf 4.}  (15) Consider the {\bf addone()} example in our MIPS unit, but with 
{\bf addone()} being replaced by {\bf addsome()}.  The latter has a
second argument which is the amount to add to the variable pointed to by
the first.  In other words,

\begin{verbatim}
int x,n;

main()

{  x = 7; n = 5;
   addsome(&x,n);
   printf("%d\n",x);
}
\end{verbatim}

would print out 12.  Fill in the missing code (at most two instructions)
in this excerpt of the output of {\bf gcc -S}:

\begin{verbatim}
# addsome(&x,n)
la     $4,x
# missing code goes here
la     $25,addsome
jal    $31,$25
\end{verbatim} 

{\bf 5.} (15) Look at the OS code excerpt on p.8 of the OS unit.  Suppose
the designers of the OS had a field named {\bf pc} in the TSS {\bf
struct}s, 300 bytes past the start of the TSS.  Suppose also that they
wished to record in the TSS the value of the PC at the time of the
interrupt.  Fill in the blanks of the following code to do this
recording, just before the first {\bf movl} on p.8:

\begin{verbatim}
movl ______, %ebp
movl ______(%ebp), %ebp
movl _____, 300(_____)
\end{verbatim}

{\bf 6.}  (10) Suppose we get a seg fault at the declaration of a local
variable:

\begin{verbatim}
int x;
\end{verbatim}

There are no other locals.  Show the likely assembly language
instruction which triggered the error.

{\bf Solutions:}

{\bf 1.a.}  immediate, register

{\bf 1.b.}  0xba04000000

{\bf 2.a.}  Y would never be set, leaving it as 0.  Both output values
would be 0.

{\bf 2.b.}

\begin{verbatim}
iload_0
iload_1
iadd
istore_0
\end{verbatim}

{\bf 3.}  O, B, O, B (partial credit was given for H in (b))

{\bf 4.}

\begin{verbatim}
la $5, n
lw $5, 0($5)
\end{verbatim}

{\bf 5.}  \%esp, 12, \%ebp, \%ebx

{\bf 6.}  (See the example in our subroutines unit.)

\begin{verbatim}
movl $0, -4(%ebp)
\end{verbatim}

\end{document}

