diff --git a/AR/02_electricity/02_electricity.tex b/AR/02_electricity/02_electricity.tex index 191fb69..6c09423 100644 --- a/AR/02_electricity/02_electricity.tex +++ b/AR/02_electricity/02_electricity.tex @@ -3,7 +3,7 @@ % Author: James Foster, pogil@jgfoster.net % comment out for student version -% \ifdefined\Student\relax\else\def\Teacher{}\fi +\ifdefined\Student\relax\else\def\Teacher{}\fi \documentclass[12pt]{article} diff --git a/AR/02_electricity/electric_circuit.tex b/AR/02_electricity/electric_circuit.tex index d2a39e2..d10fdf2 100644 --- a/AR/02_electricity/electric_circuit.tex +++ b/AR/02_electricity/electric_circuit.tex @@ -39,12 +39,12 @@ \end{answer} \Q With the switch closed (see the diagram below), is there pressure between the switch and the resistor? - \vspace{10pt} - \begin{center} - \includegraphics[width=0.3\textwidth]{figures/circuit_closed_switch.png} - \par\vspace{5pt} - {\small Figure 3: Circuit with closed switch} - \end{center} + \vspace{10pt} + \begin{center} + \includegraphics[width=0.3\textwidth]{figures/circuit_closed_switch.png} + \par\vspace{5pt} + {\small Figure 3: Circuit with closed switch} + \end{center} \begin{answer}[1in] Yes, there is pressure between the switch and the resistor. \end{answer} @@ -68,12 +68,12 @@ \end{center} \Q The circuit in Figure 5 does not have a wire across the bottom completing the circuit. How would this change impact the number of electrons moving through the circuit? - \vspace{10pt} - \begin{center} - \includegraphics[width=0.3\textwidth]{figures/circuit_two_grounds.png} - \par\vspace{5pt} - {\small Figure 5: Circuit with two grounds} - \end{center} + \vspace{10pt} + \begin{center} + \includegraphics[width=0.3\textwidth]{figures/circuit_two_grounds.png} + \par\vspace{5pt} + {\small Figure 5: Circuit with two grounds} + \end{center} \begin{answer}[1in] Because the ``reservoir'' is infinite and not under pressure, it makes no difference when the bottom wire is replaced with two grounds. \end{answer} @@ -83,19 +83,19 @@ \Q The following table has observations of electrons/second (current is measured in amperes), pressure (voltage is measured in volts), and resistance (measured in ohms). From this data, derive Ohm's Law, a formula for I in terms of E and R. \vspace{10pt} \begin{center} - \begin{tabular}{|c|c|c|} - \hline - Amperes (I) & Voltage (E) & Resistance (R) \\ - \hline - 5 & 100 & 20 \\ - \hline - 5 & 200 & 40 \\ - \hline - 10 & 200 & 20 \\ - \hline - 2 & 50 & 25 \\ - \hline - \end{tabular} + \begin{tabular}{|c|c|c|} + \hline + Amperes (I) & Voltage (E) & Resistance (R) \\ + \hline + 5 & 100 & 20 \\ + \hline + 5 & 200 & 40 \\ + \hline + 10 & 200 & 20 \\ + \hline + 2 & 50 & 25 \\ + \hline + \end{tabular} \end{center} \begin{answer}[1in] diff --git a/AR/02_electricity/figures/relay_extend_distance_solution.png b/AR/02_electricity/figures/relay_extend_distance_solution.png new file mode 100644 index 0000000..f875dd7 Binary files /dev/null and b/AR/02_electricity/figures/relay_extend_distance_solution.png differ diff --git a/AR/02_electricity/telegraphs_and_relays.tex b/AR/02_electricity/telegraphs_and_relays.tex index b03f62f..e9fa0ad 100644 --- a/AR/02_electricity/telegraphs_and_relays.tex +++ b/AR/02_electricity/telegraphs_and_relays.tex @@ -61,7 +61,11 @@ \vspace{10pt} \begin{center} - \includegraphics[width=0.8\textwidth]{figures/relay_extend_distance.png} + \ifdefined\Teacher + \includegraphics[width=0.6\textwidth]{figures/relay_extend_distance_solution.png} + \else + \includegraphics[width=0.6\textwidth]{figures/relay_extend_distance.png} + \fi \par\vspace{5pt} {\small Figure 10: Use of relay to extend distance} \end{center} \ No newline at end of file diff --git a/AR/04_logic_and_gates/04_logic_and_gates.tex b/AR/04_logic_and_gates/04_logic_and_gates.tex new file mode 100644 index 0000000..9ec22f0 --- /dev/null +++ b/AR/04_logic_and_gates/04_logic_and_gates.tex @@ -0,0 +1,52 @@ +% Source: CPTR 280 Computer Organization and Assembly Language Fall 2020 +% File: "04 Logic and Gates (key).pdf" +% Author: James Foster, pogil@jgfoster.net + +% comment out for student version +% \ifdefined\Student\relax\else\def\Teacher{}\fi + +\documentclass[12pt]{article} + +\title{Activity 4: Logic, Switches, and Gates} +\author{James Foster} +\newcommand{\activityeditor}{James Foster} +\newcommand{\activitysource}{\url{pogil@jgfoster.net}} +\date{Fall 2020} + +\input{../../cspogil.sty} +\usepackage{graphicx} +\usepackage{tabularx} + +\begin{document} + + \begin{center} + \maketitle + \rolenames + \end{center} + + \keyquestions{ + \item Model 1, Question \#1, a--f + \item Model 1, Question \#7, a--d + \item Model 2, Question \#11 a--d + } + + \newpage + \maketitle + + Boolean logic forms the basis for designing the digital logic circuits that make up a computer. In this lesson we will look at how to build various digital logic gates using relays. + + \guides{ + \item Create truth tables for AND, OR, NOT, NAND, NOR, and XOR; and + \item Use relays to create digital logic gates. + }{ + \item Draw circuit diagrams representing six logic gates. + }{ + No additional notes + } + + \input{truth_tables.tex} + \newpage + \input{logic_gates.tex} + \newpage + +\end{document} \ No newline at end of file diff --git a/AR/04_logic_and_gates/figures/and_gate_solution.png b/AR/04_logic_and_gates/figures/and_gate_solution.png new file mode 100644 index 0000000..49f0d66 Binary files /dev/null and b/AR/04_logic_and_gates/figures/and_gate_solution.png differ diff --git a/AR/04_logic_and_gates/figures/and_gate_template.png b/AR/04_logic_and_gates/figures/and_gate_template.png new file mode 100644 index 0000000..3e375d0 Binary files /dev/null and b/AR/04_logic_and_gates/figures/and_gate_template.png differ diff --git a/AR/04_logic_and_gates/figures/generic_relay.png b/AR/04_logic_and_gates/figures/generic_relay.png new file mode 100644 index 0000000..652f324 Binary files /dev/null and b/AR/04_logic_and_gates/figures/generic_relay.png differ diff --git a/AR/04_logic_and_gates/figures/inverter_solution.png b/AR/04_logic_and_gates/figures/inverter_solution.png new file mode 100644 index 0000000..70781c5 Binary files /dev/null and b/AR/04_logic_and_gates/figures/inverter_solution.png differ diff --git a/AR/04_logic_and_gates/figures/inverter_template.png b/AR/04_logic_and_gates/figures/inverter_template.png new file mode 100644 index 0000000..c0681a6 Binary files /dev/null and b/AR/04_logic_and_gates/figures/inverter_template.png differ diff --git a/AR/04_logic_and_gates/figures/logic_gate_symbols.png b/AR/04_logic_and_gates/figures/logic_gate_symbols.png new file mode 100644 index 0000000..0049a52 Binary files /dev/null and b/AR/04_logic_and_gates/figures/logic_gate_symbols.png differ diff --git a/AR/04_logic_and_gates/figures/nand_gate_solution.png b/AR/04_logic_and_gates/figures/nand_gate_solution.png new file mode 100644 index 0000000..ca8af72 Binary files /dev/null and b/AR/04_logic_and_gates/figures/nand_gate_solution.png differ diff --git a/AR/04_logic_and_gates/figures/nand_gate_template.png b/AR/04_logic_and_gates/figures/nand_gate_template.png new file mode 100644 index 0000000..4a48497 Binary files /dev/null and b/AR/04_logic_and_gates/figures/nand_gate_template.png differ diff --git a/AR/04_logic_and_gates/figures/nor_gate_solution.png b/AR/04_logic_and_gates/figures/nor_gate_solution.png new file mode 100644 index 0000000..a7b861e Binary files /dev/null and b/AR/04_logic_and_gates/figures/nor_gate_solution.png differ diff --git a/AR/04_logic_and_gates/figures/nor_gate_template.png b/AR/04_logic_and_gates/figures/nor_gate_template.png new file mode 100644 index 0000000..ce9f40b Binary files /dev/null and b/AR/04_logic_and_gates/figures/nor_gate_template.png differ diff --git a/AR/04_logic_and_gates/figures/or_gate_solution.png b/AR/04_logic_and_gates/figures/or_gate_solution.png new file mode 100644 index 0000000..291c3df Binary files /dev/null and b/AR/04_logic_and_gates/figures/or_gate_solution.png differ diff --git a/AR/04_logic_and_gates/figures/or_gate_template.png b/AR/04_logic_and_gates/figures/or_gate_template.png new file mode 100644 index 0000000..6a30941 Binary files /dev/null and b/AR/04_logic_and_gates/figures/or_gate_template.png differ diff --git a/AR/04_logic_and_gates/figures/switch_relay_light.png b/AR/04_logic_and_gates/figures/switch_relay_light.png new file mode 100644 index 0000000..8bf6337 Binary files /dev/null and b/AR/04_logic_and_gates/figures/switch_relay_light.png differ diff --git a/AR/04_logic_and_gates/figures/switches_in_parallel.png b/AR/04_logic_and_gates/figures/switches_in_parallel.png new file mode 100644 index 0000000..6c98eb8 Binary files /dev/null and b/AR/04_logic_and_gates/figures/switches_in_parallel.png differ diff --git a/AR/04_logic_and_gates/figures/switches_in_series.png b/AR/04_logic_and_gates/figures/switches_in_series.png new file mode 100644 index 0000000..1b7a7d0 Binary files /dev/null and b/AR/04_logic_and_gates/figures/switches_in_series.png differ diff --git a/AR/04_logic_and_gates/logic_gates.tex b/AR/04_logic_and_gates/logic_gates.tex new file mode 100644 index 0000000..999ea39 --- /dev/null +++ b/AR/04_logic_and_gates/logic_gates.tex @@ -0,0 +1,172 @@ +\model{Logic Gates} + + Figure 1 shows an electric circuit with a battery on the left, a light bulb on the right, two switches on the top, and a wire along the bottom (to complete the circuit). When a switch is open (as shown) we assign it a value of zero. When a switch is closed (and electricity can flow) we assign it a value of one. The light is on when electricity flows through it. When the light is off, we treat it as zero; when it is on it is one. + + \vspace{10pt} + \begin{center} + \includegraphics[width=0.35\textwidth]{figures/switches_in_series.png} + \par\vspace{5pt} + {\small Figure 1: Switches in Series} + \end{center} + + {\it\large Refer to Model 2 above as your team develops consensus answers + to the questions below.} + + \quest{25 min} + + \Q Considering Figure 1: + \begin{enumerate} + \item What are the values of the two switches? + \hfill\ans{0} + + \item What is the value of the light? + \hfill\ans{0} + + \item If we treat the switches as inputs and the light bulb as an output, which truth table matches Figure 1? + \begin{answer}[0.5in] + AND + \end{answer} + \end{enumerate} + + Figure 2 shows an electric circuit with a voltage source on the left, a light bulb and ground on the right, and two switches in the center. (The voltage source and ground replace the battery and connecting wire.) When either switch is closed, electricity flows through the switch and the light bulb from the voltage source to ground. + + \vspace{10pt} + \begin{center} + \includegraphics[width=0.3\textwidth]{figures/switches_in_parallel.png} + \par\vspace{5pt} + {\small Figure 2: Switches in Parallel} + \end{center} + + \Q Which truth table matches Figure 2? + \hfill\ans{OR} + + \vspace{10pt} + As shown above, we can create circuits with manual switches that mimic truth tables. + To create an automated computer, we need a way to automate these switches.\\ + + Figure 3 shows a circuit with two voltage sources, two switches (one black and one grey---more on this difference shortly), two grounds, a light, + and connecting wires, all of which were introduced above. In addition, in the center below the second (grey) switch and above the first ground, + we have an inductor (the diagram is supposed to look like a coil of wires). While a traditional switch is manually operated (you press it on or off with your finger), + you can also control a switch by a magnet, or inductor, which pulls the switch down when electricity runs through it. An inductor plus a switch is called a relay and forms one component + (the switch part of a relay can be operated only by the inductor, so is not considered a separate input to the circuit). + + \vspace{10pt} + \begin{center} + \includegraphics[width=0.35\textwidth]{figures/switch_relay_light.png} + \par\vspace{5pt} + {\small Figure 3: Switch, Relay, and Light} + \end{center} + + \Q Considering Figure 3 and the definition of inputs and outputs in question 8(c): + \begin{enumerate} + \item What external input(s) does this circuit have? + \hfill\ans{Just one, the first switch} + + \item What external output(s) does this circuit have? + \hfill\ans{Just one, the light} + \end{enumerate} + + Figure 4 shows a relay made up of a (grey) switch on the top and an inductor (connected to ground) on the bottom. Note that this is similar to the one in Figure 3, + but with input and output labels next to the four black dots. Note also that, unlike a manual switch that is either open (in which case electricity cannot pass) or closed + (so electricity can pass), the switch part of a relay has two outputs, and will send electricity on one path if the switch is up and on another path if the switch is down. + (Of course, if nothing is connected to the output then electricity will not flow.) + + \vspace{10pt} + \begin{center} + \includegraphics[width=0.25\textwidth]{figures/generic_relay.png} + \par\vspace{5pt} + {\small Figure 4: Generic Relay} + \end{center} + + \Q Consider the relay in Figure 3 and the labels in Figure 4. What is connected to the\key\\[-2.5mm] following labeled endpoints (more than just a wire!): + \begin{multicols}{2} + \begin{enumerate} + \item input 0? + \hfill\ans{A power source} + + \item input 1? + \hfill\ans{One side of the manual switch} + + \item output 0? + \hfill\ans{Nothing} + + \item output 1? + \hfill\ans{One side of the light} + \end{enumerate} + \end{multicols} + + \Q Complete Figure 5 to create an inverter (a NOT circuit; see question 4). + That is, when the input (left, black) switch is open (with a value of 0), the light is on (with a value of 1), + and when the switch is closed (1), the light is off (0). Hint: What would change from Figure 3 to have the light on instead of off when the switch is open (as shown)? + \vspace{10pt} + \begin{center} + \ifdefined\Teacher + \includegraphics[width=0.4\textwidth]{figures/inverter_solution.png} + \else + \includegraphics[width=0.4\textwidth]{figures/inverter_template.png} + \fi + \par\vspace{5pt} + {\small Figure 5: Inverter} + \end{center} + + \Q A gate is a combination of two or more relays (so technically the inverter is not a gate since it has only one relay, + but it tends to be included in lists of digital logic gates).\\ + Add wires to Figure 6 to create an AND gate (see question 3). (Hint: for the light to be on both switches need to be closed; think about what path would bring electricity to the light.) + \vspace{10pt} + \begin{center} + \ifdefined\Teacher + \includegraphics[width=0.5\textwidth]{figures/and_gate_solution.png} + \else + \includegraphics[width=0.5\textwidth]{figures/and_gate_template.png} + \fi + \par\vspace{5pt} + {\small Figure 6: AND Gate} + \end{center} + + \Q Add voltage sources and wires to Figure 7 to create an OR gate (see question 2). + \vspace{10pt} + \begin{center} + \ifdefined\Teacher + \includegraphics[width=0.5\textwidth]{figures/or_gate_solution.png} + \else + \includegraphics[width=0.5\textwidth]{figures/or_gate_template.png} + \fi + \par\vspace{5pt} + {\small Figure 7: OR Gate} + \end{center} + + Circuit designers use special symbols to represent the gates we discuss in this lesson. As you complete the exercises, consider how much easier it is to use a simple symbol. Learn them! + + \vspace{10pt} + \begin{center} + \includegraphics[width=0.7\textwidth]{figures/logic_gate_symbols.png} + \par\vspace{5pt} + {\small Figure 8: Logic Gate Symbols} + \end{center} + + \Q Add components (voltage sources, wires, and logic gates from Figure 8 as needed) to Figure 9 to create a NAND gate (see question 6). + \vspace{10pt} + \begin{center} + \ifdefined\Teacher + \includegraphics[width=0.5\textwidth]{figures/nand_gate_solution.png} + \else + \includegraphics[width=0.5\textwidth]{figures/nand_gate_template.png} + \fi + \par\vspace{5pt} + {\small Figure 9: NAND Gate} + \end{center} + + \newpage + + \Q Add components to Figure 10 to create an NOR gate (see question 5). + + \vspace{10pt} + \begin{center} + \ifdefined\Teacher + \includegraphics[width=0.5\textwidth]{figures/nor_gate_solution.png} + \else + \includegraphics[width=0.5\textwidth]{figures/nor_gate_template.png} + \fi + \par\vspace{5pt} + {\small Figure 10: NOR Gate} + \end{center} \ No newline at end of file diff --git a/AR/04_logic_and_gates/truth_tables.tex b/AR/04_logic_and_gates/truth_tables.tex new file mode 100644 index 0000000..11e1eac --- /dev/null +++ b/AR/04_logic_and_gates/truth_tables.tex @@ -0,0 +1,186 @@ +\model{Truth Tables} + + In conventional algebra (with numbers), the operands (usually letters) represent numbers and the operators + (symbols such as + and $\cdot$) indicate how these numbers are to be combined. By contrast, in Boolean algebra + (named for George Boole) an operand represent a set of things and, while the operators still specify how they are to be combined, + the meanings of the symbols are different. The following table shows four operators, two operands, and three samples. + Carefully consider the ``Meaning'' of each operator, operand, and sample to answer the questions. + + \vspace{10pt} + \begin{center} + \begin{tabular}{|c|l||c|l||c|l|} + \hline + \textbf{Operator} & \textbf{Meaning} & \textbf{Operand} & \textbf{Meaning} & \textbf{Sample} & \textbf{Meaning} \\ + \hline + $x + y$ & union (elements & 0 & an empty set (not & F & female \\ + & found in either $x$ or $y$) & & the number zero) & & cats \\ + \hline + $x \cdot y$ & intersection (elements & 1 & a universal set & M & male cats \\ + & found in both $x$ and $y$) & & (not the number 1) & & \\ + \hline + $x - y$ & difference (a copy of & & & 0 & there are \\ + & $x$ after removing all & & & & no other \\ + & elements also in $y$) & & & & cats \\ + \hline + $\bar{x}$ & not (same as $1 - x$) & & & & \\ + \hline + \end{tabular} + \end{center} + + {\it\large Refer to Model 1 above as your team develops consensus answers + to the questions below.} + + \quest{25 min} + + \Q Determine the value (0, 1, M, or F):\key\\[-2.5mm] + \begin{multicols}{2} + \begin{enumerate} + \item $M + F = $ \hfill\ans[0.5in]{1} + \item $1 - M = $ \hfill\ans[0.5in]{F} + \item $F \cdot M = $ \hfill\ans[0.5in]{0} + \item $1 \cdot F = $ \hfill\ans[0.5in]{F} + \item $0 \cdot F = $ \hfill\ans[0.5in]{0} + \item $0 + F = $ \hfill\ans[0.5in]{F} + \item $1 + F = $ \hfill\ans[0.5in]{1} + \item $F + (1 - F) = $ \hfill\ans[0.5in]{1} + \item $F \cdot (1 - F) = $ \hfill\ans[0.5in]{0} + \item $F \cdot F = $ \hfill\ans[0.5in]{F} + \item $F + F = $ \hfill\ans[0.5in]{F} + \item $\bar{M} = $ \hfill\ans[0.5in]{F} + \item $M + \bar{M} = $ \hfill\ans[0.5in]{1} + \end{enumerate} + \end{multicols} + + \newpage + + \Q Determine the value (0 or 1), then fill in the OR truth table. + \begin{multicols}{2} + \begin{enumerate} + \item $0 + 0 = $ \hfill\ans[0.5in]{0} + \item $0 + 1 = $ \hfill\ans[0.5in]{1} + \item $1 + 0 = $ \hfill\ans[0.5in]{1} + \item $1 + 1 = $ \hfill\ans[0.5in]{1} + \end{enumerate} + \end{multicols} + \vspace{10pt} + \begin{center} + \begin{tabular}{|c|c|c|} + \hline + \textbf{OR} & 0 & 1 \\ + \hline + 0 & \ans[0.3in]{0} & \ans[0.3in]{1} \\ + \hline + 1 & \ans[0.3in]{1} & \ans[0.3in]{1} \\ + \hline + \end{tabular} + \end{center} + + \Q Determine the value (0 or 1), then fill in the AND truth table. + \begin{multicols}{2} + \begin{enumerate} + \item $0 \cdot 0 = $ \hfill\ans[0.5in]{0} + \item $0 \cdot 1 = $ \hfill\ans[0.5in]{0} + \item $1 \cdot 0 = $ \hfill\ans[0.5in]{0} + \item $1 \cdot 1 = $ \hfill\ans[0.5in]{1} + \end{enumerate} + \end{multicols} + \vspace{10pt} + \begin{center} + \begin{tabular}{|c|c|c|} + \hline + \textbf{AND} & 0 & 1 \\ + \hline + 0 & \ans[0.3in]{0} & \ans[0.3in]{0} \\ + \hline + 1 & \ans[0.3in]{0} & \ans[0.3in]{1} \\ + \hline + \end{tabular} + \end{center} + + \Q Determine the value (0 or 1), then fill in the NOT Truth Table. + \begin{multicols}{2} + \begin{enumerate} + \item $\bar{0} = $ \hfill\ans[0.5in]{1} + \item $\bar{1} = $ \hfill\ans[0.5in]{0} + \end{enumerate} + \end{multicols} + \vspace{10pt} + \begin{center} + \begin{tabular}{|c|c|} + \hline + \textbf{NOT} & \\ + \hline + 0 & \ans[0.3in]{1} \\ + \hline + 1 & \ans[0.3in]{0} \\ + \hline + \end{tabular} + \end{center} + + \Q Determine the value (0 or 1), then fill in the NOR truth table. + \begin{multicols}{2} + \begin{enumerate} + \item $\overline{0 + 0} = $ \hfill\ans[0.5in]{1} + \item $\overline{0 + 1} = $ \hfill\ans[0.5in]{0} + \item $\overline{1 + 0} = $ \hfill\ans[0.5in]{0} + \item $\overline{1 + 1} = $ \hfill\ans[0.5in]{0} + \end{enumerate} + \end{multicols} + \vspace{10pt} + \begin{center} + \begin{tabular}{|c|c|c|} + \hline + \textbf{NOR} & 0 & 1 \\ + \hline + 0 & \ans[0.3in]{1} & \ans[0.3in]{0} \\ + \hline + 1 & \ans[0.3in]{0} & \ans[0.3in]{0} \\ + \hline + \end{tabular} + \end{center} + + \newpage + + \Q Determine the value (0 or 1), then fill in the NAND truth table. + \begin{multicols}{2} + \begin{enumerate} + \item $\overline{0 \cdot 0} = $ \hfill\ans[0.5in]{1} + \item $\overline{0 \cdot 1} = $ \hfill\ans[0.5in]{1} + \item $\overline{1 \cdot 0} = $ \hfill\ans[0.5in]{1} + \item $\overline{1 \cdot 1} = $ \hfill\ans[0.5in]{0} + \end{enumerate} + \end{multicols} + \vspace{10pt} + \begin{center} + \begin{tabular}{|c|c|c|} + \hline + \textbf{NAND} & 0 & 1 \\ + \hline + 0 & \ans[0.3in]{1} & \ans[0.3in]{1} \\ + \hline + 1 & \ans[0.3in]{1} & \ans[0.3in]{0} \\ + \hline + \end{tabular} + \end{center} + + \Q Calculate $(x + y) \cdot (\overline{x \cdot y})$ for each of the following, then fill in the XOR truth table.\key\\[-2.5mm] + \begin{multicols}{2} + \begin{enumerate} + \item $x=0, y=0 \rightarrow $ \hfill\ans[0.5in]{0} + \item $x=0, y=1 \rightarrow $ \hfill\ans[0.5in]{1} + \item $x=1, y=0 \rightarrow $ \hfill\ans[0.5in]{1} + \item $x=1, y=1 \rightarrow $ \hfill\ans[0.5in]{0} + \end{enumerate} + \end{multicols} + \vspace{10pt} + \begin{center} + \begin{tabular}{|c|c|c|} + \hline + \textbf{XOR} & $y = 0$ & $y = 1$ \\ + \hline + $x = 0$ & \ans[0.3in]{0} & \ans[0.3in]{1} \\ + \hline + $x = 1$ & \ans[0.3in]{1} & \ans[0.3in]{0} \\ + \hline + \end{tabular} + \end{center} \ No newline at end of file diff --git a/AR/05_addition/05_addition.tex b/AR/05_addition/05_addition.tex new file mode 100644 index 0000000..5a8585a --- /dev/null +++ b/AR/05_addition/05_addition.tex @@ -0,0 +1,56 @@ +% Source: CPTR 280 Computer Organization and Assembly Language Fall 2020 +% File: "05 Addition (key).pdf" +% Author: James Foster, pogil@jgfoster.net + +% comment out for student version +% \ifdefined\Student\relax\else\def\Teacher{}\fi + +\documentclass[12pt]{article} + +\title{Activity 5: Addition} +\author{James Foster} +\newcommand{\activityeditor}{James Foster} +\newcommand{\activitysource}{\url{pogil@jgfoster.net}} +\date{Fall 2020} + +\input{../../cspogil.sty} +\usepackage{graphicx} +\usepackage{tabularx} + +\begin{document} + + \begin{center} + \maketitle + \rolenames + \end{center} + + \keyquestions{ + \item Model 1, Question \#3 + \item Model 3, Question \#8.g + \item Model 4, Question \#9 + } + + \newpage + \maketitle + + Just as number systems can be simplified to binary, most math operations can be simplified to addition. In this lesson we will build on earlier exercises dealing with binary and with digital logic gates to understand how computers do addition and subtraction. + + \guide{ + \item Describe the logic circuits used in adding binary numbers; + \item Use nine's complement to subtract without borrowing; and, + \item Represent negative numbers in binary using two's complement. + }{ + \item Reflect on how teams can ensure all members participate. + }{ + No additional notes + } + + \input{addition_with_carry.tex} + \newpage + \input{half_adder_circuit.tex} + \newpage + \input{full_adder_circuit.tex} + \newpage + \input{multi_bit_adder.tex} + +\end{document} \ No newline at end of file diff --git a/AR/05_addition/addition_with_carry.tex b/AR/05_addition/addition_with_carry.tex new file mode 100644 index 0000000..e612707 --- /dev/null +++ b/AR/05_addition/addition_with_carry.tex @@ -0,0 +1,125 @@ +\model{Addition with Carry} + + \quest{10 min} + + \Q Complete the decimal addition problem in the table below, then answer the following questions: + \vspace{10pt} + \begin{center} + \begin{tabular}{|c|c|c|} + \hline + & \ans[0.3in]{1} & \\ + \hline + & 2 & 6 \\ + \hline + + & 4 & 5 \\ + \hline + & \ans[0.3in]{7} & \ans[0.3in]{1} \\ + \hline + \end{tabular} + \end{center} + + \begin{enumerate} + \item What is the sum of 6 + 5 (answer after completing the table)? + \hfill\ans[1in]{11} + + \item How many digits are in that value? + \hfill\ans{2} + + \item Where did you put the least significant (right-most) digit? + \begin{answer}[0.5in] + {The ``ones'' go below as part of the sum.} + \end{answer} + + \item Where did you put the most significant (left-most) digit? + \begin{answer}[0.5in] + {The ``ten'' goes above the next column of digits to be included in the next set of additions.} + \end{answer} + + \item When you have a one that ``carries'' to the next column, how is it used? + \begin{answer}[0.5in] + It is just another number that is added to the other values in the column. + \end{answer} + + \item For the expression (9 + 8 + 7), do you add all three numbers at once or do you first add two of them and then add the third to the intermediate sum? + \begin{answer}[0.5in] + I only add two digits at a time; the third one is added to the intermediate sum. + \end{answer} + + \item When adding two N-digit numbers, what is the maximum number of digits for the sum? + \begin{answer}[0.5in] + N + 1 + \end{answer} + \end{enumerate} + + \newpage + + \Q The binary addition table (with four totals) is much simpler than the decimal addition table (with 100 totals). + \begin{enumerate} + \item Complete the left table below (labeled ``total'') with a two-digit sum in each of the empty cells. + \item Complete the ``sum'' table with the least-significant digit (right-most) from the first table. + \item Complete the ``carry'' table with the most-significant digit (left-most) from the first table. + \end{enumerate} + + \vspace{10pt} + \begin{center} + \begin{minipage}{0.3\textwidth} + \centering + \begin{tabular}{|c|c|c|} + \hline + \textbf{total} & $A = 0$ & $A = 1$ \\ + \hline + $B = 0$ & \ans[0.3in]{00} & \ans[0.3in]{01} \\ + \hline + $B = 1$ & \ans[0.3in]{01} & \ans[0.3in]{10} \\ + \hline + \end{tabular} + \end{minipage} + \hfill + \begin{minipage}{0.3\textwidth} + \centering + \begin{tabular}{|c|c|c|} + \hline + \textbf{sum} & $A = 0$ & $A = 1$ \\ + \hline + $B = 0$ & \ans[0.3in]{0} & \ans[0.3in]{1} \\ + \hline + $B = 1$ & \ans[0.3in]{1} & \ans[0.3in]{0} \\ + \hline + \end{tabular} + \end{minipage} + \hfill + \begin{minipage}{0.3\textwidth} + \centering + \begin{tabular}{|c|c|c|} + \hline + \textbf{carry} & $A = 0$ & $A = 1$ \\ + \hline + $B = 0$ & \ans[0.3in]{0} & \ans[0.3in]{0} \\ + \hline + $B = 1$ & \ans[0.3in]{0} & \ans[0.3in]{1} \\ + \hline + \end{tabular} + \end{minipage} + \end{center} + + \Q The truth tables below were developed in an earlier exercise.\key\\[-2.5mm] + \begin{enumerate} + \item Which one matches the sum table? + \hfill\ans{XOR} + + \item Which one matches the carry table? + \hfill\ans{AND} + \end{enumerate} + + \vspace{10pt} + \begin{center} + \begin{tabular}{|c|c|c||c|c|c||c|c||c|c|c||c|c|c||c|c|c|} + \hline + \textbf{AND} & 0 & 1 & \textbf{OR} & 0 & 1 & \textbf{NOT} & & \textbf{NAND} & 0 & 1 & \textbf{NOR} & 0 & 1 & \textbf{XOR} & 0 & 1 \\ + \hline + $B = 0$ & 0 & 0 & $B = 0$ & 0 & 1 & $B = 0$ & 1 & $B = 0$ & 1 & 1 & $B = 0$ & 1 & 0 & $B = 0$ & 0 & 1 \\ + \hline + $B = 1$ & 0 & 1 & $B = 1$ & 1 & 1 & $B = 1$ & 0 & $B = 1$ & 1 & 0 & $B = 1$ & 0 & 0 & $B = 1$ & 1 & 0 \\ + \hline + \end{tabular} + \end{center} \ No newline at end of file diff --git a/AR/05_addition/figures/3bit_adder.png b/AR/05_addition/figures/3bit_adder.png new file mode 100644 index 0000000..42d6bd4 Binary files /dev/null and b/AR/05_addition/figures/3bit_adder.png differ diff --git a/AR/05_addition/figures/3bit_adder_solution.png b/AR/05_addition/figures/3bit_adder_solution.png new file mode 100644 index 0000000..d7bb31b Binary files /dev/null and b/AR/05_addition/figures/3bit_adder_solution.png differ diff --git a/AR/05_addition/figures/adding_three_binary_digits.png b/AR/05_addition/figures/adding_three_binary_digits.png new file mode 100644 index 0000000..6e451d3 Binary files /dev/null and b/AR/05_addition/figures/adding_three_binary_digits.png differ diff --git a/AR/05_addition/figures/adding_three_binary_digits_solution.png b/AR/05_addition/figures/adding_three_binary_digits_solution.png new file mode 100644 index 0000000..04b4399 Binary files /dev/null and b/AR/05_addition/figures/adding_three_binary_digits_solution.png differ diff --git a/AR/05_addition/figures/adding_two_binary_digits.png b/AR/05_addition/figures/adding_two_binary_digits.png new file mode 100644 index 0000000..831587d Binary files /dev/null and b/AR/05_addition/figures/adding_two_binary_digits.png differ diff --git a/AR/05_addition/figures/adding_two_binary_digits_solution.png b/AR/05_addition/figures/adding_two_binary_digits_solution.png new file mode 100644 index 0000000..f86a6b8 Binary files /dev/null and b/AR/05_addition/figures/adding_two_binary_digits_solution.png differ diff --git a/AR/05_addition/figures/full_adders.png b/AR/05_addition/figures/full_adders.png new file mode 100644 index 0000000..05796b1 Binary files /dev/null and b/AR/05_addition/figures/full_adders.png differ diff --git a/AR/05_addition/figures/half_adder.png b/AR/05_addition/figures/half_adder.png new file mode 100644 index 0000000..61ba3ea Binary files /dev/null and b/AR/05_addition/figures/half_adder.png differ diff --git a/AR/05_addition/figures/logic_gate_outputs.png b/AR/05_addition/figures/logic_gate_outputs.png new file mode 100644 index 0000000..58b03c1 Binary files /dev/null and b/AR/05_addition/figures/logic_gate_outputs.png differ diff --git a/AR/05_addition/figures/logic_gate_outputs_solution.png b/AR/05_addition/figures/logic_gate_outputs_solution.png new file mode 100644 index 0000000..81b4c98 Binary files /dev/null and b/AR/05_addition/figures/logic_gate_outputs_solution.png differ diff --git a/AR/05_addition/figures/logic_gate_symbols.png b/AR/05_addition/figures/logic_gate_symbols.png new file mode 100644 index 0000000..0049a52 Binary files /dev/null and b/AR/05_addition/figures/logic_gate_symbols.png differ diff --git a/AR/05_addition/full_adder_circuit.tex b/AR/05_addition/full_adder_circuit.tex new file mode 100644 index 0000000..c6c6a47 --- /dev/null +++ b/AR/05_addition/full_adder_circuit.tex @@ -0,0 +1,93 @@ +\model{Digital Circuit for a Full Adder} + + \quest{15 min} + + \Q Add the binary numbers 110 + 011 in the table to the right (fill each of the non-shaded cells). (Hint: see question 2.) + \vspace{10pt} + \begin{center} + \begin{tabular}{|c|c|c|c|c|c|} + \hline + \rowcolor{gray!25} + \cellcolor{gray!25} & digit & 3 & 2 & 1 & 0 \\ + \hline + \cellcolor{gray!25} & \cellcolor{gray!25}carry & \ans[0.3in]{1} & \ans[0.3in]{1} & \ans[0.3in]{0} & \ans[0.3in]{0} \\ + \hline + \cellcolor{gray!25} & \cellcolor{gray!25}A & \cellcolor{gray!25}& 1 & 1 & 0 \\ + \hline + \cellcolor{gray!25}+ & \cellcolor{gray!25}B & \cellcolor{gray!25} & 0 & 1 & 1 \\ + \hline + \cellcolor{gray!25} & \cellcolor{gray!25}sum & \ans[0.3in]{1} & \ans[0.3in]{0} & \ans[0.3in]{0} & \ans[0.3in]{1} \\ + \hline + \end{tabular} + \end{center} + + \begin{enumerate} + \item What is the value for carry for digit 2 in this problem (the third column from the right)? Will it always be that even for other values of A \& B? + \begin{answer}[0.5in] + 1, no + \end{answer} + + \item What is the value for carry for digit 1 in this problem? Will it always be that even for other values of A \& B? + \begin{answer}[0.5in] + 0, no + \end{answer} + + \item What is the value for carry for digit 0 in this problem? Will it always be that even for other values of A \& B? + \begin{answer}[0.5in] + 0, yes + \end{answer} + + \item If we wanted the circuit for each column to be the same (simplicity/consistency), how many inputs (digits or bits) should we allow for each column? + \begin{answer}[0.5in] + three + \end{answer} + + \item How many outputs (digits or bits) should we allow for each column? + \hfill\ans[0.6in]{two} + + \item When adding digits, does the order matter? + \begin{answer}[0.75in] + Overall, we need to go right to left, but within a column order doesn't matter. + \end{answer} + \end{enumerate} + + \Q Follow the instructions below to create a Full Adder in Figure 5. + \vspace{10pt} + \begin{center} + \ifdefined\Teacher + \includegraphics[width=0.3\textwidth]{figures/adding_three_binary_digits_solution.png} + \else + \includegraphics[width=0.3\textwidth]{figures/adding_three_binary_digits.png} + \fi + \par\vspace{5pt} + {\small Figure 5: Adding Three Binary Digits} + \end{center} + + \begin{enumerate} + \item Label the three inputs (on the left of the figure) for carry, A, and B. (Hint: see question 7f.) + + \item How many outputs should we have? (Hint: see question 7e.) + \hfill\ans[1in]{two} + + \item What should the outputs be named? + \hfill\ans{sum \& carry} + + \item When adding two, one-bit values, will sum and carry ever both be one? (Hint: see question 2.) + \begin{answer}[0.5in] + no + \end{answer} + + \item If C = 1 on the left Half Adder, what is the value of S on the left one? + \hfill\ans[1in]{always 0} + + \item If S = 0 on the left Half Adder, what is the value of C on the right one? + \hfill\ans[1in]{always 0} + + \item Will both C values from the Half Adders in Figure 5 ever both be one?\key\\[-2.5mm] + \hfill\ans[1in]{no} + + \item Add the appropriate gate from Figure 1 on the right of Figure 5 to complete the circuit. + + \item Label the outputs. (Hint: try various inputs and see what outputs you get.) + + \end{enumerate} \ No newline at end of file diff --git a/AR/05_addition/half_adder_circuit.tex b/AR/05_addition/half_adder_circuit.tex new file mode 100644 index 0000000..5d319aa --- /dev/null +++ b/AR/05_addition/half_adder_circuit.tex @@ -0,0 +1,54 @@ + \model{Digital Circuit for a Half Adder} + + \quest{10 min} + + \Q The following symbols are used to represent digital logic circuits that produce the truth tables described above. + Based on your answer to question 3, label one of them sum and another one of them carry. + \vspace{10pt} + \begin{center} + \includegraphics[width=0.9\textwidth]{figures/logic_gate_symbols.png} + \par\vspace{5pt} + {\small Figure 1: Logic Gate Symbols} + \end{center} + \begin{answer}[0.5in] + CARRY\hfill SUM + \end{answer} + + \Q Complete Figure 2 by identifying the output value for each of the gates given the input values for A and B: + \vspace{10pt} + \begin{center} + \ifdefined\Teacher + \includegraphics[width=0.9\textwidth]{figures/logic_gate_outputs_solution.png} + \else + \includegraphics[width=0.9\textwidth]{figures/logic_gate_outputs.png} + \fi + \par\vspace{5pt} + {\small Figure 2: Logic Gate Outputs} + \end{center} + + \Q Follow the instructions in (a) and (b) below to complete the circuit diagram in Figure 3 so that it can add two binary digits A and B: + \begin{enumerate} + \item Connect A and B to the appropriate input lines on each of the two gates. (Hint: see question 5.) + \item Label the outputs sum and carry. (Hint: see question 4.) + \end{enumerate} + + \vspace{10pt} + \begin{center} + \ifdefined\Teacher + \includegraphics[width=0.3\textwidth]{figures/adding_two_binary_digits_solution.png} + \else + \includegraphics[width=0.3\textwidth]{figures/adding_two_binary_digits.png} + \fi + \par\vspace{5pt} + {\small Figure 3: Adding Two Binary Digits} + \end{center} + + \vspace{10pt} + A circuit that has two inputs and a sum and carry output is called a Half Adder and has a special symbol (Figure 4). + + \vspace{10pt} + \begin{center} + \includegraphics[width=0.2\textwidth]{figures/half_adder.png} + \par\vspace{5pt} + {\small Figure 4: Half Adder} + \end{center} diff --git a/AR/05_addition/multi_bit_adder.tex b/AR/05_addition/multi_bit_adder.tex new file mode 100644 index 0000000..3930a9f --- /dev/null +++ b/AR/05_addition/multi_bit_adder.tex @@ -0,0 +1,47 @@ +\model{Multi-Bit Adder} + + A circuit like the one built in question 8, that has three inputs and two outputs, a sum and carry, is called a Full Adder. + It can be represented with either of the images in Figure 6. The difference between them is whether then inputs and outputs are + on the left or right. While we have had inputs on the left so far, we will soon see how it may be convenient to have the inputs on the right. + + \vspace{10pt} + \begin{center} + \includegraphics[width=0.4\textwidth]{figures/full_adders.png} + \par\vspace{5pt} + {\small Figure 6: Full Adders} + \end{center} + + {\it\large Refer to Model 4 above as your team develops consensus answers + to the questions below.} + + \quest{15 min} + + \Q To add a pair of N-digit binary numbers, how many Full Adders do we need? (Hint:\key\\[-2.5mm] how many columns are we adding in question 7?) + \begin{answer}[0.5in] + N Full Adders, one for each column. + \end{answer} + + \Q Follow the instructions below to make a 3-Bit Adder in Figure 7 to add A + B. + \vspace{10pt} + \begin{center} + \ifdefined\Teacher + \includegraphics[width=0.7\textwidth]{figures/3bit_adder_solution.png} + \else + \includegraphics[width=0.7\textwidth]{figures/3bit_adder.png} + \fi + \par\vspace{5pt} + {\small Figure 7: 3-Bit Adder} + \end{center} + + \begin{enumerate} + \item Given that A is a three-bit number with the least-significant bit on the right (a0) and the most significant bit on the left (a2), + draw lines connecting each digit of A to the appropriate Full Adder. + + \item Draw lines connecting each digit of B to the appropriate Full Adder. + + \item Draw lines connecting the S output of each Full Adder to the appropriate output (s0-s2). + + \item Draw lines connecting the C output of each Full Adder to the appropriate place. + + \item Draw a component for the input for Cin on the least-significant Full Adder (at the right). (Hint: what is the value needed and what circuit element provides that value?) + \end{enumerate} diff --git a/AR/06_subtraction/06_subtraction.tex b/AR/06_subtraction/06_subtraction.tex new file mode 100644 index 0000000..a5db8a9 --- /dev/null +++ b/AR/06_subtraction/06_subtraction.tex @@ -0,0 +1,61 @@ +% Source: CPTR 280 Computer Organization and Assembly Language Fall 2021 +% File: "06 Subtraction (key).pdf" +% Author: James Foster, pogil@jgfoster.net + +% comment out for student version +% \ifdefined\Student\relax\else\def\Teacher{}\fi + +\documentclass[12pt]{article} + +\title{Activity 6: Subtraction} +\author{James Foster} +\newcommand{\activityeditor}{James Foster} +\newcommand{\activitysource}{\url{pogil@jgfoster.net}} +\date{Fall 2021} + +\input{../../cspogil.sty} +\usepackage{graphicx} +\usepackage{tabularx} + +\begin{document} + + \begin{center} + \maketitle + \rolenames + \end{center} + + \keyquestions{ + \item Model 1, Question \#2 + \item Model 2, Question \#7 + \item Model 3, Question \#12 + \item Model 3, Question \#16 + \item Model 4, Question \#21, a--c + } + + \newpage + \maketitle + + We said earlier that most math operations can be simplified to addition. In this lesson we will build on + earlier exercises dealing with binary and with digital logic gates to understand how computers do subtraction. + + \guides{ + \item Use nine's complement to subtract without borrowing; and, + \item Represent negative numbers in binary using two's complement. + }{ + \item Reflect on how what how the team could work and learn more effectively. + }{ + No additional notes + }{ + \item odometer \href{https://search.creativecommons.org/photos/57c70ba8-18f2-482a-87ab-285606463446}{link here} + \item clock: \url{https://pngio.com/images/png-a1553797.html} + } + + \input{subtraction_without_borrowing.tex} + \newpage + \input{wrap_around.tex} + \newpage + \input{negative_numbers.tex} + \newpage + \input{encoding_in_binary.tex} + +\end{document} \ No newline at end of file diff --git a/AR/06_subtraction/encoding_in_binary.tex b/AR/06_subtraction/encoding_in_binary.tex new file mode 100644 index 0000000..eb3f2e9 --- /dev/null +++ b/AR/06_subtraction/encoding_in_binary.tex @@ -0,0 +1,73 @@ +\model{Encoding in Binary} + + While we said that there isn't anything special about decimal (base ten), there is something special about binary: + it is the simplest number system possible and forms the foundation of all digital computers. Anything that can be mapped to + discrete values can be encoded in binary; the only requirement is that everyone who uses the code must understand the mapping.\\ + + {\it\large Refer to Model 4 above as your team develops consensus answers + to the questions below.} + + \quest{15 min} + + \Q ``Hang a lantern aloft in the belfry arch / Of the North Church tower as a special light, --- / One, if by land, and two. if by sea \ldots'' + Map Paul Revere's code to binary. + \vspace{10pt} + \begin{center} + \begin{tabular}{|c|l|} + \hline + \textbf{Code} & \textbf{Meaning} \\ + \hline + 00 & \ans[1in]{``no invasion''} \\ + \hline + 01 & \ans[1in]{``by land''} \\ + \hline + 10 & \ans[1in]{``by land''} \\ + \hline + 11 & ``by sea'' \\ + \hline + \end{tabular} + \end{center} + + \Q The WWU CS department has four professors, Preston Carman, James Foster, John Foster, and Natalie Smith-Gray. + Assign each a unique ID using just two bits. + \vspace{10pt} + \begin{center} + \begin{tabular}{|c|l|} + \hline + \textbf{Code} & \textbf{Professor} \\ + \hline + \ans[0.4in]{00} & Preston Carman \\ + \hline + \ans[0.4in]{01} & James Foster \\ + \hline + \ans[0.4in]{10} & John Foster \\ + \hline + \ans[0.4in]{11} & Natalie Smith-Gray \\ + \hline + \end{tabular} + \end{center} + + \Q How many bits would be required to encode the following:\key\\[-2.5mm] + \begin{enumerate} + \item The letter grades A, B, C, D, F? (Hint: not 5!) + \begin{answer}[0.5in] + 3 bits are needed to encode 5 values (2 bits give only 4 values) + \end{answer} + + \item The 30 students enrolled in CPTR 280? + \begin{answer}[0.5in] + 5 bits are needed to encode 30 values (4 bits give only 16 values) + \end{answer} + + \item All 34 students if we admitted everyone on the wait list? + \begin{answer}[0.5in] + 6 bits are needed to encode 34 values (5 bits give only 32 values) + \end{answer} + \end{enumerate} + + \vspace{-20pt} + + \Q If you were using four bits to represent a non-negative integer (to keep things simple), what is the range of numbers you could encode (that is, what would they convert to in decimal)? + \begin{answer}[0.5in] + 4 bits can represent 16 values, from 0 to 15 + \end{answer} \ No newline at end of file diff --git a/AR/06_subtraction/figures/clock.png b/AR/06_subtraction/figures/clock.png new file mode 100644 index 0000000..ad62ca1 Binary files /dev/null and b/AR/06_subtraction/figures/clock.png differ diff --git a/AR/06_subtraction/figures/odometer.png b/AR/06_subtraction/figures/odometer.png new file mode 100644 index 0000000..721b5a3 Binary files /dev/null and b/AR/06_subtraction/figures/odometer.png differ diff --git a/AR/06_subtraction/negative_numbers.tex b/AR/06_subtraction/negative_numbers.tex new file mode 100644 index 0000000..a7b4b82 --- /dev/null +++ b/AR/06_subtraction/negative_numbers.tex @@ -0,0 +1,160 @@ +\model{Negative Numbers} + + \quest{15 min} + + \Q Consider a traditional analog clock face. + \vspace{10pt} + \begin{center} + \includegraphics[width=0.25\textwidth]{figures/clock.png} + \end{center} + + \begin{enumerate} + \item How many unique hours can it represent? + \hfill\ans{12} + + \item What is the range of hours it represents? + \hfill\ans{1 to 12} + + \item If we think of 3:00 as ``three hours after noon'' (or ``+3''), what hour position on the clock is represented by ``three hours before noon'' (``-3'')? + \begin{answer}[0.5in] + 9 + \end{answer} + + \item What range of integers would support the same number of negative clock-face ``hours'' as nonnegative clock-face ``hours''? + \begin{answer}[0.5in] + -6 to +5 + \end{answer} + \end{enumerate} + + \vspace{-20pt} + + \Q Complete the following table to map the typical clock face hours (line 1) to the hours before and after noon (line 2). + (Hint: start at each end and work to the middle.) + \vspace{10pt} + \begin{center} + \begin{tabular}{|c|c|c|c|c|c|c|c|c|c|c|c|} + \hline + 12 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 \\ + \hline + \ans[0.3in]{0} & \ans[0.3in]{1} & \ans[0.3in]{2} & \ans[0.3in]{3} & \ans[0.3in]{4} & \ans[0.3in]{5} & \ans[0.3in]{-6} & \ans[0.3in]{-5} & \ans[0.3in]{-4} & \ans[0.3in]{-3} & \ans[0.3in]{-2} & \ans[0.3in]{-1} \\ + \hline + \end{tabular} + \end{center} + + \Q With this relabeled clock, answer the following questions: + \begin{enumerate} + \item If we start at 2 and add 2, what do we get? + \hfill\ans{+4} + + \item If we start at 2 and subtract 1, what do we get? + \hfill\ans{+1} + + \item If we start at 2 and subtract 2, what do we get? (Hint: not 12) + \hfill\ans[1.5in]{0} + + \item If we start at 2 and subtract 5, what do we get? + \hfill\ans{-3} + + \item If we start at -2 and subtract 2, what do we get? + \hfill\ans{-4} + + \item If we start at -2 and add 6, what do we get? + \hfill\ans{+4} + + \item So far this maps very nicely to ``normal'' arithmetic. But if we start at 5 and add 3, what do we get? (Hint: not 8!) + \begin{answer}[0.5in] + -4 + \end{answer} + + \item If we start at -5 and subtract 4, what do we get? (Hint: not -9!) + \hfill\ans[1.5in]{+3} + \end{enumerate} + + \Q Using a similar approach, fill in the following table to map selected unsigned values [0, 255] to signed values [-128, 127]. This is called a two's complement. + \vspace{10pt} + \begin{center} + \begin{tabular}{|c|c|c|c|c|c|c|c|c|c|c|c|} + \hline + 0 & 1 & 2 & \ldots & 126 & 127 & 128 & 129 & 130 & \ldots & 254 & 255 \\ + \hline + \ans[0.2in]{0} & \ans[0.2in]{1} & \ans[0.2in]{2} & \ldots & \ans[0.25in]{126} & \ans[0.25in]{127} & \ans[0.3in]{-128} & \ans[0.3in]{-127} & \ans[0.3in]{-126} & \ldots & \ans[0.2in]{-2} & \ans[0.2in]{-1} \\ + \hline + \end{tabular} + \end{center} + + \Q Convert some of these binary values to unsigned and signed decimal:\key\\[-2.5mm] + \vspace{10pt} + \begin{center} + \begin{tabular}{|c|c|c|} + \hline + \textbf{Binary} & \textbf{Unsigned Decimal} & \textbf{Signed Decimal} \\ + \hline + 0000 0000 & \ans[0.4in]{0} & \ans[0.4in]{0} \\ + \hline + 0000 0001 & \ans[0.4in]{1} & \ans[0.4in]{1} \\ + \hline + 0111 1110 & \ans[0.4in]{126} & \ans[0.4in]{126} \\ + \hline + 0111 1111 & \ans[0.4in]{127} & \ans[0.4in]{127} \\ + \hline + 1000 0000 & \ans[0.4in]{128} & \ans[0.4in]{-128} \\ + \hline + 1000 0001 & \ans[0.4in]{129} & \ans[0.4in]{-127} \\ + \hline + 1111 1110 & \ans[0.4in]{254} & \ans[0.4in]{-2} \\ + \hline + 1111 1111 & \ans[0.4in]{255} & \ans[0.4in]{-1} \\ + \hline + \end{tabular} + \end{center} + + \Q How does the high-order (left-most) bit correlate with the sign? + \hfill\ans[1.5in]{0 $\Rightarrow$ positive; 1 $\Rightarrow$ negative} + + \newpage + + \Q Perform some addition of signed binary numbers and note how the sign works: + \vspace{10pt} + \begin{center} + \begin{tabular}{|c|c|c|c|} + \hline + 11 & 0000 1011 & -118 & 1000 1010 \\ + + 5 & + 0000 0101 & + 44 & + 0010 1100 \\ + \hline + \ans[1in]{16} & \ans[1in]{0001 0000} & \ans[1in]{-74} & \ans[1in]{1011 0110} \\ + \hline + 106 & 0110 1010 & -22 & 1110 1010 \\ + + -63 & + 1100 0001 & + -86 & +1010 1010 \\ + \hline + \ans[1in]{43} & \ans[1in]{1 0010 1011} & \ans[1in]{-204} & \ans[1in]{1 1001 0100} \\ + \hline + \end{tabular} + \end{center} + + This suggests that another way to do subtraction is just to add the negative value. So how do we get a negative? Compare a few examples and + note that in each case, if you added the values you would get zeros in the right-most (low order) 8 bits (which is, of course, correct). + + \vspace{10pt} + \begin{center} + \begin{tabular}{ccc} + 1 = 0000 0001 & & -1 = 1111 1111 \\ + 2 = 0000 0010 & & -2 = 1111 1110 \\ + 126 = 0111 1110 & & -126 = 1000 0010 \\ + 127 = 0111 1111 & & -127 = 1000 0001 \\ + \end{tabular} + \end{center} + + \Q For each positive value above (1, 2, 126, and 127), write out its one's complement or inverse (replace 0 with 1, 1 with 0). + \vspace{10pt} + \begin{center} + \begin{tabular}{cccc} + \ans[1in]{1111 1110} & \ans[1in]{1111 1101} & \ans[1in]{1000 0001} & \ans[1in]{1000 0000} \\ + \end{tabular} + \end{center} + + \vspace{-20pt} + + \Q How does the inverse compare with the negative value? What would you add\key\\[-2.5mm] to the inverse to get the negative? Learn this useful rule for computing the negative of a number! + \begin{answer}[0.5in] + The inverse is one less than the negative. To get a negative, invert and add 1. + \end{answer} \ No newline at end of file diff --git a/AR/06_subtraction/subtraction_without_borrowing.tex b/AR/06_subtraction/subtraction_without_borrowing.tex new file mode 100644 index 0000000..20c19e6 --- /dev/null +++ b/AR/06_subtraction/subtraction_without_borrowing.tex @@ -0,0 +1,101 @@ +\model{Subtraction without Borrowing} + + \quest{10 min} + + \Q Complete the problem below. With subtraction, what complexity arises analogous to (but more difficult than) the carry step in addition? + \vspace{10pt} + \begin{center} + \begin{tabular}{|c|c|c|c|} + \hline + & \ans[0.3in]{1} & \ans[0.3in]{14} & \\ + \hline + & 2 & 5 & 3 \\ + \hline + - & 1 & 7 & 6 \\ + \hline + & & \ans[0.3in]{7} & \ans[0.3in]{7} \\ + \hline + \end{tabular} + \end{center} + \begin{answer}[0.75in] + Borrowing. + \end{answer} + + \Q Given the expression $x - y$ (where $y$ is no more than three digits), what decimal va-\key\\[-2.5mm]lue for $x$ will guarantee that you never have to borrow? + \begin{answer}[0.25in] + All nines (999) + \end{answer} + + \Q To avoid borrowing, we can use algebra to rewrite $x - y$ as follows: + \vspace{5pt} + \begin{center} + \begin{align*} + x - y &= x - y + 0 \\ + &= x - y + (1000 - 1000) \\ + &= x - y + (999 + 1 - 1000) \\ + &= x + (999 - y) + 1 - 1000 \\ + &= (999 - y) + x + 1 - 1000 + \end{align*} + \end{center} + + Complete the problems in the table below and confirm that the result is the same. + + \vspace{10pt} + \begin{center} + \begin{tabular}{|c|c|c|c|c|} + \hline + & & 9 & 9 & 9 \\ + \hline + - & & 1 & 7 & 6 \\ + \hline + & \ans[0.3in]{} & \ans[0.3in]{8} & \ans[0.3in]{2} & \ans[0.3in]{3} \\ + \hline + + & & 2 & 5 & 3 \\ + \hline + & \ans[0.3in]{1} & \ans[0.3in]{0} & \ans[0.3in]{7} & \ans[0.3in]{6} \\ + \hline + + & & & & 1 \\ + \hline + & \ans[0.3in]{1} & \ans[0.3in]{0} & \ans[0.3in]{7} & \ans[0.3in]{7} \\ + \hline + - & 1 & 0 & 0 & 0 \\ + \hline + & & & \ans[0.3in]{7} & \ans[0.3in]{7} \\ + \hline + \end{tabular} + \end{center} + + \vspace{10pt} + The result of subtracting a number from nines gives us a nines' complement. Note that while the word \textit{compliment} means to say something nice, + the word \textit{complement} means ``a thing that completes.'' Adding a number and its nines' complement gives us all (or just) nines. + + \Q Of course, in a computer with digital logic we will be using binary instead of decimal. Given the expression $x - y$ (where $y$ is no more than 8 digits), what binary value for $x$ will guarantee that you never have to borrow? + \begin{answer}[0.5in] + 1111 1111 + \end{answer} + + \Q Complete the binary subtraction problem below. + \vspace{10pt} + \begin{center} + \begin{tabular}{|c|c|c|} + \hline + & 1 & 1 \\ + \hline + - & 1 & 0 \\ + \hline + & \ans[0.3in]{0} & \ans[0.3in]{1} \\ + \hline + \end{tabular} + \end{center} + + \begin{enumerate} + \item What pattern do you notice when you compare the bits in rows 2 and 3 column by column (the subtrahend and the difference)? + \begin{answer}[0.5in] + They are inverse (opposite). + \end{answer} + + \item With respect to each column, which truth table takes one input (from line 2) and gives one output (line 3)? + \begin{answer}[0.5in] + NOT + \end{answer} + \end{enumerate} \ No newline at end of file diff --git a/AR/06_subtraction/wrap_around.tex b/AR/06_subtraction/wrap_around.tex new file mode 100644 index 0000000..9259d3a --- /dev/null +++ b/AR/06_subtraction/wrap_around.tex @@ -0,0 +1,79 @@ +\model{Wrap-Around} + + \quest{10 min} + + \Q Consider an odometer with only five digits (left of the decimal). + \vspace{10pt} + \begin{center} + \includegraphics[width=0.35\textwidth]{figures/odometer.png} + \end{center} + + \begin{enumerate} + \item If it reads 99999 and you add one mile, what will it show? + \begin{answer}[0.5in] + 00000 + \end{answer} + + \item If you have a limited number of digits, is there a way to avoid this wrap-around? + \begin{answer}[0.5in] + No, it will always happen eventually. + \end{answer} + \end{enumerate} + + \vspace{-20pt} + + \Q Consider a binary value with eight bits.\key\\[-2.5mm] + \begin{enumerate} + \item How many unique values could you represent (the count, not a formula)? + \begin{answer}[0.3in] + 256 + \end{answer} + + \item If you chose to represent only non-negative integers, what would be the range of unsigned integers (converted to decimal)? + \begin{answer}[0.3in] + 0 to 255 + \end{answer} + + \item If you added one to the maximum value, what would you get? + \begin{answer}[0.3in] + 0 + \end{answer} + + \item If you subtracted one from the minimum value, what would you get? + \begin{answer}[0.3in] + 255 + \end{answer} + + \item If you used one bit for a sign (indicating positive or negative), how many bits would be left for the number? + \begin{answer}[0.3in] + Seven (7) + \end{answer} + + \item How many values could be represented using the remaining bits? + \begin{answer}[0.3in] + 128 values + \end{answer} + + \item What is the range of unsigned integers you could represent in the remaining bits? + \begin{answer}[0.3in] + 0 to 127 + \end{answer} + + \item What would be the range of signed integers you could represent with a single sign bit and seven value bits? + \begin{answer}[0.3in] + -127 to +127 + \end{answer} + + \item How many unique values does that represent? + \begin{answer}[0.3in] + 255 values + \end{answer} + + \item Are there any missing values? If so, where did they go? + \begin{answer}[0.3in] + We have a representation for both +0 and -0, and we should not need both. + \end{answer} + \end{enumerate} + + Next, we will consider another approach to representing negative numbers that allows us to store the maximum number of values and allows + adding negative numbers without any special work. \ No newline at end of file