\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.} (15) The name for the Intel stack pointer register is
\_\_\_\_\_\_\_\_\_\_\_\_\_\_.
 
{\bf 2.} (20) Suppose we wish to call {\bf scanf()} from {\bf x.s}.  Then
instead of running {\bf as}, it's more convenient to run
\_\_\_\_\_\_\_\_\_\_\_\_\_\_
because the latter will automatically link in the C
\_\_\_\_\_\_\_\_\_\_\_\_\_\_.

{\bf 3.} (20) Suppose there is a certain C language function, {\bf f()},
with type {\bf int}, i.e. it has an integer return value.  Suppose the
compiler produces code in which the return value is held in ECX during
intermediate computation.  Fill in the blank in the code below, which
shows what the compiler produces near the end of the function.

\begin{lstlisting}
movl __________, __________
ret
\end{lstlisting}

{\bf 4.} I ran the code in pp.137-139 with GDB.  Here is part of my
session:

\begin{lstlisting}
Breakpoint 1, addone () at AddOne.s:25
25         push %ebx
(gdb) n
30         movl 8(%esp), %ebx  
(gdb) n
32         incl (%ebx)  # need the (), since the argument was an address
(gdb) info registers
eax            0xbffff7e4       -1073743900
ecx            0xcbe07bea       -874480662
edx            0x1      1
ebx            0x804a020        134520864
esp            0xbffff718       0xbffff718
ebp            0xbffff738       0xbffff738
esi            0x0      0
edi            0x0      0
eip            0x8048439        0x8048439 <addone+5>
eflags         0x200282 [ SF IF ID ]
cs             0x73     115
ss             0x7b     123
ds             0x7b     123
es             0x7b     123
fs             0x0      0
gs             0x33     51
\end{lstlisting}

\begin{itemize}

\item [(a)] (15) At what address is the return address ( the ``bread
crumbs'') stored?

\item [(b)] (15) At what address is {\bf x} (in the main program) stored?

\item [(c)] (15) During the execution (not fetch) of the {\bf incl}
instruction, what value(s) will be placed on the data bus?

\end{itemize}

\end{document}

{\bf Solutions:}

name of stack ptr:  ESP

calling scanf():  gcc, library

ECX:  movl %ecx, %eax

GDB session:  0xbffff71c, 0x804a020, 7, 8

