\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=[mips]assembler,
  basicstyle=\ttfamily,
}

\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{gMIPS-001 A First Group Project}
\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 assignment is a \emph{group} assignment. If I, in the room, do
not \textbf{hear} you interacting with the other students, you are
doing it \emph{wrong}!

\subsection*{Note}
\begin{itemize}
\item By \textbf{design}, this assignment includes questions about
  topics that you have not yet seen in lecture to encourage
  \emph{creative} exploration.
\item Work together on \emph{each} question. I \textbf{must} hear the
  group discussing the questions and the answers. All group members
  \textbf{must} participate.
\item Constructing your own model is more important than the ``right''
  answer. Read, think, discuss the material \textbf{together}. This
  process is \textbf{short-circuited} by looking the material up
  without engaging with it.
\item Each student in the group has more or less experience with the
  topics in the assignment. If you have greater familiarity
  with the topics, \emph{please} hold back a little bit so others can
  engage with building their own knowledge. You, too, must engage
  because there is always more to learn.
\end{itemize}

\section*{Assignment Goals}
\paragraph{Learning Outcomes} After completing this group assignment,
each student is expected to be able to
  \begin{itemize}
  \item \textbf{Trace} a block of MIPS assembly, noting the value of
    the \lstinline{PC}, other registers, and RAM locations at various
    points.
  \item Write MIPS code to \emph{declare} global \lstinline{int}
    variables, \emph{load} variables into registers, \emph{manipulate}
    the values in registers, and \emph{store} values back into
    variables in RAM.
  \item Be able to interpret \emph{hexadecimal} values as equivalent
    \emph{binary} values.
  \item Be able to apply logical operations to \emph{binary} values.
\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 Roles.} Students should take roles they
have not held recently (or, perhaps, ever):

\begin{quote}
\begin{description}
\item[Manager] Move discussion forward.
\item[Recorder] Writes the report that will be turned in.
\item[Reflector] Monitor that everyone gets heard and is caught
  up. (This is a \textbf{group} obligation, really.)
\item[Speaker] (Combine w/ \textbf{Reflector} if there are not four
  group members.) Asks the facilitator questions and communicates what
  the team has done.
\end{description}
\end{quote}
\noindent
\textbf{Answer these questions.}

\begin{questions}
\question{} How many different values are there for each
  \textbf{b}nary dig\textbf{it} (bit) in a base-2 number? Per digit in a base-10
  number? Per digit in a  base-16 number?
\question{} How many bits are needed to store at least 4 distinct
  values? What about 8 values? 16?
\question{} If, instead of bits, you used base 10 digits, how many
  different values could you store with each width in the previous question?
\question{} If, instead of bits, you used base 16 digits, how many
  different values could you store with each width in the previous question?

  \begin{multicols}{2}
\question{} Fill in the following table.

  \begin{tabular}{|r|r|r|}
    \hline
    Dec (2)&Hex (1)&Bin (4)\\\hline
    \texttt{00}&\texttt{}&\texttt{}\\\hline
    \texttt{}&\texttt{1}&\texttt{}\\\hline
    \texttt{}&\texttt{}&\texttt{0010}\\\hline
    \texttt{}&\texttt{}&\texttt{0011}\\\hline
    \texttt{04}&\texttt{}&\texttt{}\\\hline
    \texttt{}&\texttt{5}&\texttt{}\\\hline
    \texttt{06}&\texttt{}&\texttt{}\\\hline
    \texttt{}&\texttt{7}&\texttt{}\\\hline
    \texttt{}&\texttt{}&\texttt{1000}\\\hline
    \texttt{}&\texttt{}&\texttt{1001}\\\hline
    \texttt{10}&\texttt{}&\texttt{}\\\hline
    \texttt{}&\texttt{b}&\texttt{}\\\hline
    \texttt{12}&\texttt{}&\texttt{}\\\hline
    \texttt{13}&\texttt{}&\texttt{}\\\hline
    \texttt{14}&\texttt{}&\texttt{}\\\hline
    \texttt{15}&\texttt{}&\texttt{}\\\hline
  \end{tabular}

\question{} A \textbf{directive} in MIPS assembly begins with a dot, \emph{i.e.}
\lstinline{.data}, and commands the \emph{assembler} during
assembly-time rather than commanding the CPU during run-time

A program has two \emph{segments}: one for globally declared
\textbf{data} and one for \textbf{instructions}, the \textbf{text} of
the program. For example:

\vspace{5\baselineskip}

\begin{lstlisting}[backgroundcolor=\color{lightgray}]
      .data
x:    .word    100

      .text
main:
      lw      $t0, x
\end{lstlisting}
\begin{parts}
\part{} If the \lstinline{.word} directive sets aside a MIPS
  \emph{word} of memory, how many \textbf{bytes} is that?
\part{} How much memory is set aside by the \lstinline{.byte} directive?

\part{} What does a label, \emph{e.g.} \lstinline{x} or
  \lstinline{main}, mean to the assembler?

\part{} Write a \lstinline{.data} segment with room to store three (3)
  integer variables, \lstinline{s}, \lstinline{t}, and
  \lstinline{u}. Set the first two to non-zero values of your choice
  and the last to zero.

\part{} Write a main program that uses \lstinline{lw}, \lstinline{sw},
  \lstinline{add}, and \lstinline{sub} to evaluate the expression

  $u = 3 \times s - 2 \times t$

\part{} \lstinline{beq $rX, $rY, label} is the \emph{branch equal
    instruction}. The label is either an address or a label (that the
  assembler translates to an address). This is the basic
  \emph{selection} operator in MIPS assembly.

  \begin{tabular}{lllll}
    \emph{address}&\emph{opcode}&\emph{rX}&\emph{rY}&\emph{target}\\
    \texttt{00400020}&\texttt{beq}&\texttt{\$t3}&\texttt{\$t5}&\texttt{00400084}\\
  \end{tabular}

  \begin{subparts}
  \subpart{} What is the address of the \textbf{next} instruction
    after this one?
  \subpart{} What is the \emph{least-significant} nybble of the target
    in binary?
  \subpart{} Why does it end with two zero bits?
  \subpart{} What is the \lstinline{pc} set to if \lstinline{$t3} == \lstinline{$t5}?
  \subpart{} What is the \lstinline{pc} set to if \lstinline{$t3} != \lstinline{$t5}?
  \end{subparts}
\end{parts}

\question{} What is the value in \lstinline{$s0} after the following
  command with the given initial values?
\begin{lstlisting}[backgroundcolor=\color{lightgray}]
$s0 = 0xABCD0123
$s1 = 0x0123DCBA

and $s0, $s0, $s1
\end{lstlisting}
  \end{multicols}

\end{questions}
\end{document}

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