%% -*- Mode: LATEX -*-

\documentclass[11pt]{rhitcsse}

\input{cs232_defs}
\title{Lab 3 Handout}

\begin{document}

%\maketitle

\begin{minipage}[t]{3.25in}
\begin{verbatim}
int
main(int argc, char *argv)
{
  printf("The factorial of 10 is %d\n",
         fact(10));
}

int
fact(int n)
{
  if (n<1) {
    return(1);
  }
  else {
    return(n*fact(n-1));
  }
}
\end{verbatim}
\vspace{3in}
{\footnotesize
  \begin{tabular}{r|l|}
      \cline{2-2}
      \texttt{0x7FFFEDC0} & \\
      & \texttt{0x7FFFEDFC} \\
      & \texttt{0x0040008C}\\
      & \\
      \texttt{0x7FFFEDDC} & 9\\
      \cline{2-2}
      \texttt{0x7FFFEDE0} & \\
      & \texttt{0x7FFFEE1C} \\
      & \texttt{0x00400038}\\
      & \\
      \texttt{0x7FFFEDFC} & 10\\
      \cline{2-2}
      \texttt{0x7FFFEE00} & \\
      & \texttt{0x00000000} \\
      & \texttt{0x00400018}\\
      & \\
      \texttt{0x7FFFEE1C} & \\
      \cline{2-2}
      \multicolumn{1}{r}{\texttt{0x7FFFEE20}} & \multicolumn{1}{l}{}
    \end{tabular}}
\end{minipage}
\hspace{0.25in}
\begin{minipage}[t]{2.5in}
\begin{verbatim}
        main:   subu $sp, $sp, 32
                sw   $ra, 20($sp)
                sw   $fp, 16($sp)
                addu $fp, $sp, 28

                li   $a0, 10
                jal  fact

0x00400038      la   $a0, STRING
                move $a1, $v0
                jal  printf

                lw   $ra, 20($sp)
                lw   $fp, 16($sp)
                addu $sp, $sp, 32
                jr   $ra

        fact:   subu $sp, $sp, 32
                sw   $ra, 20($sp)
                sw   $fp, 16($sp)
                addu $fp, $sp, 28
                sw   $a0, 0($fp)
                lw   $v0, 0($fp)
                bgtz $v0, L2
                li   $v0, 1
                j    L1

        L2:     lw   $v1, 0($fp)
                subu $v0, $v1, 1
                move $a0, $v0
                jal  fact

0x0040008C      lw   $v1, 0($fp)
                mul  $v0, $v0, $v1

        L1:     lw   $ra, 20($sp)
                lw   $fp, 16($sp)
                addu $sp, $sp, 32
                j    $ra
\end{verbatim} %$
\end{minipage}

\end{document}

% Local Variables:
% mode:latex
% End:
