Chapter 4 Hardware Basics We assume that a computing agent will exe- cute all the algorithms we have been discussing. Now, we will see how this agent looks like and how it is able to execute those algorithms. We will first look at the very basics, such as how to represent data, how to follow the logic principles to design gates, and how to combine gates to construct logic circuits that manipu- late data. This part is called hardware design or logic design. 1
37
Embed
Chapter 4 Hardware Basics - Plymouth State Universityturing.plymouth.edu/~zshen/Webfiles/notes/CS201/note4.pdf · Chapter 4 Hardware Basics We assume that a computing agent will exe-cute
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Generally speaking, any whole number can berepresented in this “base-2” representation.
Homework: Exercises 1–6.4
Representing fractions
Decimal numbers, such as 12.34 and -43.21,
can also be represented in the binary system,
by first converting them into the scientific sys-
tem: ±M × B±E, where M is the mantissa, B
is the base, and E is the exponent.
For example,
(5.75)10 = 4 + 1 + 0.5 + 0.25
= 1 × 22 + 0 × 21 + 1 × 20
+1 × 2−1 + 1 × 2−2
= (101.11)2.
Homework: Exercises 7.
5
A couple of notes
1. As computer is a finite device, there is a
maximal number of binary digits that can be
used to store digits, e.g., 16, 32, or 64. Once
this number is fixed, the maximal integer that
can be represented is also fixed. For example,
for a 16 bit machine, the maximum integer is
216 = 65,535. Any operation in this machine
that produces a larger integer will lead to an
overflow error.
2. Binary system can be used to represent
other things as well. For example, to represent
a signed number, we can use the leftmost bit
to represent the sign, 0 for ‘+’, and 1 for ‘-’.
Hence, -49 and 3 will be represented, respec-
tively, as (1110001) and (0000011), assuming
we use 7 digits.
Homework: Exercise 8.6
Moreover, we can also use it represent textinformation. There is no the way to do so, wejust assign a binary number, usually with 8 bits,to every text symbol we want to represent.ASCII is the most widely used representationschema. For example,
tion, such as sound and image, is based on thedigitization of those information.
For example, given a B/W picture, we can putit in a grid to convert it into a bunch of pixels,namely, elements of picture. We then assign
either a 1 or 0 to each pixel, depending on ifthat picture is black or white. For a color pic-
ture, besides identifying the position, we alsoneed to assign its share in three of the basic
colors: red, blue, and green, each of which istypically represented using a byte (8 bits).
Hence, a picture taken with a 3 MegaPixel digi-
tal camera using 24 bit color occupies 72 Megabits.
Homework: Complete §4.2.2 and completeExercises 10 and 11.
9
Data compression
Since the information storage needs so muchspace, the subject of data compression be-comes really important. A simple compressiontechnique is run-length encoding, which re-places a sequence of identical values v1, v2, · · · , vn
with a pair (v, n). If each v and n requires 1byte, then the total number of bytes will bereduced from n to 2, if n ≥ 2. For example,the following data
255 255 255255 0 0255 255 255255 0 0255 255 255
can be represented as the following list:
(255, 4) (0, 2) (255, 4) (0, 2) (255, 3), thusreducing the total bytes from 15 to 10, a ratioof 15/10=1.5.
10
Variable length code
In ASCII code, every character is coded in 8
bits. So, if we have a text file with 1,000 char-
acters, we have to use 8,000 bits to store it.
In reality, some characters are used more often
than the others (Think about Wheel of For-
tune). It makes sense to assign shorter codes
to those used more often, and longer codes to
those used less often. The question is how?
One approach is to assign code to symbols
based on their frequencies. For example, in
the string aaxuaxz, the frequency of a, x, u
and z are 3, 2, 1 and 1. When frequency
varies a great deal, it makes sense to assign
shortest code to the most frequently occurring
one, while assigns longest code to the least fre-
quently occurring symbol.
11
For the above example, we can assign the codesas follows: 0=a, 10=x, 110=u, 111=z). Hence,aaxuaxz will be coded as 0010110010111. Thelength is 13 bits, compared with 14, if we giveeach of them two bits. On the other hand, ifthe frequency of the four symbols are (996, 2,1, 1), then the 2 bits per code method, for a1,000 character file will lead to 2,000 bits long,while our code will lead to a file of only 1,006bits, a ratio of almost 2.
How could we decode? For 0010110010111,since we have no code ”00”, the first piece ofcode must be ”0”, which is an ’a’, the nextis also ’a’. As we do have a code ”10”, weread off an ’x’, etc.. So, we always read offthe longest possible piece from the undecodedstring. The reason that this method worksis because this is a prefix code, i.e., no codeis a prefix of another. Such a code is calledHuffman code.
Homework: Exercises 12 and 13.12
Why binary?
There is absolutely no theoretical reason why
we can’t build up a base-10 computer, or a
computer based on any notation system. The
use of binary system is wholly a reliability con-
cern.
The computer is an electronic equipment so
that the internal representation must be based
on such quantities as currents or voltages. As
a result, we must, say the least, use 10 dif-
ferent voltages to represent the 10 digits. For
example, 0v for 0, 5v for 1, 10v for 2, · · · , 45v
for 9. So, to represent 28, we uses two de-
vices, one is charged to 10v, and the other to
40v.
The problem is that voltages are not stable.
When the voltage of the second drops to 37.5,
what number does it represent?
13
The trouble is that in representing a base-10
system, we need 10 stable states. Such a sys-
tem is difficult to come by. On the other hand,
an electrical system works best in a bi-stable
environment, where there are only 2 states,
separated by “huge” energy gap. For example,
on-off, fully charged-fully discharged, charged
positively-charged negatively, etc.
In such a system, there are two stable states.
We can let one, e.g., 0v, represent the digit
0, the other, e.g., 45v, represent the digit 1.
Now, a mere 10% voltage change would not
cause any problem.
The use of the binary system for the internal
data representation significantly increases the
inherent reliability of modern computer.
14
Binary storage devices
combined with our earlier results, we know that
any information can be represented by using bi-
stable devices that 1) has two stable states; 2)
it is possible to know what state the device is
in; and 3) it is possible to switch the device
from one state to the other.
There are many such devices, such as light
switch. Thus, at least theoretically, we can
build a computer out of a bunch of light switches.
Modern computers are built on such other much
smaller, more efficient, and stable devices. We
discuss two of them: magnetic core and tran-
sistor.
15
Magnetic core
This type of device was used to construct com-
puter memories, roughly from 1955 to 1975.
It is a small magnetizable iron oxide-coated
“doughnut”, about 1/50 of an inch in its di-
ameter, with one or more wires through its
center hole. If electric current is sent through
the wire in specific way, the core will be mag-
netized in one of two ways, to represent 0 or
1.
Since magnetic fields do not change much over
time, this device is very stable.
16
Transistors
Today, transistor is the building block for com-puter memories. It is simply a tiny switch. But,it has no mechanical or moving parts. Theswitching is done electronically, rather thanmechanically. This allows it to be extremelyfast as well as small. It can be switched inabout 10-20 billions of a second, while severalmillions of transistors can fit in a space onecentimeter square.
Constructed from semi-conductor material, tran-sistors, together with some connecting wires,can be printed photographically on a layer ofsilicon to produce integrated circuits (chips),which will be used as functional parts inside acomputer.
Photographic techniques, such as VLSI andULSI, allow us to produce chip with billionsof transistor/cm2, which leads to smaller andfaster computers.
17
Boolean logic and gates
The construction of chips is based on Boolean
logic, which makes operations in base-2 possi-
ble. This logic has two variables, T(rue) and
F(alse.) Interpreting 0 as F and 1 as T, the re-
lationship between this logic and binary system
is immediately established.
There are three operations, AND(∧), OR(∨)
and NOT(¬), in Boolean logic. A Boolean
expression is essentially a combination of those
operation applied on boolean variables. For
example, (a ∧ b) ∨ ¬c is a boolean expression.
18
Boolean operations
Let a and b be two Boolean expression. Then
a∧b is true iff both a and b are true, a∨b is true
iff at least one of a and b is true, ¬a is true iff a
is false. These rules can be demonstrated with
the following truth tables, when true and false
are represented with 1, and 0, respectively.
Homework: Exercises 15 and 16.
19
Gates
A gate is an electronic device that operates ona collection of binary inputs to produce a binaryoutput. Although there are a wide range ofgates, we only consider those that implementthe three Boolean operations, as they are theonly things we need.
Below show the implementation of OR gate,one of the three basic ones, by using transis-tors.
20
Building circuits
A (combinational) circuit is a collection of (AND,