\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}
\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 the assembly code for the function {\bf Insert()} on
p.13 of the PLN unit on the JVM  The instruction {\bf aload\_0} in
offset 78 will push \_\_\_\_\_\_\_\_ onto the stack.  (Your answer must
be a variable name or a Java reserved word.)

{\bf 2.} (10) Consider these Java functions: 

\begin{Verbatim}[fontsize=\relsize{-2}]
public int sum2(int a, int b) 
{  return a+b; }

public int sum3(int u, int b, int c) 
{  return a+b+c; }

public int sum4(int u, int b, int c, int d) 
{  return a+b+c+d; }

\end{Verbatim}

The compiled code for {\bf sum3()} is

\begin{Verbatim}[fontsize=\relsize{-2}]
int sum3(int,int,int);
  Code:
   0:   iload_1
   1:   iload_2
   2:   iadd
   3:   iload_3
   4:   iadd
   5:   ireturn
\end{Verbatim}

The size of the compiled code for {\bf sum2()} has \_\_\_\_\_\_\_\_ more
bytes than that of {\bf sum3()}, while the size for {\bf sum4()} has
\_\_\_\_\_\_\_\_ more bytes than that of {\bf sum3()}.  (Your answers
must be positive, negative or zero integers.)

{\bf 3.} (15) The three lines in {\bf Tetris.s} beginning at line
\_\_\_\_\_\_\_\_ enable you to continue with other work after finishing
your game.

{\bf 4.} (15) Suppose {\bf x.s} has a label {\bf zzz} in the {\bf .text}
segment, and we wish execution to start there.  We assemble the file,
producing {\bf x.o}.  Show the {\bf ld} command we would need so as to
arrange execution to start at {\bf zzz}.

{\bf 5.} (20) A certain Java function is {\bf static} and has no arguments,
but has three local variables, declared as

\begin{Verbatim}[fontsize=\relsize{-2}]
int x,y,z;
\end{Verbatim} 

Fill in the following blanks in the code below, which does

\begin{Verbatim}[fontsize=\relsize{-2}]
z = (x+y) * (x+y+2);
\end{Verbatim}

\begin{Verbatim}[fontsize=\relsize{-2}]
iload_0
iload_1
________
________
iconst_2
iadd
________
________
\end{Verbatim}  

{\bf 6.} (10) A disadvantage of a virtually-mapped cache is that we could
not have blocks from different \_\_\_\_\_\_\_ simultaneously.

{\bf 7.} (20) The following code prints out a 2-hex-digit number in hex.
Fill in the blanks:

\begin{Verbatim}[fontsize=\relsize{-2}]
# prints out a 2-hex-digit number in hex
printx:
   # 3 pushl, not shown
   movl 16(%esp), %eax
   movl $0, %edx
   movl $0x10, %ecx
   idivl %ecx  # quotient, remainder in EAX, EDX
   pushl %eax
   call printhexdig
   pushl ________
   call printhexdig
   addl $8, %esp
   # 3 popl, not shown
   ret

printhexdig:
   # 5 pushl, not shown
   movl 24(%esp), %esi
   cmpl ________, %esi
   jge caseaf
   addl $'0', %esi
   jmp prnt
caseaf:
   subl $10, %esi
   addl $'a', %esi
prnt:
   movl $4, %eax
   movl $1, %ebx
   pushl %esi
   movl ________, %ecx
   movl $1, %edx
   int $0x80
   # 6 popl, not shown
   ret
\end{Verbatim}

{\bf Solutions:}

{\bf 1.}  {\bf this}

{\bf 2.}  -2, 3; for the latter, note that we'll need an {\bf iload}
instruction (with operand 4), since there is no such thing as {\bf
iload\_4}

{\bf 3.}  632 (three lines after {\bf gameover} beginning with {\bf
getterm})

{\bf 4.}  {\bf ld x.o -e zzz}

{\bf 5.}  {\bf iadd}, {\bf dup}, {\bf imul}, {\bf istore\_2}

{\bf 6.}  processes

{\bf 7.}  {\bf \%edx}, {\bf \$10}, {\bf \%esp}

\end{document}

