\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.} (15) In the Tetris game, the macro \_\_\_\_\_\_\_\_ and the
subroutine \_\_\_\_\_\_\_\_ do work which is similar to the \%d
portion of the {\bf print()} subroutine you wrote for Homework V.

{\bf 2.} (15) At the end of the game Tetris, the first digit of the
score will be written at row \_\_\_\_\_\_\_\_ and column
\_\_\_\_\_\_\_\_ of the screen.  (Your answers must be numbers, not
symbols.)

{\bf 3.} (15) We have a method whose declaration begins with

\begin{Verbatim}[fontsize=\relsize{-2}]
private int q(int a, int b)
{  int x,y;
\end{Verbatim}

The following JVM byte code begins at offset 28:  1c 08 a2 00 4b.  {\it
Disassemble} these instructions, i.e. give the corresponding JVM
assembly language.

{\bf 4.} (15) In our PLN unit on the JVM, Thomas Fifield shows some
``unnatural'' compiled code and then compares it with the ``natural
code,'' pointing out that the latter produces longer code.  In terms of
program size, the ``natural'' code uses \_\_\_\_\_\_\_\_ more bytes than
the ``unnatural'' code.  (Answer with a positive, negative or zero
integer.)

{\bf 5.} (20) The source code

\begin{Verbatim}[fontsize=\relsize{-2}]
N.Next = this;
\end{Verbatim}

on line 37 of p.12 of our PLN unit on the JVM compiles to the
instructions in offsets \_\_\_\_\_\_\_\_ through \_\_\_\_\_\_\_\_.

{\bf 6.} (20) Suppose a program occupies just two pages, for the {\bf
.data} and {\bf .text} segments.  The {\bf .data} segment has virtual
page number 0x22 and physical page number 0x188.  The corresponding
values for the {\bf .text} segment are 0x23 and 0x6, respectively.  The
page table begins at 0x20000.  Assume the structure on p.17 of our PLN
unit on OS, with bits 7-0 always containing 0s.  Then the page table
entry for the {\bf .data} segment is in word \_\_\_\_\_\_\_\_, with the
entry value being \_\_\_\_\_\_\_\_, and the entry for the {\bf .text}
segment is in word \_\_\_\_\_\_\_\_, with the entry value being
\_\_\_\_\_\_\_\_ Give your answers in hex.

{\bf Solutions:}

{\bf 1.}  {\bf twodigits}, {\bf numbertostring}

{\bf 2.}  See the lines following {\bf gameover}, and in the Makefile.
The string ``Loser'' is written at row 19, column 0, so the score will
be written at row 20, column 8.

{\bf 3.}

\begin{Verbatim}[fontsize=\relsize{-2}]
iload_2
iconst_5
if_cmpge 105
\end{Verbatim}

{\bf 4.}  3

{\bf 5.}  86, 88

{\bf 6.}  First entry is at 0x20000 + 4*0x22 = 0x20088.  The page is
resident (since it has a physical address), readable and writable, but
not executable.  The entry is thus 0x00188e00.  The second entry is at
0x2008c and contains 0x00006d00.

\end{document}

