\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}
\usetikzlibrary{circuits.logic.US}
\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\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{gDigitalDesign - Synchronous Circuits}
\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 using digital \emph{logic} gates and
design more complex digital \emph{circuits}.

\section*{Assignment Goals}
\paragraph{Learning Outcomes} After completing this group assignment,
each student is expected to be able to
  \begin{itemize}
  \item \textbf{Draw} truth tables for a given logic circuit or
    expression.
  \item \textbf{Draw} a logic circuit for a given truth table.
  \item \textbf{Create} different ``simple'' gates from other
    ``simple'' gates.
\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{} Draw the \emph{truth-table} for each of the circuits below.

  \begin{tikzpicture}[circuit logic US,
    tiny circuit symbols,
    every circuit symbol/.style={
      fill=white,draw}]
    \draw (0, 0) node [and gate] (a1) {};
    \draw (a1.input 1) -| ++(-0.3, 0);
    \draw (a1.input 2) -| ++(-0.3,0);
    \draw (a1.output) -| ++(0.3,0);

    \draw (1.5, 0) node [or gate] (o1) {};
    \draw (o1.input 1) -| ++(left:3mm);
    \draw (o1.input 2) -| ++(left:3mm);
    \draw (o1.output) -| ++(right:3mm);

    \draw (3, 0) node [not gate] (n1) {};
    \draw (n1.input) -| ++(-0.3, 0);
    \draw (n1.output) -| ++(0.3,0);
  \end{tikzpicture}

\question{} Using just the gate below, construct circuits that are
  logically equivalent to \textbf{AND}, \textbf{OR}, and \textbf{NOT}
  (you may want to do them in a different order).

  \begin{tikzpicture}[circuit logic US,
    tiny circuit symbols,
    every circuit symbol/.style={
      fill=white,draw}]
    \draw (0, 0) node [nand gate] (a1) {};
    \draw (a1.input 1) -| ++(-0.3, 0);
    \draw (a1.input 2) -| ++(-0.3,0);
    \draw (a1.output) -| ++(0.3,0);
  \end{tikzpicture}

\question{} Using only two-input \textbf{AND} gates, construct a
  \emph{three-input} \textbf{AND} gate. Before starting, make sure you
  understand the desired truth-table (no need to draw it).

\question{} Draw the truth table for the following circuit:

  \begin{tikzpicture}[circuit logic US,
    tiny circuit symbols,
    every circuit symbol/.style={
      fill=white,draw}]
  \matrix[column sep=7mm]
  {
    \node (i0) {a}; &
    & \\
    & \node [and gate] (a1) {}; & \\
    \node (i1) {b}; &
    & \node [xor gate] (o) {};\\
    & \node [nand gate] (a2) {}; & \\
    \node (i2) {c}; &
    & \\
  };
  \draw (i0.east) -- ++(right:3mm) |- (a1.input 1);
  \draw (i1.east) -- ++(right:3mm) |- (a1.input 2);
  \draw (i1.east) -- ++(right:3mm) |- (a2.input 1);
  \draw (i2.east) -- ++(right:3mm) |- (a2.input 2);
  \draw (a1.output) -- ++(right:3mm) |- (o.input 1);
  \draw (a2.output) -- ++(right:3mm) |- (o.input 2);
  \draw (o.output) -- ++(right:3mm);
\end{tikzpicture}

\question{} Draw the truth table for the following circuit. Put the
  \lstinline{sel} column on the left of the table.

  \begin{tikzpicture}[circuit logic US,
  tiny circuit symbols,
  every circuit symbol/.style={
    fill=white,draw}]
  \matrix[column sep=7mm]
  {
    \node (i0) {a}; &
    & \\
    & \node [and gate, logic gate inputs=ni] (a1) {}; & \\
    \node (i1) {sel}; &
    & \node [or gate] (o) {};\\
    & \node [and gate] (a2) {}; & \\
    \node (i2) {b}; &
    & \\
  };
  \draw (i0.east) -- ++(right:3mm) |- (a1.input 1);
  \draw (i1.east) -- ++(right:3mm) |- (a1.input 2);
  \draw (i1.east) -- ++(right:3mm) |- (a2.input 1);
  \draw (i2.east) -- ++(right:3mm) |- (a2.input 2);
  \draw (a1.output) -- ++(right:3mm) |- (o.input 1);
  \draw (a2.output) -- ++(right:3mm) |- (o.input 2);
  \draw (o.output) -- ++(right:3mm);
\end{tikzpicture}

\question{} Add the \emph{binary} numbers \lstinline{0101} and
  \lstinline{0111}; interpreting them (and their sum) as
  \emph{unsigned} values, what sum did you just calculate, in decimal?

\question{} Consider a \textbf{full-adder} that could add the two
  numbers from above. How many \emph{carry-in} wires would you need?
  How many \emph{carry-out}? How many wires of input and how many for
  output?

\question{} Draw a \emph{three-input} circuit that determines if
  exactly two of its inputs are \lstinline{1}. You may only use
  two-input \textbf{AND}, \textbf{OR}, and \textbf{NOT} gates.

\end{questions}
\end{document}

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