Skip to content

Commit bc765e8

Browse files
committed
Chapter 6
1 parent a95d1aa commit bc765e8

7 files changed

Lines changed: 474 additions & 0 deletions

File tree

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
% Source: CPTR 280 Computer Organization and Assembly Language Fall 2021
2+
% File: "06 Subtraction (key).pdf"
3+
% Author: James Foster, pogil@jgfoster.net
4+
5+
% comment out for student version
6+
% \ifdefined\Student\relax\else\def\Teacher{}\fi
7+
8+
\documentclass[12pt]{article}
9+
10+
\title{Activity 6: Subtraction}
11+
\author{James Foster}
12+
\newcommand{\activityeditor}{James Foster}
13+
\newcommand{\activitysource}{\url{pogil@jgfoster.net}}
14+
\date{Fall 2021}
15+
16+
\input{../../cspogil.sty}
17+
\usepackage{graphicx}
18+
\usepackage{tabularx}
19+
20+
\begin{document}
21+
22+
\begin{center}
23+
\maketitle
24+
\rolenames
25+
\end{center}
26+
27+
\keyquestions{
28+
\item Model 1, Question \#2
29+
\item Model 2, Question \#7
30+
\item Model 3, Question \#12
31+
\item Model 3, Question \#16
32+
\item Model 4, Question \#21, a--c
33+
}
34+
35+
\newpage
36+
\maketitle
37+
38+
We said earlier that most math operations can be simplified to addition. In this lesson we will build on
39+
earlier exercises dealing with binary and with digital logic gates to understand how computers do subtraction.
40+
41+
\guides{
42+
\item Use nine's complement to subtract without borrowing; and,
43+
\item Represent negative numbers in binary using two's complement.
44+
}{
45+
\item Reflect on how what how the team could work and learn more effectively.
46+
}{
47+
No additional notes
48+
}{
49+
\item odometer \href{https://search.creativecommons.org/photos/57c70ba8-18f2-482a-87ab-285606463446}{link here}
50+
\item clock: \url{https://pngio.com/images/png-a1553797.html}
51+
}
52+
53+
\input{subtraction_without_borrowing.tex}
54+
\newpage
55+
\input{wrap_around.tex}
56+
\newpage
57+
\input{negative_numbers.tex}
58+
\newpage
59+
\input{encoding_in_binary.tex}
60+
61+
\end{document}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
\model{Encoding in Binary}
2+
3+
While we said that there isn't anything special about decimal (base ten), there is something special about binary:
4+
it is the simplest number system possible and forms the foundation of all digital computers. Anything that can be mapped to
5+
discrete values can be encoded in binary; the only requirement is that everyone who uses the code must understand the mapping.\\
6+
7+
{\it\large Refer to Model 4 above as your team develops consensus answers
8+
to the questions below.}
9+
10+
\quest{15 min}
11+
12+
\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''
13+
Map Paul Revere's code to binary.
14+
\vspace{10pt}
15+
\begin{center}
16+
\begin{tabular}{|c|l|}
17+
\hline
18+
\textbf{Code} & \textbf{Meaning} \\
19+
\hline
20+
00 & \ans[1in]{``no invasion''} \\
21+
\hline
22+
01 & \ans[1in]{``by land''} \\
23+
\hline
24+
10 & \ans[1in]{``by land''} \\
25+
\hline
26+
11 & ``by sea'' \\
27+
\hline
28+
\end{tabular}
29+
\end{center}
30+
31+
\Q The WWU CS department has four professors, Preston Carman, James Foster, John Foster, and Natalie Smith-Gray.
32+
Assign each a unique ID using just two bits.
33+
\vspace{10pt}
34+
\begin{center}
35+
\begin{tabular}{|c|l|}
36+
\hline
37+
\textbf{Code} & \textbf{Professor} \\
38+
\hline
39+
\ans[0.4in]{00} & Preston Carman \\
40+
\hline
41+
\ans[0.4in]{01} & James Foster \\
42+
\hline
43+
\ans[0.4in]{10} & John Foster \\
44+
\hline
45+
\ans[0.4in]{11} & Natalie Smith-Gray \\
46+
\hline
47+
\end{tabular}
48+
\end{center}
49+
50+
\Q How many bits would be required to encode the following:\key\\[-2.5mm]
51+
\begin{enumerate}
52+
\item The letter grades A, B, C, D, F? (Hint: not 5!)
53+
\begin{answer}[0.5in]
54+
3 bits are needed to encode 5 values (2 bits give only 4 values)
55+
\end{answer}
56+
57+
\item The 30 students enrolled in CPTR 280?
58+
\begin{answer}[0.5in]
59+
5 bits are needed to encode 30 values (4 bits give only 16 values)
60+
\end{answer}
61+
62+
\item All 34 students if we admitted everyone on the wait list?
63+
\begin{answer}[0.5in]
64+
6 bits are needed to encode 34 values (5 bits give only 32 values)
65+
\end{answer}
66+
\end{enumerate}
67+
68+
\vspace{-20pt}
69+
70+
\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)?
71+
\begin{answer}[0.5in]
72+
4 bits can represent 16 values, from 0 to 15
73+
\end{answer}
248 KB
Loading
338 KB
Loading
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
\model{Negative Numbers}
2+
3+
\quest{15 min}
4+
5+
\Q Consider a traditional analog clock face.
6+
\vspace{10pt}
7+
\begin{center}
8+
\includegraphics[width=0.25\textwidth]{figures/clock.png}
9+
\end{center}
10+
11+
\begin{enumerate}
12+
\item How many unique hours can it represent?
13+
\hfill\ans{12}
14+
15+
\item What is the range of hours it represents?
16+
\hfill\ans{1 to 12}
17+
18+
\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'')?
19+
\begin{answer}[0.5in]
20+
9
21+
\end{answer}
22+
23+
\item What range of integers would support the same number of negative clock-face ``hours'' as nonnegative clock-face ``hours''?
24+
\begin{answer}[0.5in]
25+
-6 to +5
26+
\end{answer}
27+
\end{enumerate}
28+
29+
\vspace{-20pt}
30+
31+
\Q Complete the following table to map the typical clock face hours (line 1) to the hours before and after noon (line 2).
32+
(Hint: start at each end and work to the middle.)
33+
\vspace{10pt}
34+
\begin{center}
35+
\begin{tabular}{|c|c|c|c|c|c|c|c|c|c|c|c|}
36+
\hline
37+
12 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 \\
38+
\hline
39+
\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} \\
40+
\hline
41+
\end{tabular}
42+
\end{center}
43+
44+
\Q With this relabeled clock, answer the following questions:
45+
\begin{enumerate}
46+
\item If we start at 2 and add 2, what do we get?
47+
\hfill\ans{+4}
48+
49+
\item If we start at 2 and subtract 1, what do we get?
50+
\hfill\ans{+1}
51+
52+
\item If we start at 2 and subtract 2, what do we get? (Hint: not 12)
53+
\hfill\ans[1.5in]{0}
54+
55+
\item If we start at 2 and subtract 5, what do we get?
56+
\hfill\ans{-3}
57+
58+
\item If we start at -2 and subtract 2, what do we get?
59+
\hfill\ans{-4}
60+
61+
\item If we start at -2 and add 6, what do we get?
62+
\hfill\ans{+4}
63+
64+
\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!)
65+
\begin{answer}[0.5in]
66+
-4
67+
\end{answer}
68+
69+
\item If we start at -5 and subtract 4, what do we get? (Hint: not -9!)
70+
\hfill\ans[1.5in]{+3}
71+
\end{enumerate}
72+
73+
\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.
74+
\vspace{10pt}
75+
\begin{center}
76+
\begin{tabular}{|c|c|c|c|c|c|c|c|c|c|c|c|}
77+
\hline
78+
0 & 1 & 2 & \ldots & 126 & 127 & 128 & 129 & 130 & \ldots & 254 & 255 \\
79+
\hline
80+
\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} \\
81+
\hline
82+
\end{tabular}
83+
\end{center}
84+
85+
\Q Convert some of these binary values to unsigned and signed decimal:\key\\[-2.5mm]
86+
\vspace{10pt}
87+
\begin{center}
88+
\begin{tabular}{|c|c|c|}
89+
\hline
90+
\textbf{Binary} & \textbf{Unsigned Decimal} & \textbf{Signed Decimal} \\
91+
\hline
92+
0000 0000 & \ans[0.4in]{0} & \ans[0.4in]{0} \\
93+
\hline
94+
0000 0001 & \ans[0.4in]{1} & \ans[0.4in]{1} \\
95+
\hline
96+
0111 1110 & \ans[0.4in]{126} & \ans[0.4in]{126} \\
97+
\hline
98+
0111 1111 & \ans[0.4in]{127} & \ans[0.4in]{127} \\
99+
\hline
100+
1000 0000 & \ans[0.4in]{128} & \ans[0.4in]{-128} \\
101+
\hline
102+
1000 0001 & \ans[0.4in]{129} & \ans[0.4in]{-127} \\
103+
\hline
104+
1111 1110 & \ans[0.4in]{254} & \ans[0.4in]{-2} \\
105+
\hline
106+
1111 1111 & \ans[0.4in]{255} & \ans[0.4in]{-1} \\
107+
\hline
108+
\end{tabular}
109+
\end{center}
110+
111+
\Q How does the high-order (left-most) bit correlate with the sign?
112+
\hfill\ans[1.5in]{0 $\Rightarrow$ positive; 1 $\Rightarrow$ negative}
113+
114+
\newpage
115+
116+
\Q Perform some addition of signed binary numbers and note how the sign works:
117+
\vspace{10pt}
118+
\begin{center}
119+
\begin{tabular}{|c|c|c|c|}
120+
\hline
121+
11 & 0000 1011 & -118 & 1000 1010 \\
122+
+ 5 & + 0000 0101 & + 44 & + 0010 1100 \\
123+
\hline
124+
\ans[1in]{16} & \ans[1in]{0001 0000} & \ans[1in]{-74} & \ans[1in]{1011 0110} \\
125+
\hline
126+
106 & 0110 1010 & -22 & 1110 1010 \\
127+
+ -63 & + 1100 0001 & + -86 & +1010 1010 \\
128+
\hline
129+
\ans[1in]{43} & \ans[1in]{1 0010 1011} & \ans[1in]{-204} & \ans[1in]{1 1001 0100} \\
130+
\hline
131+
\end{tabular}
132+
\end{center}
133+
134+
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
135+
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).
136+
137+
\vspace{10pt}
138+
\begin{center}
139+
\begin{tabular}{ccc}
140+
1 = 0000 0001 & & -1 = 1111 1111 \\
141+
2 = 0000 0010 & & -2 = 1111 1110 \\
142+
126 = 0111 1110 & & -126 = 1000 0010 \\
143+
127 = 0111 1111 & & -127 = 1000 0001 \\
144+
\end{tabular}
145+
\end{center}
146+
147+
\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).
148+
\vspace{10pt}
149+
\begin{center}
150+
\begin{tabular}{cccc}
151+
\ans[1in]{1111 1110} & \ans[1in]{1111 1101} & \ans[1in]{1000 0001} & \ans[1in]{1000 0000} \\
152+
\end{tabular}
153+
\end{center}
154+
155+
\vspace{-20pt}
156+
157+
\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!
158+
\begin{answer}[0.5in]
159+
The inverse is one less than the negative. To get a negative, invert and add 1.
160+
\end{answer}

0 commit comments

Comments
 (0)