
\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}
\usepackage{hyperref}

\begin{document}

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

Directions: {\bf 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.

{\bf 1.} (20) Fill in the blank with a term from our course:  Compilers
for Intel machines typically have EBP play a major role in the
maintenance of a linked list of \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_.

{\bf 2.} (20) State all lines (if any) on p.151 in which the linker is
invoked.

{\bf 3.} (20) A ``mask'' is used in Chapter 7 in a couple of places.  Show
one such instruction in that chapter.

{\bf 4.} (20) The C library contains a function with the following
signature:

\begin{Verbatim}[fontsize=\relsize{-2}]
char *strncpy(char *s1, char *s2, int n);
\end{Verbatim}

It copies the first {\bf n} characters at {\bf s2} to {\bf s1}.

Suppose we wish to call this function in assembly language, copying 8
characters from the array pointed to by EBX to the array in the {\bf
.data} section beginning at a word with the label {\bf w}.  Show
assembly code to do this.

{\bf 5.} (20) Consider the code at p.153, bottom.   Fill in the 2 blanks:
If we insert 

\begin{Verbatim}[fontsize=\relsize{-2}]
printf("%x\n",*(p +      ));
\end{Verbatim}

between lines 3 and 4, it will print out the address of the assembly
code compiled from line \_\_\_\_\_\_\_\_\_\_\_.

add one to four lines of C code between
lines 7 and 8 that will print out in hex the address of instruction
following {\bf call g} compiled from line 12.

{\bf Solutions:}

{\bf 1.}  stack frames

{\bf 2.}  3

{\bf 3.} any of the AND instructions, e.g. in line 4, p.168

{\bf 4.} for example,

\begin{Verbatim}[fontsize=\relsize{-2}]
pushl $8
pushl %ebx
pushl $w
call strncpy
\end{Verbatim}

{\bf 5.} 2, 13

\end{document}

