\documentclass[noanswers,addpoints,10pt]{exam}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage[most]{tcolorbox}
\usepackage{datetime}
\usepackage{enumerate}
\usepackage{enumitem}
\usepackage{xltxtra}
\usepackage{listings}
\usepackage{listings-mips}

\usepackage{graphicx}
\usepackage{hyperref}
\usepackage{makecell}
\usepackage{multicol}
\usepackage{multirow}

\usepackage{tabularx}
\usepackage{textcomp}
\usepackage{tikz}
\usetikzlibrary{arrows,automata,decorations.pathmorphing,backgrounds,positioning,fit}
\usepackage{pgf-umlcd}

% compact itemized and then enumerated
\setlist{leftmargin=*,
  noitemsep,
  topsep=5pt,
  parsep=0pt,
  partopsep=0pt,
}

\setlist[enumerate]{leftmargin=*,
  itemsep=2pt,
  topsep=0pt,
  parsep=0pt,
  partopsep=0pt,
}


\usepackage{fontspec}
\setmainfont{Gentium Basic}
\setmonofont{Comic Code}[
  Scale          = 0.80,
  UprightFont    = *-Regular,
  ItalicFont     = *-Italic,
  BoldFont       = *-Bold,
  BoldItalicFont = *-Bold Italic
]

\lstset{
  language={},
  basicstyle=\ttfamily\small,
}

\DeclareMathOperator{\limplies}{\Rightarrow}
\DeclareMathOperator{\liff}{\iff}
\DeclareMathOperator{\lxor}{\oplus}
\DeclareMathOperator{\qeq}{\overset{?}{=}}
\DeclareMathOperator{\modulus}{\mathbf{mod}}
\DeclareMathOperator{\even}{even}
\DeclareMathOperator{\odd}{odd}
\DeclareMathOperator{\ddiv}{|}
\DeclareMathOperator{\ndiv}{\not|}
\DeclareMathOperator{\contra}{\Rightarrow\mskip-\thinmuskip\Leftarrow}
\newcommand{\Q}{\mathbb{Q}}
\newcommand{\R}{\mathbb{R}}
\newcommand{\Z}{\mathbb{Z}}
\renewcommand{\P}[1]{\mathbb{P}(#1)}

\DeclareMathOperator{\vowel}{vowel}
\DeclareMathOperator{\consonant}{consonant}
\DeclareMathOperator{\isprime}{prime}
\DeclareMathOperator{\equals}{equals}
\DeclareMathOperator{\divides}{divides}

% classname
\newcommand\examNumber{gStrLib --- Using \texttt{strncat}}
\newcommand\semester{Spring 2024}
\newcommand\className{Computer Organization}
\newcommand\classNumber{CIS~356}
\newcommand\classFullName{\classNumber~\className}
\renewcommand{\dateseparator}{-}
\yyyymmdddate

% /classname

\pagestyle{headandfoot}
\firstpageheader{\classFullName\\\semester}{\examNumber\\~}{\today\\~}
\runningheader{\examNumber}{}{\today}


\title{\examNumber}


\newenvironment{showExample}[1]{
  \begingroup
  \renewcommand{\solutiontitle}{\noindent\textbf{Example:}\enspace}
  \printanswers
  \begin{solution}[#1]
  }{
  \end{solution}
  \endgroup
}

\begin{document}

\subsection*{Introduction}
This is a group assignment on manipulating C-style (ASCIIZ) strings in
MIPS assembly functions.

\section*{Assignment Goals}
\paragraph{Learning Outcomes} After completing this group assignment,
each student is expected to be able to
  \begin{itemize}
  \item \textbf{Trace} C/Java code using \lstinline{char *} parameters.
  \item \textbf{Translate} simple C/Java \lstinline{char *} functions
    to MIPS.
  \item \textbf{Write} string functions in C/Java on the way to
    implementing them in MIPS.
\end{itemize}

\section*{Procedure}

Get out paper for a \emph{single} turn-in at the end of class. Copy
enough of each question so that the paper could stand alone as a study
guide.

\noindent
\textbf{Assign (Least-recently Held) Roles:} \emph{Manager}, \emph{Recorder},
\emph{Reflector}, \emph{Speaker}. Everyone should help the whole team
contribute and manage time.

\noindent
\textbf{Answer these questions:}

\begin{questions}
\question{} Assume the call to the \lstinline{new} \textbf{function}
  returns the \emph{address} of the new object in \lstinline{$v0} and
  that \lstinline{SomeNode} has the following C/Java definition:

\begin{lstlisting}[language=c++]
class SomeNode {
  SomeNode * other;
  int radius;
  int height;
};
\end{lstlisting}

  Translate the following C/Java to MIPS
\begin{lstlisting}[language=c++]
SomeNode * x = new SomeNode(); // Pretend no parameters for function
                               // *you* save result in global x
x->radius = 5;
x->height = x->radius + 11;
\end{lstlisting}

\question{} Thinking about the \lstinline{atoi} (ASCII-to-Int) code we
  wrote in class:
  \begin{parts}
  \part{} How did we convert from a \lstinline{char} with an ASCII
    code of a digit to the numeric value of the digit?
  \part{} Given a character variable, \lstinline{ch}, that contains a
    \emph{hexadecimal} digit (assume uppercase alphabetic), how could
    you use Java's \lstinline{String.indexOf} function to convert to
    its numeric value?
  \part{} Write \lstinline{int hextoi(char * hexstring)} that converts
    the \emph{non-null} string passed in into the equivalent
    \lstinline{int} value.
  \end{parts}


\question{} Let's assume you have working C/Java versions of\\
  \lstinline{int strlen(char * str)} and \\
  \lstinline{char * strncpy(char * destination, char * source, int n)}

  \begin{parts}
  \part{} Write \lstinline{char * chomp(char * str)} in C/Java
    \textbf{using} the given functions to make your code as simple as
    possible.
  \part{} Write
    \lstinline{char * strncat(char * destination, char * source, int n)}
    in C/Java \textbf{using} the given functions to make your code as simple as
    possible.
  \part{} What value(s) in the \emph{activation record} of
    \lstinline{strncat} do you count on remaining unchanged on calling
    the other library functions?
  \part{} In MIPS assembly what must you do with those values
    \textbf{before} calling the other function(s)?
  \end{parts}

\end{questions}
\end{document}

%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% End:
