%\documentclass[dvipdfmx,t,serif,mathserif,14pt]{beamer} % t: from top; serif: rmdefault
\documentclass[dvipdfmx,t,14pt]{beamer} % t: from top; serif: rmdefault
\usepackage{mybeamer}

\newcommand{\PDFTITLE}{論理回路入門（９）}
\newcommand{\PDFSUBJECT}{一年生秋学期}
\newcommand{\PDFAUTHOR}{法政大学情報科学部}
\newcommand{\PDFKEYWORDS}{
  組み合わせ回路設計の手順、
  マルチプレクサ、バレル・シフタ、
  ALU: Arithmetic Logic Unit (算術論理演算回路)}

\date{2023 年 11 月 21 日 (火)}

\title{\PDFTITLE} % bottom PDFTITLE
\subtitle{マルチプレクサと簡単なALUの設計}
\author[\PDFAUTHOR]{李　亜民}% bottom PDFAUTHOR; titlepage Yamin Li

\hypersetup{
  pdftitle=\PDFTITLE,
  pdfsubject=\PDFSUBJECT,
  pdfauthor=\PDFAUTHOR,
  pdfkeywords=\PDFKEYWORDS
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\everymath={\sf}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{\PDFTITLE}
\begin{frame}
  \titlepage
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%------------------------------------------------ SLIDE -
\input{mybackgroundcolor.tex}
%------------------------------------------------ SLIDE -
\section{マルチプレクサ}
\begin{frame}\frametitle{\secname}
\textcolor{blue}{ポイント}

\begin{itemize}
  \color{blue}
\setlength{\itemsep}{1.5mm}
\item マルチプレクサ
\item 組み合わせ回路設計の手順
\item 1 ビット 2-to-1 のマルチプレクサ
\item 4 ビット 2-to-1 のマルチプレクサ
\item 1 ビット 4-to-1 のマルチプレクサ
\item 4 ビット 4-to-1 のマルチプレクサ
\item バレルシフタ (Barrel shifter) 回路
\item 7 セグメント~LED
\item ALU: Arithmetic Logic Unit (算術論理演算回路)
\end{itemize}

\end{frame}
%------------------------------------------------ SLIDE -
\section{マルチプレクサ}
\begin{frame}\frametitle{\secname}
\fontsize{12pt}{14}\selectfont
マルチプレクサ (Multiplexer) は、複数の入力から１つを選択し出力する。
\hfill\textcolor{blue}{(マルチプレクサ = データ選択器)~~~}

\vspace{3mm}
\includegraphics[width=.9\textwidth]{figs/multiplexers.pdf}
\end{frame}
%------------------------------------------------ SLIDE -
\section{2-to-1 のマルチプレクサを設計}
\begin{frame}\frametitle{\secname}
\includegraphics[width=.8\textwidth]{figs/mux2x1_sym.pdf}

\vspace{5mm}
\resizebox{\textwidth}{!}{１ビット 2-to-1 のマルチプレクサ回路を設計しましょう。}
\end{frame}
%------------------------------------------------ SLIDE -
\section{組み合わせ回路設計の手順}
\begin{frame}\frametitle{\secname}
\renewcommand\baselinestretch{1.15}
\fontsize{13pt}{15}\selectfont
\begin{enumerate}

\item 問題を理解する。

\item 入力と出力信号の名前を任意に決める。

\item 入力のあらゆる組み合わせを列挙し，真理値表をつくる。

\item 真理値表から論理式をつくる。

\textcolor{red}{(どの組み合わせで出力が １ になるか。)}

\item カルノー図を用いて論理式を簡単化する。

\item 論理式から回路をつくる。

\item テストベンチをつくる~(シミュレーションするため)。

\item 回路をシミュレーションする~(回路設計の正当性検証)。

\item 与えられた回路の動作を理解する~(波形の説明)。

\end{enumerate}
\end{frame}
%------------------------------------------------ SLIDE -
\section{マルチプレクサ}
\begin{frame}\frametitle{\secname}
\fontsize{12pt}{14}\selectfont
\begin{itemize}
\item[\textcolor{magenta}{\bfseries{1.}}] 問題: 二つの入力~(それぞれの入力は 1 ビット) から一つを選択して出力するマルチプレクサを設計せよ。

\vspace{5mm}
\begin{center}
    \includegraphics[scale=1.2]{figs/mux_switch.pdf}
\end{center}
\end{itemize}
\end{frame}
%------------------------------------------------ SLIDE -
\section{マルチプレクサ~--- 信号}
\begin{frame}\frametitle{\secname}
  \fontsize{12pt}{14}\selectfont
  \begin{itemize}
  \item[\textcolor{magenta}{\bfseries{2.}}] 入力と出力信号の名前を任意に決める。例えば
      \fontsize{11pt}{13}\selectfont
    \begin{itemize}
      \color{blue}
    \item 二つの入力信号: A0 と~A1
    \item 一つの出力信号: Y
    \item どっちを選択するかを告げる信号~(入力): S

      \vspace{1.1mm}
      \begin{itemize}
        \color{magenta} 
      \item if ($S==0$) $Y = A0$; \cdotfill S は~0 のとき、A0 を選択する
      \item else $Y = A1$;        \cdotfill S は~1 のとき、A1 を選択する
        
        \vspace{3mm}
        \includegraphics{figs/mux_switch_name.pdf}        
      \end{itemize}

      \vspace{1mm}
    \item 右側の図はマルチプレクサのシンボル\\ですが、どのような回路で Y は出力さ\\れているでしょうか？

      \vspace{-17mm}
      \hspace*{75mm}
      \includegraphics[scale=.95]{figs/mux2x1_symbol.pdf}
    \end{itemize}
  \end{itemize}
\end{frame}
%------------------------------------------------ SLIDE -
\section{マルチプレクサ~--- 真理値表}
\begin{frame}\frametitle{\secname}
\fontsize{12pt}{14}\selectfont
\begin{itemize}
\item [\textcolor{magenta}{\bfseries{3.}}] 真理値表をつくる。

\vspace{2mm}
\textcolor{magenta}{入力は 3 つ、全ての組み合わせは 8 つ~($2^3=8$)}

\renewcommand{\arraystretch}{1.3}
\setlength{\tabcolsep}{4mm}
\begin{tabular}[t]{ccc|cl}\cline{1-4}
\multicolumn{3}{c|}{入力}&出力\\\cline{1-4}
S & A1 & A0 & Y \\ \cline{1-4}
\textcolor{blue}{0}   & 0 & \textcolor{blue}{0} & \textcolor{blue}{0} \\[-4pt]
\textcolor{blue}{0}   & 0 & \textcolor{blue}{1} & \bfseries\textcolor{blue}{1} & \textcolor{blue}{S は~0 のとき、}\\[-4pt]
\textcolor{blue}{0}   & 1 & \textcolor{blue}{0} & \textcolor{blue}{0}    & \textcolor{blue}{A0 を選択する}\\[-4pt]
\textcolor{blue}{0}   & 1 & \textcolor{blue}{1} & \bfseries\textcolor{blue}{1} \\\cline{1-4}
\textcolor{purple}{1} & \textcolor{purple}{0} & 0 & \textcolor{purple}{0} \\[-4pt]
\textcolor{purple}{1} & \textcolor{purple}{0} & 1 & \textcolor{purple}{0} & \textcolor{purple}{S は~1 のとき、}\\[-4pt]
\textcolor{purple}{1} & \textcolor{purple}{1} & 0 & \bfseries\textcolor{purple}{1}  & \textcolor{purple}{A1 を選択する}\\[-4pt]
\textcolor{purple}{1} & \textcolor{purple}{1} & 1 & \bfseries\textcolor{purple}{1} \\ \cline{1-4}
\end{tabular}
\end{itemize}
\end{frame}
%------------------------------------------------ slide -
\section{マルチプレクサ~--- 論理式}
\begin{frame}\frametitle{\secname}
  \fontsize{12pt}{14}\selectfont
  \begin{itemize}
  \item [\textcolor{magenta}{\bfseries{4.}}] 論理式をつくる~(\textcolor{red}{どの組み合わせで出力が１になるか})。

    \vspace{1mm}
    \begin{center}
      \setlength{\tabcolsep}{5mm}
      \begin{tabular}[t]{ccc|cl}\cline{1-4}
        \multicolumn{3}{c|}{\rule{0pt}{.8\normalbaselineskip}入力}&出力\\\cline{1-4}
        \rule{0pt}{.8\normalbaselineskip}S & A1 & A0 & Y & \raisebox{1.5ex}[0pt]{~~~~~~$Y=1$:}\\ \cline{1-4}
        \rule{0pt}{.8\normalbaselineskip}\textcolor{blue}{0}   & 0 & \textcolor{blue}{0} & \textcolor{blue}{0} \\
        \textcolor{blue}{0}   & 0 & \textcolor{blue}{1} & {\bfseries\textcolor{blue}{1}}     & $\leftarrow\ \textcolor{blue}{\overline{S}~\overline{A1}~A0}$\\
        \textcolor{blue}{0}   & 1 & \textcolor{blue}{0} & \textcolor{blue}{0} \\
        \textcolor{blue}{0}   & 1 & \textcolor{blue}{1} & {\bfseries\textcolor{blue}{1}}     & $\leftarrow\ \textcolor{blue}{\overline{S}~A1~A0}$\\\cline{1-4}
        \rule{0pt}{.8\normalbaselineskip}\textcolor{purple}{1} & \textcolor{purple}{0} & 0 & \textcolor{purple}{0} \\
        \textcolor{purple}{1} & \textcolor{purple}{0} & 1 & \textcolor{purple}{0} \\
        \textcolor{purple}{1} & \textcolor{purple}{1} & 0 & {\bfseries\textcolor{purple}{1}} & $\leftarrow\ \textcolor{purple}{S~A1~\overline{A0}}$\\
        \textcolor{purple}{1} & \textcolor{purple}{1} & 1 & {\bfseries\textcolor{purple}{1}} & $\leftarrow\ \textcolor{purple}{S~A1~A0}$\\ \cline{1-4}
      \end{tabular}
    \end{center}

    \vspace{2mm}
    $Y=\textcolor{blue}{\overline{S}~\overline{A1}~A0} + \textcolor{blue}{\overline{S}~A1~A0} + \textcolor{purple}{S~A1~\overline{A0}} + \textcolor{purple}{S~A1~A0}$
    
  \end{itemize}
\end{frame}
%------------------------------------------------ slide -
\section{マルチプレクサ~--- 論理式の簡単化}
\begin{frame}\frametitle{\secname}
  \fontsize{12pt}{14}\selectfont
  \begin{itemize}
  \item [\textcolor{magenta}{\bfseries{5.}}] カルノー図を用いて論理式を簡単化する:

    \vspace{2mm}
    \begin{center}
      \includegraphics[scale=1.4]{figs/mux2x1_karnaugh_map.pdf}
    \end{center}
    $$\mathsf{Y=\textcolor{blue}{\overline{S}~A0} + \textcolor{purple}{S~A1}}$$

    あるいはブール代数の定理により論理式を簡単化する:

    \vspace{2mm}
    \begin{itemize}
    \item[]

      \vspace{0mm}
      $Y=
      \textcolor{blue}{\overline{S}~\overline{A1}~A0} + 
      \textcolor{blue}{\overline{S}~A1~A0} + 
      \textcolor{purple}{S~A1~\overline{A0}} + 
      \textcolor{purple}{S~A1~A0}$
      
      \vspace{1mm}
      $\phantom{Y}=
      \textcolor{blue}{\overline{S}~A0~\mbox{(}\overline{A1}+A1\mbox{)}} + 
      \textcolor{purple}{S~A1~\mbox{(}\overline{A0}+A0\mbox{)}}$
      
      \vspace{1mm}
      $\phantom{Y}=
      \textcolor{blue}{\overline{S}~A0} + 
      \textcolor{purple}{S~A1}$
    \end{itemize}
    
  \end{itemize}
\end{frame}
%------------------------------------------------ slide -
\section{マルチプレクサ~--- 回路}
\begin{frame}[fragile]\frametitle{\secname}
\fontsize{12pt}{14}\selectfont
\begin{itemize}
\item [\textcolor{magenta}{\bfseries{6.}}] 論理式から回路をつくる。

\vspace{6mm}
$Y=\overline{S}~A0 + S~A1$ ~~~~~~~~~~~~~ $\rightarrow$ ~~~~~~~~~~~~~ {\tt{Y = \texttt{\~}S \& A0 | S \& A1}}

\vspace{6mm}
\fontsize{14pt}{14.55}\selectfont
\begin{code}
`timescale 1ns/1ns

module mux2x1 (A0, A1, S, Y);
    input  A0, A1, S;
    output Y;

    assign Y = ~S & A0 | S & A1;

endmodule
\end{code}

\vspace{-9mm}
\hfill
\href{https://yamin.cis.k.hosei.ac.jp/lectures/logic/mux2x1.v}{\color{blue}\underline{mux2x1.v}}~~~

\end{itemize}
\end{frame}
%------------------------------------------------ slide -
\section{マルチプレクサ~--- テストベンチ}
\begin{frame}[fragile]\frametitle{\secname}
\fontsize{12pt}{14}\selectfont
\begin{itemize}
\item [\textcolor{magenta}{\bfseries{7.}}] テストベンチをつくる \textcolor{red}{(シミュレーションするため)}。

\vspace{2mm}
\fontsize{10pt}{10.2}\selectfont
\begin{code}
`timescale 1ns/1ns
module mux2x1_tb;
    reg  A0, A1, S;
    wire Y;
    mux2x1 i0 (A0, A1, S, Y);
    initial begin
        #0 A0 = 0; A1 = 0; S = 0;
        #8 $finish;
    end
    always #1 A0 = ~A0;
    always #2 A1 = ~A1;
    always #4 S  = ~S;
    initial begin
        $dumpfile ("mux2x1.vcd");
        $dumpvars;
    end
endmodule
\end{code}

\vspace{-8mm}
\hfill
\href{https://yamin.cis.k.hosei.ac.jp/lectures/logic/mux2x1_tb.v}{\color{blue}\underline{mux2x1\_tb.v}}~~~

\end{itemize}
\end{frame}
%------------------------------------------------ slide -
\section{マルチプレクサ~--- 波形}
\begin{frame}[fragile]\frametitle{\secname}
\vspace{-5mm}
\begin{verbatim}
% iverilog -Wall -o mux2x1 mux2x1_tb.v mux2x1.v
% ./mux2x1
% gtkwave mux2x1.vcd
\end{verbatim}

\vspace{2mm}
\includegraphics[width=\textwidth]{figs/mux2x1_vcd_crop.png}

  \fontsize{11pt}{15}\selectfont
  \white
  \vspace{3mm}
  \colorbox{blue}{$S=0$の時、$Y = \overline{S} \cdot A0 + S \cdot A1 = 1 \cdot A0 + 0 \cdot A1 = A0 + 0 = A0$}

  \colorbox{blue}{$S=1$の時、$Y = \overline{S} \cdot A0 + S \cdot A1 = 0 \cdot A0 + 1 \cdot A1 = 0 + A1 = A1$}

  \fontsize{7pt}{9}\selectfont
  \color{magenta}
  \vspace{-35mm}
  \hspace*{24mm}
  0\hspace{10mm}1\hspace{10mm}0\hspace{10mm}1

  \color{yellow}
  \vspace{1.8mm}
  \hspace*{77.5mm}
  0\hspace{22mm}1

  \color{green}
  \vspace{1.8mm}
  \hspace*{42mm}
  0\hspace{45.6mm}1

  \color{magenta}
  \vspace{1.8mm}
  \hspace*{24mm}
  0\hspace{10mm}1\hspace{10mm}0\hspace{10mm}1\color{yellow}\hspace{16.7mm}0\hspace{22mm}1

\end{frame}
%------------------------------------------------ SLIDE -
\section{4 ビット 2-to-1 のマルチプレクサ}
\begin{frame}\frametitle{\secname}
\fontsize{10pt}{13}\selectfont
\includegraphics[width=.73\textwidth]{figs/mux2x4.pdf}

\color{red}
\vspace{-65mm}
\hspace*{70mm}
A0[3:0]: 4 ビット幅である

\vspace{2mm}
\hspace*{70mm}
A0[3], A0[2], A0[1], A0[0]

\vspace{2mm}
\hspace*{70mm}
のまとめ表示であること

\color{blue}
\vspace{5mm}
\hspace*{70mm}
A1[3:0]: 4 ビット幅である

\vspace{2mm}
\hspace*{70mm}
A1[3], A1[2], A1[1], A1[0]

\vspace{2mm}
\hspace*{70mm}
のまとめ表示であること

\color{magenta}
\vspace{5mm}
\hspace*{70mm}
Y[3:0]: 4 ビット幅である

\vspace{2mm}
\hspace*{70mm}
Y[3], Y[2], Y[1], Y[0]

\vspace{2mm}
\hspace*{70mm}
のまとめ表示であること

\end{frame}
%------------------------------------------------ SLIDE -
\section{4-to-1 のマルチプレクサ（１ビット）}
\begin{frame}\frametitle{\secname}
\fontsize{13pt}{15}\selectfont
\begin{itemize}
\item 2-to-1 のマルチプレクサ

\vspace{3mm}
\tabcolsep=3pt
\begin{tabular}{lll}
$Y$&$=$&$\overline{S}\cdot A0$\\
   &$+$&$S\cdot A1$\\
\end{tabular}

\vspace{5mm}
\textcolor{blue}{\tt{assign Y = \texttt{\~}S \& A0 | S \& A1;}}

\vspace{5mm}
\item 4-to-1 のマルチプレクサ

\vspace{3mm}
\tabcolsep=3pt
\begin{tabular}{lll}
$Y$&$=$&$\overline{S1}\cdot \overline{S0}\cdot A0$\\
&$+$&$\overline{S1}\cdot S0\cdot A1$\\
&$+$&$S1\cdot \overline{S0}\cdot A2$\\
&$+$&$S1\cdot S0\cdot A3$\\
\end{tabular}

\vspace{3mm}
\textcolor{blue}{\tt{assign Y = ????????????????;}}

\end{itemize}

{\fontsize{10pt}{12}\selectfont
\vspace{-72mm}
\hspace*{59mm}
\includegraphics[width=.2\textwidth]{figs/mux2x1_symbol.pdf}

\vspace{15mm}
\hspace*{59mm}
\includegraphics[width=.2\textwidth]{figs/mux4x1_symbol.pdf}
}

\vspace{-63mm}
\hspace*{89mm}
\tabcolsep=6pt
\begin{tabular}{c|c}
\multicolumn{2}{c}{真理値表}\\\hline
\rule{0pt}{.8\normalbaselineskip}S&Y\\\hline
\rule{0pt}{.8\normalbaselineskip}0&A0\\
1&A1\\\hline
\end{tabular}

\vspace{12mm}
\hspace*{89mm}
\tabcolsep=6pt
\begin{tabular}{c|c}
\multicolumn{2}{c}{真理値表}\\\hline
\rule{0pt}{.8\normalbaselineskip}S1~S0&Y\\\hline
\rule{0pt}{.8\normalbaselineskip}0~~~0&A0\\
0~~~1&A1\\
1~~~0&A2\\
1~~~1&A3\\\hline
\end{tabular}

\end{frame}
%------------------------------------------------ SLIDE -
\section{4-to-1 のマルチプレクサ（回路）}
\begin{frame}[fragile]\frametitle{\secname}
\fontsize{13pt}{15}\selectfont

\tabcolsep=3pt
\begin{tabular}{lll}
$Y$&$=$&$\overline{S1}\cdot \overline{S0}\cdot A0$\\
&$+$&$\overline{S1}\cdot S0\cdot A1$\\
&$+$&$S1\cdot \overline{S0}\cdot A2$\\
&$+$&$S1\cdot S0\cdot A3$\\
\end{tabular}

\vspace{4mm}
\fontsize{13pt}{14}\selectfont
\begin{code}
`timescale 1ns/1ns
module mux4x1 (A0, A1, A2, A3, S0, S1, Y);
    input  A0, A1, A2, A3, S0, S1;
    output Y;
    assign Y = ~S1 & ~S0 & A0 | // S1 S0 = 0 0, Y = A0
               ~S1 &  S0 & A1 | // S1 S0 = 0 1, Y = A1
                S1 & ~S0 & A2 | // S1 S0 = 1 0, Y = A2
                S1 &  S0 & A3;  // S1 S0 = 1 1, Y = A3
endmodule
\end{code}

\vspace{-8mm}
\hfill
\href{https://yamin.cis.k.hosei.ac.jp/lectures/logic/mux4x1.v}{\color{blue}\underline{mux4x1.v}}~~~

\end{frame}
%------------------------------------------------ slide -
\section{テストベンチ}
\begin{frame}[fragile]\frametitle{\secname}
\fontsize{9pt}{9.16}\selectfont
\begin{code}
`timescale 1ns/1ns
module mux4x1_tb;
    reg  A0, A1, A2, A3, S0, S1;
    wire Y;
    mux4x1 i0 (A0, A1, A2, A3, S0, S1, Y);
    initial begin
        #0  A0 = 0; A1 = 0; A2 = 0; A3 = 0;
        #0  S0 = 0; S1 = 0;
        #64 $finish;
    end
    always #1  A0 = ~A0;
    always #2  A1 = ~A1;
    always #4  A2 = ~A2;
    always #8  A3 = ~A3;
    always #16 S0 = ~S0;
    always #32 S1 = ~S1;
    initial begin
        $dumpfile ("mux4x1.vcd");
        $dumpvars;
    end
endmodule
\end{code}

\vspace{-8mm}
\hfill
\href{https://yamin.cis.k.hosei.ac.jp/lectures/logic/mux4x1_tb.v}{\color{blue}\underline{mux4x1\_tb.v}}~~~

\end{frame}
%------------------------------------------------ slide -
\section{4-to-1 のマルチプレクサ（波形）}
\begin{frame}[fragile]\frametitle{\secname}
\fontsize{13pt}{14}\selectfont
\vspace{-5mm}
\begin{verbatim}
% iverilog -Wall -o mux4x1 mux4x1_tb.v mux4x1.v
% ./mux4x1
% gtkwave mux4x1.vcd
\end{verbatim}

\includegraphics[width=\textwidth]{figs/mux4x1_vcd_crop.png}

\hspace{32mm}A0
\hspace{15.5mm}A1
\hspace{15.5mm}A2
\hspace{15.5mm}A3

\fontsize{12pt}{14}\selectfont
\white
\vspace{-23mm}
\hspace{33mm}0
\hspace{19.3mm}1
\hspace{19.3mm}0
\hspace{19.3mm}1

\vspace{1.2mm}
\hspace{33mm}0
\hspace{19.3mm}0
\hspace{19.3mm}1
\hspace{19.3mm}1

\end{frame}
%------------------------------------------------ SLIDE -
\section{4-to-1 のマルチプレクサ（４ビット）}
\begin{frame}\frametitle{\secname}
\fontsize{10pt}{12}\selectfont
\includegraphics[width=.5\textwidth]{figs/mux4x4_sch.pdf}

\vspace{-70mm}
\hspace*{80mm}
\includegraphics[width=.3\textwidth]{figs/mux4x4_symbol.pdf}

\vspace{2mm}
\hspace*{91mm}
シンボル

\fontsize{9pt}{11}\selectfont

\vspace{3mm}
\hspace*{47mm}
A0[\textcolor{red}{3:0}]: ４ビット: A0[\textcolor{red}{3}], A0[\textcolor{red}{2}], A0[\textcolor{red}{1}], A0[\textcolor{red}{0}]

\vspace{3mm}
\hspace*{47mm}
A1[\textcolor{red}{3:0}]: ４ビット: A1[\textcolor{red}{3}], A1[\textcolor{red}{2}], A1[\textcolor{red}{1}], A1[\textcolor{red}{0}]

\vspace{3mm}
\hspace*{47mm}
A2[\textcolor{red}{3:0}]: ４ビット: A2[\textcolor{red}{3}], A2[\textcolor{red}{2}], A2[\textcolor{red}{1}], A2[\textcolor{red}{0}]

\vspace{3mm}
\hspace*{47mm}
A3[\textcolor{red}{3:0}]: ４ビット: A3[\textcolor{red}{3}], A3[\textcolor{red}{2}], A3[\textcolor{red}{1}], A3[\textcolor{red}{0}]

\vspace{3mm}
\hspace*{47mm}
Y[\textcolor{red}{3:0}]: ４ビット: Y[\textcolor{red}{3}], Y[\textcolor{red}{2}], Y[\textcolor{red}{1}], Y[\textcolor{red}{0}]

\vspace{3mm}
\hspace*{47mm}
S[\textcolor{red}{1:0}]: ２ビット: S[\textcolor{red}{1}], S[\textcolor{red}{0}]

\end{frame}
%------------------------------------------------ SLIDE -
\section{マルチプレクサの応用 --- バレルシフタ}
\begin{frame}\frametitle{\secname}
  \fontsize{11pt}{12}\selectfont
  \begin{itemize}
  \item SLL --- Shift Left Logical (論理左シフト)
  \begin{itemize}
  \item 0010 \underline{0011} \textcolor{blue}{4-bit shift left:}\\
  \underline{0011} \textcolor{red}{0000}
  \item 1010 \underline{0011} \textcolor{blue}{4-bit shift left:}\\
  \underline{0011} \textcolor{red}{0000}
  \end{itemize}
  \item SRL --- Shift Right Logical (論理右シフト)
  \begin{itemize}
  \item \underline{0010} 0011 \textcolor{blue}{4-bit shift right logical:}\\
  \textcolor{red}{0000} \underline{0010}
  \item \underline{1010} 0011 \textcolor{blue}{4-bit shift right logical:}\\
  \textcolor{red}{0000} \underline{1010}
  \end{itemize}
  \item SRA --- Shift Right Arithmetic (算術右シフト)
  \begin{itemize}
  \item \underline{\textcolor{red}{0}010} 0011 \textcolor{blue}{4-bit shift right arithmetic:}\\
  \textcolor{red}{0000} \underline{\textcolor{red}{0}010} (符号拡張)
  \item \underline{\textcolor{red}{1}010} 0011 \textcolor{blue}{4-bit shift right arithmetic:}\\
  \textcolor{red}{1111} \underline{\textcolor{red}{1}010} (符号拡張)
  \end{itemize}
  \end{itemize}
\end{frame}
%------------------------------------------------ SLIDE -
\section{マルチプレクサの応用 --- バレルシフタ}
\begin{frame}\frametitle{\secname}
\fontsize{6pt}{8}\selectfont
  論理左シフト (SLL)$~$

  01111110 $\rightarrow$ (\textcolor{red}{0}-bit shift) $\rightarrow$ 01111110 \cdotfill(\textcolor{red}{0}=000: shift 0, 0, 0 bit)

  01111110 $\rightarrow$ (\textcolor{red}{1}-bit shift) $\rightarrow$ 1111110\textcolor{red}{0} \cdotfill(\textcolor{red}{1}=00\textcolor{red}{1}: shift 0, 0, \textcolor{red}{1} bit)

  01111110 $\rightarrow$ (\textcolor{red}{2}-bit shift) $\rightarrow$ 111110\textcolor{red}{00} \cdotfill(\textcolor{red}{2}=0\textcolor{red}{1}0: shift 0, \textcolor{red}{2}, 0 bit)

  01111110 $\rightarrow$ (\textcolor{red}{3}-bit shift) $\rightarrow$ 11110\textcolor{red}{000} \cdotfill(\textcolor{red}{3}=0\textcolor{red}{11}: shift 0, \textcolor{red}{2}, \textcolor{red}{1} bit)

  01111110 $\rightarrow$ (\textcolor{red}{4}-bit shift) $\rightarrow$ 1110\textcolor{red}{0000} \cdotfill(\textcolor{red}{4}=\textcolor{red}{1}00: shift \textcolor{red}{4}, 0, 0 bit)

  01111110 $\rightarrow$ (\textcolor{red}{5}-bit shift) $\rightarrow$ 110\textcolor{red}{00000} \cdotfill(\textcolor{red}{5}=\textcolor{red}{1}0\textcolor{red}{1}: shift \textcolor{red}{4}, 0, \textcolor{red}{1} bit)

  01111110 $\rightarrow$ (\textcolor{red}{6}-bit shift) $\rightarrow$ 10\textcolor{red}{000000} \cdotfill(\textcolor{red}{6}=\textcolor{red}{11}0: shift \textcolor{red}{4}, \textcolor{red}{2}, 0 bit)

  01111110 $\rightarrow$ (\textcolor{red}{7}-bit shift) $\rightarrow$ 0\textcolor{red}{0000000} \cdotfill(\textcolor{red}{7}=\textcolor{red}{111}: shift \textcolor{red}{4}, \textcolor{red}{2}, \textcolor{red}{1} bit)

\vspace{4mm}
\includegraphics[width=.5\textwidth]{figs/slli.pdf}

\blue

\vspace{-38mm}

\hspace*{67mm}
If $b\mbox{[}2\mbox{]}=1$, shift $2^2=4$ bits

\hspace*{67mm}
If $b\mbox{[}1\mbox{]}=1$, shift $2^1=2$ bits

\hspace*{67mm}
If $b\mbox{[}0\mbox{]}=1$, shift $2^0=1$ bit

\end{frame}
%------------------------------------------------ SLIDE -
\section{マルチプレクサの応用 --- バレルシフタ}
\begin{frame}\frametitle{\secname}
\fontsize{6pt}{8}\selectfont
  論理右シフト (SRL)$~$

  01111110 $\rightarrow$ (\textcolor{red}{0}-bit shift) $\rightarrow$ 01111110 \cdotfill(\textcolor{red}{0}=000: shift 0, 0, 0 bit)

  01111110 $\rightarrow$ (\textcolor{red}{1}-bit shift) $\rightarrow$ \textcolor{red}{0}0111111 \cdotfill(\textcolor{red}{1}=00\textcolor{red}{1}: shift 0, 0, \textcolor{red}{1} bit)

  01111110 $\rightarrow$ (\textcolor{red}{2}-bit shift) $\rightarrow$ \textcolor{red}{00}011111 \cdotfill(\textcolor{red}{2}=0\textcolor{red}{1}0: shift 0, \textcolor{red}{2}, 0 bit)

  01111110 $\rightarrow$ (\textcolor{red}{3}-bit shift) $\rightarrow$ \textcolor{red}{000}01111 \cdotfill(\textcolor{red}{3}=0\textcolor{red}{11}: shift 0, \textcolor{red}{2}, \textcolor{red}{1} bit)
  
  10000000 $\rightarrow$ (\textcolor{red}{4}-bit shift) $\rightarrow$ \textcolor{red}{0000}1000 \cdotfill(\textcolor{red}{4}=\textcolor{red}{1}00: shift \textcolor{red}{4}, 0, 0 bit)

  10000000 $\rightarrow$ (\textcolor{red}{5}-bit shift) $\rightarrow$ \textcolor{red}{00000}100 \cdotfill(\textcolor{red}{5}=\textcolor{red}{1}0\textcolor{red}{1}: shift \textcolor{red}{4}, 0, \textcolor{red}{1} bit)

  10000000 $\rightarrow$ (\textcolor{red}{6}-bit shift) $\rightarrow$ \textcolor{red}{000000}10 \cdotfill(\textcolor{red}{6}=\textcolor{red}{11}0: shift \textcolor{red}{4}, \textcolor{red}{2}, 0 bit)

  10000000 $\rightarrow$ (\textcolor{red}{7}-bit shift) $\rightarrow$ \textcolor{red}{0000000}1 \cdotfill(\textcolor{red}{7}=\textcolor{red}{111}: shift \textcolor{red}{4}, \textcolor{red}{2}, \textcolor{red}{1} bit)

\vspace{4mm}
\includegraphics[width=.5\textwidth]{figs/srli.pdf}

\blue

\vspace{-38mm}

\hspace*{67mm}
If $b\mbox{[}2\mbox{]}=1$, shift $2^2=4$ bits

\hspace*{67mm}
If $b\mbox{[}1\mbox{]}=1$, shift $2^1=2$ bits

\hspace*{67mm}
If $b\mbox{[}0\mbox{]}=1$, shift $2^0=1$ bit

\end{frame}
%------------------------------------------------ SLIDE -
\section{マルチプレクサの応用 --- バレルシフタ}
\begin{frame}\frametitle{\secname}
\fontsize{6pt}{8}\selectfont
  算術右シフト (SRA)$~$

  01111110 $\rightarrow$ (\textcolor{red}{0}-bit shift) $\rightarrow$ 01111110 \cdotfill(\textcolor{red}{0}=000: shift 0, 0, 0 bit)

  01111110 $\rightarrow$ (\textcolor{red}{1}-bit shift) $\rightarrow$ \textcolor{red}{0}0111111 \cdotfill(\textcolor{red}{1}=00\textcolor{red}{1}: shift 0, 0, \textcolor{red}{1} bit)

  01111110 $\rightarrow$ (\textcolor{red}{2}-bit shift) $\rightarrow$ \textcolor{red}{00}011111 \cdotfill(\textcolor{red}{2}=0\textcolor{red}{1}0: shift 0, \textcolor{red}{2}, 0 bit)

  01111110 $\rightarrow$ (\textcolor{red}{3}-bit shift) $\rightarrow$ \textcolor{red}{000}01111 \cdotfill(\textcolor{red}{3}=0\textcolor{red}{11}: shift 0, \textcolor{red}{2}, \textcolor{red}{1} bit)

  10000000 $\rightarrow$ (\textcolor{red}{4}-bit shift) $\rightarrow$ \textcolor{red}{1111}1000 \cdotfill(\textcolor{red}{4}=\textcolor{red}{1}00: shift \textcolor{red}{4}, 0, 0 bit)

  10000000 $\rightarrow$ (\textcolor{red}{5}-bit shift) $\rightarrow$ \textcolor{red}{11111}100 \cdotfill(\textcolor{red}{5}=\textcolor{red}{1}0\textcolor{red}{1}: shift \textcolor{red}{4}, 0, \textcolor{red}{1} bit)

  10000000 $\rightarrow$ (\textcolor{red}{6}-bit shift) $\rightarrow$ \textcolor{red}{111111}10 \cdotfill(\textcolor{red}{6}=\textcolor{red}{11}0: shift \textcolor{red}{4}, \textcolor{red}{2}, 0 bit)

  10000000 $\rightarrow$ (\textcolor{red}{7}-bit shift) $\rightarrow$ \textcolor{red}{1111111}1 \cdotfill(\textcolor{red}{7}=\textcolor{red}{111}: shift \textcolor{red}{4}, \textcolor{red}{2}, \textcolor{red}{1} bit)

\vspace{4mm}
\includegraphics[width=.5\textwidth]{figs/srai.pdf}

\blue

\vspace{-38mm}

\hspace*{67mm}
If $b\mbox{[}2\mbox{]}=1$, shift $2^2=4$ bits

\hspace*{67mm}
If $b\mbox{[}1\mbox{]}=1$, shift $2^1=2$ bits

\hspace*{67mm}
If $b\mbox{[}0\mbox{]}=1$, shift $2^0=1$ bit

\end{frame}
%------------------------------------------------ SLIDE -
\section{バレルシフタの回路}
\begin{frame}\frametitle{\secname}
\includegraphics[width=.98\textwidth]{figs/barrel.pdf}

%\fontsize{6pt}{7}\selectfont
%\vspace{-1mm}
%\hspace*{0mm}\blue
%必要なマルチプレクサの数 $=2nlog_2n$

\end{frame}
%------------------------------------------------ SLIDE -
\section{バレルシフタの波形 (論理左シフト)}
\begin{frame}\frametitle{\secname}
\includegraphics[width=\textwidth]{figs/barrel_shifter_vcd_sll_crop.png}

\fontsize{10pt}{12}\selectfont
\hfill\href{https://yamin.cis.k.hosei.ac.jp/lectures/logic/shift_tb.v}{\color{blue}\underline{shift\_tb.v}}~

$~$

  論理左シフト (arith $=$ 0; right $=$ 0) \cdotfill (SLL)

\vspace{3mm}
  01111110 $\rightarrow$ (\textcolor{red}{0}-bit shift) $\rightarrow$ 01111110 \cdotfill(\textcolor{red}{0}=000: shift 0, 0, 0 bit)

  01111110 $\rightarrow$ (\textcolor{red}{1}-bit shift) $\rightarrow$ 1111110\textcolor{red}{0} \cdotfill(\textcolor{red}{1}=00\textcolor{red}{1}: shift 0, 0, \textcolor{red}{1} bit)

  01111110 $\rightarrow$ (\textcolor{red}{2}-bit shift) $\rightarrow$ 111110\textcolor{red}{00} \cdotfill(\textcolor{red}{2}=0\textcolor{red}{1}0: shift 0, \textcolor{red}{2}, 0 bit)

  01111110 $\rightarrow$ (\textcolor{red}{3}-bit shift) $\rightarrow$ 11110\textcolor{red}{000} \cdotfill(\textcolor{red}{3}=0\textcolor{red}{11}: shift 0, \textcolor{red}{2}, \textcolor{red}{1} bit)

  01111110 $\rightarrow$ (\textcolor{red}{4}-bit shift) $\rightarrow$ 1110\textcolor{red}{0000} \cdotfill(\textcolor{red}{4}=\textcolor{red}{1}00: shift \textcolor{red}{4}, 0, 0 bit)

  01111110 $\rightarrow$ (\textcolor{red}{5}-bit shift) $\rightarrow$ 110\textcolor{red}{00000} \cdotfill(\textcolor{red}{5}=\textcolor{red}{1}0\textcolor{red}{1}: shift \textcolor{red}{4}, 0, \textcolor{red}{1} bit)

  01111110 $\rightarrow$ (\textcolor{red}{6}-bit shift) $\rightarrow$ 10\textcolor{red}{000000} \cdotfill(\textcolor{red}{6}=\textcolor{red}{11}0: shift \textcolor{red}{4}, \textcolor{red}{2}, 0 bit)

  01111110 $\rightarrow$ (\textcolor{red}{7}-bit shift) $\rightarrow$ 0\textcolor{red}{0000000} \cdotfill(\textcolor{red}{7}=\textcolor{red}{111}: shift \textcolor{red}{4}, \textcolor{red}{2}, \textcolor{red}{1} bit)

\end{frame}
%------------------------------------------------ SLIDE -
\section{バレルシフタの波形 (論理右シフト)}
\begin{frame}\frametitle{\secname}
\includegraphics[width=\textwidth]{figs/barrel_shifter_vcd_srl_crop.png}

\fontsize{10pt}{12}\selectfont
\hfill\href{https://yamin.cis.k.hosei.ac.jp/lectures/logic/shift_tb.v}{\color{blue}\underline{shift\_tb.v}}~

$~$

  論理右シフト (arith $=$ 0; right $=$ 1) \cdotfill (SRL)

\vspace{3mm}
  01111110 $\rightarrow$ (\textcolor{red}{0}-bit shift) $\rightarrow$ 01111110 \cdotfill(\textcolor{red}{0}=000: shift 0, 0, 0 bit)

  01111110 $\rightarrow$ (\textcolor{red}{1}-bit shift) $\rightarrow$ \textcolor{red}{0}0111111 \cdotfill(\textcolor{red}{1}=00\textcolor{red}{1}: shift 0, 0, \textcolor{red}{1} bit)

  01111110 $\rightarrow$ (\textcolor{red}{2}-bit shift) $\rightarrow$ \textcolor{red}{00}011111 \cdotfill(\textcolor{red}{2}=0\textcolor{red}{1}0: shift 0, \textcolor{red}{2}, 0 bit)

  01111110 $\rightarrow$ (\textcolor{red}{3}-bit shift) $\rightarrow$ \textcolor{red}{000}01111 \cdotfill(\textcolor{red}{3}=0\textcolor{red}{11}: shift 0, \textcolor{red}{2}, \textcolor{red}{1} bit)
  
  10000000 $\rightarrow$ (\textcolor{red}{4}-bit shift) $\rightarrow$ \textcolor{red}{0000}1000 \cdotfill(\textcolor{red}{4}=\textcolor{red}{1}00: shift \textcolor{red}{4}, 0, 0 bit)

  10000000 $\rightarrow$ (\textcolor{red}{5}-bit shift) $\rightarrow$ \textcolor{red}{00000}100 \cdotfill(\textcolor{red}{5}=\textcolor{red}{1}0\textcolor{red}{1}: shift \textcolor{red}{4}, 0, \textcolor{red}{1} bit)

  10000000 $\rightarrow$ (\textcolor{red}{6}-bit shift) $\rightarrow$ \textcolor{red}{000000}10 \cdotfill(\textcolor{red}{6}=\textcolor{red}{11}0: shift \textcolor{red}{4}, \textcolor{red}{2}, 0 bit)

  10000000 $\rightarrow$ (\textcolor{red}{7}-bit shift) $\rightarrow$ \textcolor{red}{0000000}1 \cdotfill(\textcolor{red}{7}=\textcolor{red}{111}: shift \textcolor{red}{4}, \textcolor{red}{2}, \textcolor{red}{1} bit)

\end{frame}
%------------------------------------------------ SLIDE -
\section{バレルシフタの波形 (算術右シフト)}
\begin{frame}\frametitle{\secname}
\includegraphics[width=\textwidth]{figs/barrel_shifter_vcd_sra_crop.png}

\fontsize{10pt}{12}\selectfont
\hfill\href{https://yamin.cis.k.hosei.ac.jp/lectures/logic/shift_tb.v}{\color{blue}\underline{shift\_tb.v}}~

$~$

  算術右シフト (arith $=$ 1; right $=$ 1) \cdotfill (SRA)

\vspace{3mm}
  01111110 $\rightarrow$ (\textcolor{red}{0}-bit shift) $\rightarrow$ 01111110 \cdotfill(\textcolor{red}{0}=000: shift 0, 0, 0 bit)

  01111110 $\rightarrow$ (\textcolor{red}{1}-bit shift) $\rightarrow$ \textcolor{red}{0}0111111 \cdotfill(\textcolor{red}{1}=00\textcolor{red}{1}: shift 0, 0, \textcolor{red}{1} bit)

  01111110 $\rightarrow$ (\textcolor{red}{2}-bit shift) $\rightarrow$ \textcolor{red}{00}011111 \cdotfill(\textcolor{red}{2}=0\textcolor{red}{1}0: shift 0, \textcolor{red}{2}, 0 bit)

  01111110 $\rightarrow$ (\textcolor{red}{3}-bit shift) $\rightarrow$ \textcolor{red}{000}01111 \cdotfill(\textcolor{red}{3}=0\textcolor{red}{11}: shift 0, \textcolor{red}{2}, \textcolor{red}{1} bit)

  10000000 $\rightarrow$ (\textcolor{red}{4}-bit shift) $\rightarrow$ \textcolor{red}{1111}1000 \cdotfill(\textcolor{red}{4}=\textcolor{red}{1}00: shift \textcolor{red}{4}, 0, 0 bit)

  10000000 $\rightarrow$ (\textcolor{red}{5}-bit shift) $\rightarrow$ \textcolor{red}{11111}100 \cdotfill(\textcolor{red}{5}=\textcolor{red}{1}0\textcolor{red}{1}: shift \textcolor{red}{4}, 0, \textcolor{red}{1} bit)

  10000000 $\rightarrow$ (\textcolor{red}{6}-bit shift) $\rightarrow$ \textcolor{red}{111111}10 \cdotfill(\textcolor{red}{6}=\textcolor{red}{11}0: shift \textcolor{red}{4}, \textcolor{red}{2}, 0 bit)

  10000000 $\rightarrow$ (\textcolor{red}{7}-bit shift) $\rightarrow$ \textcolor{red}{1111111}1 \cdotfill(\textcolor{red}{7}=\textcolor{red}{111}: shift \textcolor{red}{4}, \textcolor{red}{2}, \textcolor{red}{1} bit)

\end{frame}
%------------------------------------------------ SLIDE -
\section{マルチプレクサの応用 --- RegFile}
\begin{frame}\frametitle{\secname}
\includegraphics[width=\textwidth]{figs/computer_alu.pdf}
\end{frame}
%------------------------------------------------ SLIDE -
\section{マルチプレクサの応用 --- RegFile}
\begin{frame}\frametitle{\secname}
\textcolor{red}{8 $\times$ 32 ビットレジスタ・ファイル}

\includegraphics[width=\textwidth]{figs/regfile8x32_schematic.pdf}
\end{frame}
%------------------------------------------------ SLIDE -
\section{16 進数７セグメント LED 点灯回路}
\begin{frame}\frametitle{\secname}
16 進数７セグメント LED 点灯の例

\vspace{4mm}
\includegraphics[width=\textwidth]{figs/seven_led_ex.pdf}
\end{frame}
%------------------------------------------------ SLIDE -
\section{16 進数７セグメント LED 点灯回路}
\begin{frame}\frametitle{\secname}
\fontsize{13pt}{15}\selectfont

\includegraphics[width=.6\textwidth]{figs/seg7led.pdf}


\vspace{2mm}
\fontsize{10pt}{12}\selectfont
\renewcommand{\arraystretch}{1.05}
\setlength{\tabcolsep}{2.5pt}
\begin{tabular}[t]{cccc|ccccccc}
\multicolumn{11}{c}{真理値表}\\ \hline
\multicolumn{4}{c|}{入力 (スイッチ)} & \multicolumn{7}{c}{出力 (LED)}\\ \hline
 n[3] & n[2] & n[1] & n[0] & led[6] & led[5] & led[4] & led[3] & led[2] & led[1] & led[0] \\ \hline
 0 & 0 & 0 & 0   &   1 & 0 & 0 & 0 & 0 & 0 & 0 \\
 0 & 0 & 0 & 1   &   1 & 1 & 1 & 1 & 0 & 0 & 1 \\
 $\cdots$ & $\cdots$ & $\cdots$ & $\cdots$ & $\cdots$ & $\cdots$ & $\cdots$ & $\cdots$ & $\cdots$ & $\cdots$ & $\cdots$\\
 1 & 0 & 0 & 0   &   0 & 0 & 0 & 0 & 0 & 0 & 0 \\
 $\cdots$ & $\cdots$ & $\cdots$ & $\cdots$ & $\cdots$ & $\cdots$ & $\cdots$ & $\cdots$ & $\cdots$ & $\cdots$ & $\cdots$\\
 1 & 1 & 1 & 1   &   0 & 0 & 0 & 1 & 1 & 1 & 0 \\ \hline
\end{tabular}

\vspace{2mm}
\color{red}
カルノー図を使用して、各 led 出力信号を簡単化する。

\vspace{-71mm}
\hspace*{92mm}
\textcolor{red}{led[$i$] $=$ 0: 点灯}

\vspace{4mm}
\hspace*{92mm}
led[$i$] $=$ 1: 消灯

\end{frame}
%------------------------------------------------ SLIDE -
\section{16 進数７セグメント LED 点灯回路}
\begin{frame}\frametitle{\secname}
６つの７セグメント\,LED\,と\,10\,個のスイッチ

\vspace{3mm}
\includegraphics[width=.93\textwidth]{figs/digiclock.eps}
\end{frame}
%------------------------------------------------ SLIDE -
\section{コンピューターシステムとALUの関係}
\begin{frame}\frametitle{\secname}
\includegraphics[width=\textwidth]{figs/computer_alu.pdf}
\end{frame}
%------------------------------------------------ SLIDE -
\section{簡単な~ALU~の設計 (シンボル)}
\begin{frame}\frametitle{\secname}
\includegraphics[width=\textwidth]{figs/alu8op8bit_sym.pdf}
\end{frame}
%------------------------------------------------ SLIDE -
\section{簡単な~ALU~の設計 (回路)}
\begin{frame}\frametitle{\secname}
\includegraphics[width=\textwidth]{figs/alu8op8bit.pdf}

\vspace{2mm}
すべての演算を用意して、マルチプレクサで選択する。
\end{frame}
%------------------------------------------------ SLIDE -
\section{簡単な~ALU~の設計 (波形)}
\begin{frame}\frametitle{\secname}
ALU のシミュレーション波形

\vspace{3mm}
\includegraphics[width=\textwidth]{figs/alu8_crop.png}

\fontsize{8pt}{10}\selectfont
\hfill\href{https://yamin.cis.k.hosei.ac.jp/lectures/logic/alu8_tb.v}{\textcolor{blue}{\underline{alu8\_tb.v}}}~

\vspace{6mm}
\setlength{\tabcolsep}{1.4pt}
\begin{tabular}{cccccccccccl}
                & \red 0 0 0 (論理積) &~~&             & \red 0 0 1  (論理和) &~~&          & \red 0 1 0 (足し算) &~~&          & \red 0 1 1 (引き算) & \blue $\leftarrow$ aluc \\
                & 1 1 0 0 1 1 1 0    &~~&             & 1 1 0 0 1 1 1 0     &~~&          & 1 1 0 0 1 1 1 0    &~~&          & 1 1 0 0 1 1 1 0    & \blue $\leftarrow$ a \\
\red $\&$       & 1 0 1 0 0 1 0 1    &~~& \red $\mid$ & 1 0 1 0 0 1 0 1     &~~& \red $+$ & 1 0 1 0 0 1 0 1    &~~& \red $-$ & 1 0 1 0 0 1 0 1    & \blue $\leftarrow$ b \\\cline{1-2}\cline{4-5}\cline{7-8}\cline{10-11}
\rule{0pt}{2ex} & 1 0 0 0 0 1 0 0    &~~&             & 1 1 1 0 1 1 1 1     &~~&          & 0 1 1 1 0 0 1 1    &~~&          & 0 0 1 0 1 0 0 1    & \blue $\leftarrow$ s \\
\ \\
                & \red 1 0 0 (SLL)   &~~&             & \red 1 0 1  (SRL)   &~~&          & \red 1 1 0 (XOR)   &~~&          & \red 1 1 1 (SRA)   & \blue $\leftarrow$ aluc \\
                & 1 1 0 0 1 1 1 0    &~~&             & 1 1 0 0 1 1 1 0     &~~&          & 1 1 0 0 1 1 1 0    &~~&          & \textcolor{blue}{1} 1 0 0 1 1 1 0  & \blue $\leftarrow$ a \\
\red $\leftarrow$ & \textcolor{lightgray}{1 0 1 0 0} 1 0 1  &~~& \red $\rightarrow$ & \textcolor{lightgray}{1 0 1 0 0} 1 0 1  &~~& \red $\oplus$ & 1 0 1 0 0 1 0 1  &~~& \red $\rightarrow$ & \textcolor{lightgray}{1 0 1 0 0} 1 0 1  & \blue $\leftarrow$ b \\\cline{1-2}\cline{4-5}\cline{7-8}\cline{10-11}
\rule{0pt}{2ex} & 1 1 0 \textcolor{blue}{0 0 0 0 0}  &~~&             & \textcolor{blue}{0 0 0 0 0} 1 1 0 &~~&           & 0 1 1 0 1 0 1 1  &~~&          & \textcolor{blue}{1 1 1 1 1} 1 1 0  & \blue $\leftarrow$ s \\
%                & aを左に5ビットずらす  &~~&             & aを論理右に5ビットずらす  &~~&             &  &~~&             & aを算術右に5ビットずらす\\
\end{tabular}

\fontsize{6pt}{6}\selectfont
\color{yellow}
\vspace{-54mm}
\hspace*{20mm}AND
\hspace*{8mm}~OR~
\hspace*{8mm}ADD
\hspace*{8mm}SUB
\hspace*{8mm}SLL
\hspace*{8mm}SRL
\hspace*{9mm}XOR
\hspace*{8mm}SRA

\end{frame}
%------------------------------------------------ SLIDE -
\section{マルチプレクサ}
\begin{frame}\frametitle{\secname}
\textcolor{blue}{まとめ}

\begin{itemize}
  \color{blue}
\setlength{\itemsep}{1.5mm}
\item マルチプレクサ
\item 組み合わせ回路設計の手順
\item 1 ビット 2-to-1 のマルチプレクサ
\item 4 ビット 2-to-1 のマルチプレクサ
\item 1 ビット 4-to-1 のマルチプレクサ
\item 4 ビット 4-to-1 のマルチプレクサ
\item バレルシフタ (Barrel shifter) 回路
\item 7 セグメント~LED
\item ALU: Arithmetic Logic Unit (算術論理演算回路)
\end{itemize}

\end{frame}
%------------------------------------------------ SLIDE -
\section{課題~IX (200 点~+ 100 点)}
\begin{frame}[fragile]\frametitle{\secname}
\fontsize{11pt}{12.7}\selectfont

問題１： ($100$ 点): ４ビット 4-to-1 のマルチプレクサ回路を設計し動作検証シミュレーションして下さい~(15-19ページを参照)。

{\fontsize{9pt}{10}\selectfont
\begin{code}
`timescale 1ns/1ns
module mux4x4 (A0, A1, A2, A3, S, Y);
    input  [1:0] S;
    input  [3:0] A0, A1, A2, A3;
    output [3:0] Y;

    // mux4x1 (A0,    A1,    A2,    A3,    S0,   S1,   Y);

    mux4x1 i0 (A0[0], A1[0], A2[0], A3[0], S[0], S[1], Y[0]); // bit 0
    mux4x1 i1 (     ,      ,      ,      ,     ,     ,     ); // bit 1
    mux4x1 i2 (     ,      ,      ,      ,     ,     ,     ); // bit 2
    mux4x1 i3 (     ,      ,      ,      ,     ,     ,     ); // bit 3

endmodule
\end{code}
}

モジュール名は~\href{https://yamin.cis.k.hosei.ac.jp/lectures/logic/mux4x4.v}{\textcolor{blue}{\underline{mux4x4}}} にすること。\phantom{\underline{g}}

テストベンチ~\href{https://yamin.cis.k.hosei.ac.jp/lectures/logic/mux4x4_tb.v}{\textcolor{blue}{\underline{mux4x4\_tb.v}}} を使って下さい。

\end{frame}
%------------------------------------------------ SLIDE -
\section{課題~IX (200 点~+ 100 点)}
\begin{frame}[fragile]\frametitle{\secname}
\fontsize{11pt}{12.7}\selectfont

問題２： ($100$ 点): 16 進数~7 セグメント~LED 点灯回路を設計し動作検証シミュレーションして下さい~(30$\sim$31ページを参照)。

{\fontsize{9pt}{10}\selectfont
\begin{code}
`timescale 1ns/1ns
module led7seg (n, led);
    input  [3:0] n;   // 4 bits, 2^4=16: 0-F in hexadecimal format
    output [6:0] led; // 7-segment LEDs: 0: light on; 1: light off

    assign led[6] =                                 ; // segment 6
    assign led[5] =                                 ; // segment 5
    assign led[4] =                                 ; // segment 4
    assign led[3] =                                 ; // segment 3
    assign led[2] =                                 ; // segment 2
    assign led[1] =                                 ; // segment 1
    assign led[0] =                                 ; // segment 0

endmodule
\end{code}
}

モジュール名は~\href{https://yamin.cis.k.hosei.ac.jp/lectures/logic/led7seg.v}{\textcolor{blue}{\underline{led7seg}}} にすること。

テストベンチ~\href{https://yamin.cis.k.hosei.ac.jp/lectures/logic/led7seg_tb.v}{\textcolor{blue}{\underline{led7seg\_tb.v}}} を使って下さい。

\end{frame}
%------------------------------------------------ SLIDE -
\section{課題~IX (200 点~+ 100 点)}
\begin{frame}[fragile]\frametitle{\secname}
\fontsize{11pt}{12.7}\selectfont

\textcolor{brown}{{オプション~($+100$ 点):}} 簡単な~ALU~を設計し動作検証シミュレーションして下さい~(33$\sim$36ページを参照)。

{\fontsize{9pt}{9.333}\selectfont
\begin{code}
`timescale 1ns/1ns
module alu8 (a, b, aluc, s);
    input  [7:0] a, b;
    input  [2:0] aluc;
    output [7:0] s;
    wire   [7:0] d_and = a & b;                         // AND
    wire   [7:0] d_or  = a | b;                         // OR
    wire   [7:0] d_xor = a ^ b;                         // XOR
    wire   [7:0] d_ao, d_as, d_sh, d_xa;                // internal wires
    mux2x8  mx_a (d_and, d_or, aluc[0], d_ao);          // 0: AND or OR
    addsub8 as   (a,     b,    aluc[0], d_as);          // 1: ADD or SUB
    shift   sh   (a,   b[2:0], aluc[0], aluc[1], d_sh); // 2: SLL or SRL
    mux2x8  mx_x (     ,     ,        , d_xa);          // 3: XOR or SRA
    mux4x8  mx_s (     ,     ,        ,     ,     , s); // final result s
endmodule
\end{code}
}

モジュール名は~\href{https://yamin.cis.k.hosei.ac.jp/lectures/logic/alu8.v}{\textcolor{blue}{\underline{alu8}}} にすること。\phantom{\underline{g}}

テストベンチ~\href{https://yamin.cis.k.hosei.ac.jp/lectures/logic/alu8_tb.v}{\textcolor{blue}{\underline{alu8\_tb.v}}} を使って下さい。

\end{frame}
%------------------------------------------------ SLIDE -
\end{document}
%------------------------------------------------ SLIDE -
