Sie sind auf Seite 1von 21

CHAPTERO

INTRODUCTION TO
COMPUTING

OBJECTIVES

Upon completion of this chapter, you wiJJ be able to:

>> Convert any number from base 2, base 10, or base 16 to either of the
other two bases
>> Add and subtract hex numbers
>> Add binary numbers
>> Represent any binary number in 2's complement
>> Represent an alphanumeric string in ASCII code
>> Describe logical operations AND, OR, NOT, XOR, NAND, NOR
>> Use logic gates to diagram simple circuits
>> Explain the difference between a bit, a nibble, a byte, and a word
>> Give precise mathematical definitions of the terms kilobyte, megabyte,
gigabyte, and terabyte
>> Explain the difference between RAM and ROM and describe their use
>> Describe the purpose of the major components of a computer system
>> List the three types of buses found in computers and describe the
purpose of each type of bus
>> Describe the role of the CPU in computer systems
>> List the maj or components of the CPU and describe the purpose of each
.. f. 11, icrocontrollcr-based system, one
In unckrsland rhc soliwarc and hardware O .i ..
1n t h'1s chapter
• • inputer design.
lllli~t I 1rst 111ash:r some very basic concepts under 1ymg co f
(" ·Ill·l:-I1 111
· •. . . . · . , 11 d Cl1 pter 0) the fundamenta Is o num-
the trad1t1011 ol d1g1tal computers 1s Cd e a ' . .
' ·
bl:nng · d t'10n to logic gates, an overview
and coding systems arc presented. After an mtro uc . . .
. I · . ·
0 I t le workings inside the computer 1s given. Fma Y, 111 1
· II · ti e last section we give a bnef
.
··
I11st · d h ve an adequate background 111
ory of CPU architecture. Although some rea ers may a .
Illany ot. tI1c topics · of· this· chapter, 1t
· 1·s recommended that the material be scanned, how-
ever brie11y.

SECTION 0.1: NUMBERING AND CODING SYSTEMS

Whereas human beings use base IO (decimal) arithmetic, compute~s use the base
2 (bina,y ) system. ln this section we explain how to convert from the ~ectmal syS tem ~o
the binary system, and vice versa. The convenient representation of binary numbers m
base 16, called hexadecimal, also is covered. Finally, the binary format of the alphanumer-
ic code, called ASCII, is explored.

Decimal and binary number systems


Although there has been speculation that the origin of the base l O system is the
fact that human beings have IO fingers, there is absolutely no speculation about the rea-
son behind the use of the binary system in computers. The binary system is used in com-
puters because I and Orepresent the two voltage levels of on and off Whereas in base I0
there are IO distinct symbols, O, 1, 2, ... , 9, in base 2 there are only two, 0 and l, with
which to generate numbers. Base 1Ocontains digits Othrough 9; binary contains digits 0
and I only. These two binary digits, Oand 1, are commonly referred to as bits.

Converting from decimal to binary


One method of converting from decimal to binary is to divide the decimal num-
ber by 2 repeatedly, keeping track of the remainders. This process continues until the quo-
tient becomes zero. The remainders are then written in reverse order to obtain the binary
number. This is demonstrated in Example 0- 1.

Example 0-1
Convert 251o to binary.

Solution:
Quo ti ent Remai nder
25/2 = 12 1 LSB (leas t sign i f ica nt bit )
12/2 = 6 0
6/2 = 3 0
3/2 = 1 1
1 /2 = 0 1 MSB (mos t s igni fica nt bit )

Therefore, 25 10 = 1100 l 2.
Converting from binary to decimal
740 683 10 =
To convert from binary to decimal, it is impor-
tant to understand th e concept of wei ght associated 3 X 10 ° 3
with each digit positi on. Fi rst, as an unalogy, recall the 8 X 10 1 80
weight or numbers in th1.: base IO system , as sh own in 6 X 1 02 600
the diagra m. By the same token, each digit position in 0 X 10 3 00 00
a number in base 2 has a weight assoc ia ted with it: 4 X 104 40 000
7 X 1 05 700000
740683

11 01 012 Deci mal Binary


lx 20 l xl 1 1
Ox 2 1 Ox2 0 00
lx 2 2 = l x4 = 4 1 00
Ox 2 3 Ox 8 0 00 00
l x24 l xl 6 16 1 000 0
l x2 5 lx 32 32 10000 0
53 11010 1

Knowing the weight of each bit in a binary number makes it simple to add them
together to get its decimal equivalent, as shown in Example 0-2.

Example 0-2
Convert 11001 2 to de~imal.

Solution :
Weight: 16 8 4 2
Digits: ~ .l 0 0
Sum: , 1v , )8 + 0+ 0+ 1 =25 10

Knowing the -:Jght associated with each binary· bit position allows one to con-
vert a decimal number/a.binary directly instead of going through the process of repeated
division. This is shown in Exampl e 0-3 .

Example 0-3
Use the concept of weight to convert 39 Io to binary.

Solution :
Weight: 32 16 8 4 2
0 0 I
32 + 0+ 0+ .4 + 2+ l = 39
Therefore, 39 10 = 1001 11 2.

CHAPTER 0: INTROD UCT ION TO COMPUTING 3


Table 0-1: Base 16
Hexadecimal system
l3ase 16. or the hexadecimal system as it is called in ~om-
Number Systems
Decimal Binary
-
Hex
putcr literature. is used as a convenient representation of bmary
0 0000 0
numbers. For example, it is much easier for a human being to
represent a string of Os and \ s such as l 000 l 00 IO 110 as its hexa- 1 000 \
decimal equivalent of 896H. The binary system has 2 digits, 0 2 0010 2
and l. The base l Osystem has l O digits, 0 through 9. The hexa- 3 00 11 3
decimal (base 16) system has 16 digits. In base 16, the first 10 4 0100 4
digits, 0 to 9, are the same as in decimal, and for the remaining 5 0101 5
six digits, the letters A. B, C, D, E, and F are used. Table 0-1 0110 6
6
shows the equivalent binary, decimal, and hexadecimal represen- 01 11 7
7
tations for Oto 15.
8 1000 8
Converting between binary and hex 9 1001 9
10 1010 A
To represent a binary number as its equivalent hexadeci-
1011 B
~al number, start from the right and group 4 bits at a time, replac- 11
ing each 4-bit binary nu~ber with its hex equivalent shown in 12
1100 C
Table 0-1. To convert from hex to binary, each hex digit is 13 1101 D
replaced with its 4-bit binary equivalent. See Examples 0-4 and 14 1110 E
0-5. 15 1111 F

Example 0-4
Represent binary 100111110 l O1 in hex.

Solution:
First the number is grouped into sets of 4 bits: 1001 1111 OlO 1.
Then each group of 4 bits is replaced with its hex equivalent:
1001 111 1 0101
9 F 5
Therefore, l 001 11110 l O12 = 9F5 hexadecimal.

Example 0-5
Convert hex 29B to binary.

Solution:
2 9 B
= 0010 1001 l O11
Dropping the leading zeros gives 10l00 110 l l.

Converting from decimal to hex


Converting from decimal to hex could be approached in two ways:
1. Convert to binary first and then convert to hex. Example 0-6 shows this

____________________
method of converting decimal to hex.
2. Convert directly from decimal to hex by repeated division, keeping track of the
remainders . Experimenting with this method is left to the reader. ______,,,,..
Example 0-6
(a) Convert 45 10 to hex.

lQ 2 l First, convert to binary.


0 0 32 + 8 + 4 + I = 45

45 10 = 00 10 11 0 12 = 2D hex

(b) Convert 629 10 to hex.

512 256 128 64 32 lQ B. 2 l


0 0 0 0 1

62910 = (512+64 + 32+ 16+4 + 1) = 00100111 0I01 2 = 275hex

(c) Convert 1714 10 to hex.

1024 512 256 128 64 32 lQ .8. 1 2 l


0 0 0 0 0

1714 10 = (1024 + 512 + 128 + 32 + 16 + 2) = 0110 1011 0010 2 = 6B2 hex

Converting from hex to decimal


Conversion from hex to decimal can also be approached in two ways:
I. Convert from hex to binary and then to decimal. Example 0-7 demonstrates this
method of converting from hex to decimal.
2. Convert directly from hex to decimal by summing the weight of all digits.

Example 0-7
Convert the following hexadecimal numbers to decimal.

(a)6B2 1-6 = 0110101100102


1024 512 256 128 64 32 lQ .8. 1 2 l
0 0 0 0 0

1024 + 512 + 128 + 32 + 16 + 2 = 171410

(b) 9F2D 16 = 100 1 11 11 00 10 11 0 12


32768 16384 8192 4096 2048 1024 512 256 128 64 32 16 8 4 2 l
1 0 0 1 1 1 1 1 001 0 1 1 0 1

32768 + 4096 + 2048 + 1024 + 512 + 256 + 32 + 8 + 4 + I = 40,749 10

CHAPTER 0: INTRODUCTION TO COMPUTING


s
Ta ble 0- 2: C ountin g in Bases Counting in bases 10, 2, ao d 16
To show the relat ionship between all three
Decimal Bin ary He x
bases, in Table 0-2 we show the sequence of nu~-
0 00000 0
bcrs fro m O to 31 in decimal , along w ith th e equiv-
0000 I I
a\e nt binary Table 0-3: Binary Addition
2 000 I O 2
and hex
3 0001 1 3 Sum
nu mbers . A +B Carry
4 00100 4 0
Noti ce 111
o+ o 0
5 00 10 I 5 each base
0+ l 0 l
6 001 10 6 that when
1+ 0 0 l
7 001 11 7 one more 1s
1+ l 0
8 0 1000 8 added to the
9 0 100 1 9 hig h es t
10 01 01 0 A di git, that
11 010 11 B digit becomes zero and a l is carried to the next-
12 0 11 00 C highest digit position. For example, in decimal , 9 +
13 0110 1 D 1 = 0 with a carry to the next-hi ghest position . In
binary, 1 + 1 = O with a carry; simi larly, in hex, F +
14 0 11 10 E
1 = 0 with a carry.
15 0 11 11 F
16 10000 10 Addition of binary and hex numbers
17 10001 11
18 10010 12 The addition of binary numbers is a very
straightforward process. Table 0-3 shows the addi-
19 10011 13
tion of two bits. The discussion of subtraction of
20 10100 14
binary numbers is bypassed since all computers use
21 10101 15 the addition process to implement subtraction.
22 10110 16 Although computers have adder circuitry, there is
23 10111 17 no separate circuitry for subtractors. Instead,
24 11000 18 s
adders are used in conjunction with 2 comp lemen t
25 1100 1 19 circuitry to perfonn subtraction. In other words, to
, 26 11010 lA implement "x - y" , the computer takes the 2's com-
27 11011 lB plement of y and adds it to x. The concept of 2's
28 11100 lC complement is reviewed next. Example 0-8 shows
29 11101 1D the addition of binary numbers.
30 11110 lE
31 11111 lF

Exam ple 0-8


Add the fo llowing binary numbers. Check against their dec imal equi valents.

Solution:

Bin a,y Decimal


110 1 13
+ 1001 __2_
10 110 22
2's complement
Togc tth c2 's compl, 111 11· t 0 f · b' .
l o th e res ult
I · ~ ~ d ,n ary number, in vert all the bits and the n add I
Th. . II d
,nvc~ rng th e bit s is simp ly a mailer of chang ing all Os to Is and Is to Os .
is is ca e t ic / s co111p/eme111. Sec Exumplc 0-9.
Example 0-9

Take the 2 's com pl ement of I 00 I 11 oI .

Solution:
100 11 101 bi nary number
OJ 1000 10 I 's complem ent
+ I
0 1100011 2 's complemen t

Addition and subtraction of hex numbers


In studying issues related to software and hardware of compu ters, it is often nec-
essary to add or subtract hex numbers. Mastery of these techniques is essentia l. Hex addi -
tion and subtraction are discussed separately below.

Addition of hex numbers


This section describes the process of adding hex numbers. Starting with the least
significant digits, the digits are added together. If the result is less than 16, write that digit
as the sum for that position. If it is greater than 16, subtract 16 from it to get the digit and
carry l to the next digit. The best way to explain this is by example, as shown in Examp le
0-10.
Example 0-1 0
Perform hex addition : 23D9 + 94BE.

Solution:
23D9 LSD: 9+ 14 = 23 23 - 16 = 7 wi th a carry
+ 94BE I + 13 + 11 = 25 25 - 16 = 9 with a carry
B897 1 + 3+4 = 8
MSD: 2 + 9 = B

Subtraction of hex numbers


· In subtracting two hex numbers, if the second dig it is greater than the first, bor-
row J 6 fro m the preceding d igit. S~e Example 0- 11 .

Example 0-11
P erform hex su btrac tion: 59F - 2B8.

Solution :

59 F LSD: 8 from 15 = 7
- 2B8 11 from25(9+ 16)= l4 (E)
2E7 2 fro m 4 (5 - l ) = 2

CHAPTER 0: JNTRODVCTION TO COMPUTING 7


ASCII code

The discussion so far has revolved around the represent ation of number
. tt
systems.
Smee
. all information in the computer must be representedb Y Os a nd ls , binary pa ems .
must be assigned to letters and other characters. In the 1960s a sta ndard representation
bl' h d
called ASCII (America n Sta ndard Code for Information Interchange) was eS ta •~ eh ·
The ASCII (pronounced "ask-E") code assigns binary patterns for numbers O to 9 , a 1 t e
letters of the English alphabet, both uppercase (capital) and lowercase, and many control
codes and punctuation marks. The great advantage of this system is that it is used by moSl
computers, so that information can be shared among computers. The ASCII system uses
a total of 7 bits to represent each code. For example, I 00 000 l is assigned to_the upper-
case letter ''A" and 11 O000 I is for the lowercase "a". Often, a zero is placed tn the most
significant bit position to make it an 8-bi t code. Figure 0- 1 shows ASCII codes. A com-
plete list of extended ASC II codes is given in Appendix F. The use of ASC H is not only
standard for keyboards used in the United States and many other countries but also pro-
vides a standard for printing and di splaying characters by output devices such as printers
and monitors.
Notice that the pattern of ASCII codes was designed to allow for easy manipula-
tion of ASCII data. For example, digits O through 9 are represented by ASCH codes 30
through 39. This enables a program to easily convert ASCII to decimal by masking off the
"3" in the upper nibble. Also notice that there is a relationship between the uppercase and
lowercase letters. The uppercase letters are represented by ASCII codes 4 I through 5A
while lowercase letters are represented by codes 61 through 7A. Looking at the binary
code, the only bit that is different between the uppercase "A" and lowercase "a" is bit 5.
Therefore, conversion between uppercase and lowercase is as simple as changing bit 5 of
the ASCII code. .
Hex Ch Hex Ch Hex Ch Hex Ch Hex Ch Hex Ch
00 Hex Ch Hex Ch

10
01 g
20 30 0 40 @ 50 p 60 . p

II 70
21 ! 31 1 A Q
02
e 12
t 22
" 32
2
41 51 61 a 71 q
03
• lJ
..
II
ti
42
B 52 R 62 b 72 :r
••
2J
04 14
411 24 $
33
3 43
C 53 s 63 C 73 s
34 4 44 D 5-1 T
05 15 64 d t
•• - s
§ 25 % 74
06 16 26 &
35 45 E 55 u 65 e 75 u
07 17
l 27
, 36 6 #, F 56 u (,(,
f 76
37 ? w "w
= G
47 57
08 67
I~
f 28 ( 38 8 9 77
48 H 58 X "~ h•
09
OA
08
0
8
{)
19

IA
18
.
,I.

4-
29
2A
28
)

*+
39
3A
38
9
..•
•t<I

4A
I
J
59
5A
y
z
f,9

6A
l.
j
78
79
7A
X
y
z
K
.
48 [
<'
58
OC'
V IC L lC # JC -IC L
ftli
k 78
<
SC \
OD J' ID 2D - 3D =
6('
1 7C I
I
OE
OF
n
0
1F.

IF •• 2E
2F
.
/
JE
3F
>
?
40
4E "N .5D
SE
l
A
6D
6E "'n 7D
7E
}
-
Figure 0-1. Selected ASCII Codes
4F 0 5F
- 6F 0 7F 0
-
Review Questions

I . Why do computers use the binary number system instead of the decimal system?
2. Convert 34 10 to binary and hex. ·
3. Convert 11010 l 2 to hex and decimal.
0
4. Perform binary addi tion : IO 11 00 + IO I
5 • Convert I OJ JOO t I·t 2 , ·
2 o s s complement representation .

SECTION 0.2: DIGITAL PRIMER

This section gives an overview of digital logic


and design . First, we cover binary logic operations
the~ we show gates that perform these functions . Next: 5 -
lo~ic g~tes are put together to fom, simple digital cir-
cuits. ~tnal!y, we cover some logic devices commonly 4 Logic I
found m m1crocontroller interfacing.
Binary logic
3
-
2-t -
As mentioned earlier, computers use the bina-
ry number system because the two voltage levels can I-
?e represented as the two digits Oand 1. Signals in dig-
ital electronics have two distinct voltage levels. For
0 - Logic 0

example, a system may define O V as logic O and +5 V


as logic I . Figure 0-2 shows this system with the built- Figure 0-2. Binary Signals
in tolerances for variations in the voltage. A valid dig-
ital signal in this example should be within either of the Logical AND Function
two shaded areas.
Inputs Output
Logic gates
XY XANDY
Binary logic gates are simple circuits that take 0 0 0
one or more input signals and send out one output sig- 0 1 0
nal . Several of these gates are defined below. 1 0 0
1 1 I
AND gate
The AND gate takes two or more inputs and
~ ==[)- X ANDY
performs a logic AND on them. See the truth table and
diagram of the AND gate. Notice that if both inputs to
Logical OR Function
the AND gate are 1, the output will be I . Any other
combination of inputs will give a O output. The exam- Inputs Output
ple shows two inputs, x and y. Multiple outputs ar~ also
XY XORY
possible for logic gates. In the ca~e of _AND, 1f all
inputs are I , the output is I . If any mput 1s 0, the out- 0 0 0
put is zero. 0 1 1
1 0 1
OR gate
1 1
The OR logic function will output a l if one or
more inputs is 1. If all inputs are 0, then and only then
will the output be 0.
~=D-XORY
Tri-state buffer
Buffer
A buffer gate does not change the logic level of
the input. It is used to isolate or amplify the signal. X-=t-Y
Control

CHAPTER 0: INTRODUCTION TO COMPUTING 9


Inverter
Logical Invcrtcr
The in\·crter, abo calkd NOT. outpu ts the Output
Input
\'alue opposite tn that input to the ga te. Thal is, a 1 NOTX
input will give a O uulput, while a O input will give a X
1 output. 0
0

XOR gate X --{>o- NOT X


The XOR gate perform s an exclusive-O R
operation on the inputs. Exclusive-OR produces a 1
output if one (but only one) input is 1. If both Logical XOR Fu nction
operands arc 0, the output is zero. Likewise, if both
In puts Output
operands arc 1, the output is also zero. Notice from
the XOR truth table, that whenever the two inputs XY XXOR Y
are the same, the output is zero. This function can be 0
0 0
used to compare two bits to see if they are the same.
0 l
0
NAND and NOR gates 0
The NANO gate functions like an AND gate
with an inverter on the output. It produces a zero out- ~ =1)- xxoRY
put when all inputs are l ; otherwise, it produces a l
output. The NOR gate functions like an OR gate with
an inverter on the output. It produces a l if all inputs
Logical NANO Function
are O; otherwise, it produces a 0. NANO and NOR
gates are used extensively in digital design because Inputs Output
they are easy and inexpensive to fabricate. Any cir-
cuit that can be designed with AND, OR, XOR, and XY XNAND Y
INVERTER gates can be implemented using only 0 0
NANO and NOR gates. A simple example of this is 0 l
given below. Notice in NANO, that if any input is l 0
zero, the output is one. Notice in NOR, that if any l l 0
input is one, the output is zero.
~ =Qo-x NANO Y
Logic design using gates
Next we will show a simple logic design to
add two binary digits. If we add two binary digits Logical NOR Function
there are four possrble outcomes: Inputs Output
x v XNORY
Carry Sum 0 0
O+O = 0 0 0 l 0
O+ l = 0 l 0 0
l +O = 0 l 0
l+l= 0
~ ==f)>- XNORY

Notice that when we add l + l we get O with a carry to the next higher place. We
w ill need to detennine the sum and the carry for this design. Notice that the sum column

10
abo\'c matc hes the ou tput for the XO R fu nction, and tha t the carry co lumn ma tches the
lllltput for the AND functi on. Figure 0-3 (a) shows a s im ple adder impleme nted wi th XOR
and AND gates. Figure 0-3 (b) shows the same logic circuit implemented w ith A ND and
OR gates .

X -{>o
X y
y Sum
>---- Sum
X
y -t>o
, - - - - Carry
X
y 0 - - -- - -- -Carry

(a) Half-Adder Using XOR and AND (a) Half-Adder Using AND, OR, Inverters

Figure 0-3. Two Implementations of a Half-Adder

Figure 0-4 shows a block diagram


of a half-adder. Two half-adders can be
combined to form an adder that can add X Sum
three input digits. This is called a full-adder. Half-
Figure 0-5 shows the logic diagram of a Adder
y Carry
full-adder, along with a block diagram that
masks the details of the circuit. Figure 0-6 out
shows a 3-bit adder using three full-adders.
Figure 0-4. Block Diagram of a Half-Adder

X X Half- Carry
y Sum y Adder

Sum

Half-
-C out
Adder
Carry
C in
C in
Final Sum

Figure 0-5. Fu ll-Adder Built from a Half-A dder

CHAPTER 0: INTRODUCTION TO COMPUTING


Decoders
Another example of the application of
logic gates is the decoder. Decoders are wide- L - - - - - - so
ly used for address decoding in computer XO Full-
design. Figure 0-7 shows decoders for 9 ( 100 I Adder Carry
binary) and 5 (0101) using inverters and AND YO
gates.

Flip-flops S1
X1
Full-
A widely used component in digital
Adder Carry
systems is the flip-flop. Frequently, flip-flops Y1
are used to store data. Figure 0-8 shows the
logic diagram, block diagram, and truth table
fo r a flip-flop.
The D flip-flop (D-FF) is widely used S2
X2
to latch data. Notice from the truth table that a Full-
D-FF grabs the data at the input as the clock is Adder Carry S3
Y2
activated. AD-FF holds the data as long as the
power is on.

Figure 0-6. 3-Bit Adder Using Three Full-Adders

LSB LSB

---{>o-
(a) Address decoder for 9 (binary l 001 ) (b) Address decoder fo r 5 (binary 0 l 0 1)
The output of the AND gate will be l The output of the AND gate will be 1
if and only if the input is binary 1001. if and only if the input is binary 0101.

Figure 0-7. Address Decoders

D Clk D 0
Q D Q No X no change
1, 0 0
Clk 1,
Clk
Q Q -- x = don't care

(b) Block diagram (c) Truth table


(a) Circuit diagram

fioure
e,
0-8. D Flip-Flops

12
Review Questions
l. The logica l operation
2. The logica l operation - - g_ivcs a I output when al l inputs are I .
3. T he logical operation- - g_1ve~ a l output when I or more of its inputs is l .
same value. - - is o ten used to compare if two inputs have the

: : ~ ame a c~: e does no~ change the logic level of the input
mon use 1or flip-flops ·
6 . An address · d . ·.
- - - is use to identify a predetermined binary address.

SECTION 0.3: INSIDE THE COMPUTER

. In this section we provide an i t d . . .


mg of computers The m0 d I d . n ro_uctton to the organization and internal work-
. e use 1s genenc but the t d·
all computers, including the IBM PC p ' con~ep s iscussed are applicable to
subject, it will be he! ful . , ~~2, and compatibles. Before embarking on this
ogy in computer rt p tu to revh1ew definitions of some of the most widely used terminol-
1 era re, sue as K, mega, giga, byte, ROM, RAM, and so on.
Some important terminology
H One_of th e mo st important features of a computer is how much memory it has
R ere ;e review t~rms ~sed to describe amounts of memory in x86 PCs and compatibles:
eca1 ~rom the discuss1?n above that a bit is a binary digit that can have the value O or 1.
~ by te IS defi~ed as 8 bits. A nibble is half a byte, or 4 bits. A word is two bytes or 16
b_its. In a 32-b,~ computer a word is 32 bits. The display is intended to show the r~lative
stze of these umts. Of course, they could all be composed of any combination of zeros and
ones.

Bit
0
Nibb l e
00 0 0
By te
0 000 00 0 0
Wo rd 0 0 0 0 0 000 00 00 000 0
3 2 -bi t Wo rd 0 0 00 000 0 0 0 00 0 0 0 0 000 0 000 0 0000 0000

A kilobyte is 2 10 bytes, which is 1024 bytes. The Table 0-4: Power of 2


abbreviation K is often used. A megabyte, or meg as 2 10 = 1024 = lK
some call it, is 2 20 bytes. That is a little over I million
220 = 1O24K = lM
bytes; it is exactly 1,048,576 bytes. Moving rapidly up
230 = 1O24M = lG
the scale in size, a gigaby te is 2 30 bytes (over 1 billion),
240 = 1O24G = l T
and a teraby te is 240 bytes (over I trillion). As an exam-
ple of how some of these terms are used, suppose that a
given computer has 16 megabytes of memory. That would be 16 x 220, or 24 x 220, which
is 224_ Therefore, 16 megabytes is 224 bytes. See Table 0-4.
Two types of memory commonly used in microcomputers are RAM, which stands
for "random access memory" (sometimes called read/write memory), and ROM, which
stands for "read-only memory." RAM is used by the computer for temporary storage of
program s that it is running. That data is lost when the computer is turned off. For this rea-
son, RAM is sometimes called volatile memory. ROM contains programs and informa-
tion essential to operation of the computer. The information in ROM is permanent, can-
not be changed by the user, and is not lost when the power is turned off. Therefore, it is
called non volatile memory.

CHAPTER 0: INTROD UCTION TO COMPUTING 13


Internal organization of computers
The internal ,vorkin l.! or e,·crv computer ca11 be broken do,vn into three parts:
CPU (central processing uni(). 111e1110~ and 1/0 (i nput/output) devices (sec Figure 0-9).
1•

~he function of the CPU is to execu te (process) in lon nation stored in memory. The fun c-
tion ?f l'.O devices such as the keyboard and video monitor is to provide a means of com-
m_unicat, ng with the CPU . The CPU is connected to memory and 1/0 through strips of
wire ca lled a hus. The bus c:1rrics in formation from place to place inside a computer just
a~ a street bus carries people from place tu place. In every computer there arc three types
of buses: address bus, data bus, and control bus.
For a device (memory or 1/0) to be recognized by the CPU, it must be assigned
an address. The address assigned to a given device must be un ique; no two devices arc
allowed to have the same address. The CPU puts the address (in bi nary, of course) on the
a?dress bus, and the decoding circuitry tin ds the device. Then the CPU uses the data bus
e'.ther to get data from that device or to send data to it. The control buses are used to pro-
vide read or wri te signals to the device to indicate if the CPU is ask ing for information or
se nd ing it information. Of the three buses the address bus and data bus determine the
capability of a given CPU . ' .

Address Bus

CPU Memory Peripherals

(monitor,
(RAM , ROM) printer, etc.)

Data Bus

Figure 0-9. Inside the Computer

More about the data bus


Since data lines are used to carry info1111ation in and out of a CPU , the more data
li nes available, the better the CPU. If one thinks of data lines as highway lanes, it is clear
that more lanes provide a better pathway between the CPU and its external devices (such
as printers, RAM, ROM, etc. ; see Figure 0-1 0) . By the same token, that increase in the
number of lanes increases the cost of construction . More data buses mean a more expen-
sive CPU and computer. The grouping of data lines is cal led data b11s. The average size
o f data buses in CPUs varies between 8 and 64. Early computers such as Apple 2 used an
8-bit data bus, while supercomputers such as Cray use a 64-bit data bus. Data buses are
.d . t· I s i·nce the CPU must use them either to receive or to send data. The process-
b 1 tree 10na, . . . .
• f oinputer is related to the size of its buses, smcc an 8-btt bus can send out
1n a power o a c . . . .
e • b t 16 bt't bus can send out 2 bytes at a tune, whic h ts tv. 1ce as fast.
1

I byte a time, u a -

14
More about the address bus
Since the address bus is used to id ·1· .
C P U th, cnt i Y the devices a11d
• 1,; more address buses avai lab I memory connected to the
1
addressed . In ot her words. th e numbe/' / ~d larger the num ber of devices that can be
ber of locati ons with which it can comm o _a ress buses for a CPU determines the num-
,. uni cate. The number of I . .
to 2· , where xis the number of add. 1· ocat1ons is always equal
iess mes regard( f h ·
examp le, a CPU with 16 add res 1· , ess o t e size of the data bus. For
s 111escan pro ·d
addressable memory. Eac h locati on can hav v1 ea tota 1 of 65,536 (216) or 64K bytes of
to the fact that all general-purpose m · . . e a maxi mu m of I byte of data. This is due
1c1op1ocessor CPUs h ·
a ble . As another example the IBM PC AT are w at 1s called byte address-
' used a C PU 'th 24 dd ·
lines. In th is case the total a 's 'bl . wi a ress Imes and 16 data
. cce s1 e memory is I 6 megabytes (224 - 16
this example there would be 2 24 . . - megabytes). In
1
would be 16 megabytes of memo ~:~ions, and s1~ce ea~h . loc~tion is one byte, there
that the CPU uses the add. b ry. I address bus is a umd1rect10nal bus, wh ich means
b f iess us on y to send out addresses. To summarize· The total
num er O memory locations address bl b · . ·
is the nwnber of address bits . di a e f y a g_1ven CPU is always equal to 2x where x
' regar ess o the size of the data bus.

Address Bus

RAM ROM Printer Disk Monitor Keyboard


CPU ~
.
' ~
' ' ~ ~

Data Bus

Read/write
Control Bus

Figure 0-1 0. Internal Organization of Computers

CPU and its relation to RAM and ROM


For the CPU to process information, the data must be stored in RAM or ROM.
The function of ROM in computers is to provide infom1ation that is fixed and permanent.
This is infonnation such as tables for character patterns to be displayed on the video mon-
itor, or programs that are essential to the working of the computer, such as programs for
testing and findin g the total amount of RAM installed on the system, or programs to d is-
play information on the v ideo monitor. In contrast, RAM is used to store information that
is not permanent and can change with time, such as various versions o f the operating sys-
tem a nd application packages suc h as word processing or tax calculation packages. These
programs are loaded into RAM to be processed by the C PU. The CPU cannot get the
informa ti on d irectly from the d isk since the disk is too slow. In othe r words, the C PU first
seeks the information to be p rocessed from RAM ( or ROM). Only if it is not there does
the CPU seek it from a mass s torage device such as a disk, and then it transfers the infor-
ma tion to RAM. For this reason, RAM and ROM are sometimes referred to as primary
memory and disks are called secondary memory. Figure 0- 11 shows a block diagram of
the in ternal organization of the PC.

CHAPTER 0: INTROD VCTION TO COMPUTING 15


)>
a.
I a.
..,

I
I Program Counter I (1)
Vl
Vl

0:,
C
Vl

Flags
ALU
IInstruction Register I n0
::,

I
Instruction
decoder, timing,
and control
- ~
2..
0:,
C
Vl
(!)
Vl

Internal 0
buses -
Cl
Cl
0:,
Register A C
Vl

Register B
Register C
Register D

Figure 0-11. Internal Block Diagram of a CPU

Inside CPUs
. A prog_ram stor~d in memory provides instructions to the CPU to perform an
action. The action can simply be adding data such as payroll data or controlling a machine
such as a robot. It is the function of the CPU to fetch these instructions from memory and
execute them. To perform the actions of fetch and execute, all CPUs are equipped with
resources such as the following:

1. Foremost among the resources at the disposal of the CPU are a number of reg-
isters. The CPU uses registers to store information temporarily. The information could
be two values to be processed, or the address of the value needed to be fetched from
memory. Registers inside the CPU can be 8-bit, 16-bit, 32-bit, or even 64-bit regis-
ters, depending on the CPU. In general, the more and bigger the registers, the better
the CPU . The disadvantage of more and bigger registers is the increased cost of such
a CPU.
2. The CPU also has what is called the ALU (arithmetic/logic unit). The ALU section of
the CPU is responsible for performing arithmetic functions such as add, subtract, mul-
tiply, and divide, and logic functions such as AND, OR, and NOT.
3. Every CPU has what is called a program counter. The function of the program count-
er is to point to the address of the next instruction to be executed. As each instruction
is executed, the program counter is incremented to point to the address of the next
instruction to be executed. The contents of the program counter are placed on the
address bus to find and fetch the desired instruction. In the IBM PC, the program
counter is a register called IP, or the instruction pointer.
4 . The function of the instruction decoder is to interpret the instruction fetched into the
C PU . One can think of the instruction decoder as a kind of dictionary, storing the
meaning of each instruction and what steps the CPU should take upon receiving a
giYen instruction. Just as a dictionary requires more pages the more words it defines,

16
a CPU capable o f understanding more instructions req uires more transistors to des ign.

Internal working of computers


To demonstrate some of the concepts discussed above, a step-by-step analysi s of
the process a CPU would go through to add three numbers is given next. Assume that an
imaginary CPU has registers called A, B, C, and D. It has an 8-bit data bus and a 16-bit
address bus. Therefore, the CPU can access memory from addresses 0000 to FFFFH (for
a total of I OOOOH locations). The action to be performed by the CPU is to put hexadeci-
mal value 21 into register A , and then add to register A values 42H and 12H. Assume that
the code for the CPU to move a value to register A is l O11 0000 (BOH) and the code for
adding a value to register A is 0000 0100 (04H). The necessary steps and code to perform
them are as follows .

Action Code Data


Mo v e v a lue 2 1H i nto r egi st~r A BOH 21H
Add value 42 H to reg i s t er A 04 H 42H
Add value 12H t o register A 04H 1 2H

If the program to perform the actions listed above is stored in memory locations
starting at 1400H, the fo llowing would represent the contents for each memory address
location:

Memory address Contents 0£ memory addre ss


1 4 00 (B0)code f o r mov ing a val u e t o regi ster A
14 0 1 (2 l)value t o be moved
1 4 02 ( 0 4) c ode for adding a value t o re g i s te r A
1 4 03 ( 42) val ue to be a dded
1 4 04 ( 04 ) code f o r addi n g a va l ue to regis t e r A
1 4 05 (1 2 ) v a l u e t o b e a d d e d
1 4 06 (F 4 ) cod e f o r halt

The actions performed by the CPU to run the program above would be as follows:

1. The CPU's program counter can have a value between 0000 and FFFFH. The pro-
gram counter must be set to the value 1400H, indicating the address of the first
instruction code to be executed. After the program counter has been loaded with the
address of the first instruction, the CPU is ready to execute.
2. The CPU puts 1400H on the address bus and sends it out. The memory circuitry finds
the location while the CPU acti vates the READ signal, indicating to memory that it
wants the byte at location 1400H. This causes the contents of memory locatio n
1400H, which is BO, to be put on the data bus and brought into the CPU .
3. The CPU decodes the instruction BO with the help of its instruction decoder diction-
ary. When it finds the definition for that instruction it knows it must bring into regis-
ter A of the CPU the byte in the next memory location. Therefore, it commands its
cona:oller circuitry to do exactly that. When it brings in value 21 H from memory loca-
tion 140 l , it makes sure that the doors of all registers are closed except register A.
Therefore, when value 21H comes into the CPU it w ill go directly into register A .
After completing one instruction, the program counter points to the address of the next
instruction to be executed, which in this case is 1402H. Address 1402 is sent out on
the address bus to fetch the next instruction.

CHAPTER 0: INTRODUCTION TO COMPUTING 17


'

4. ho1n m~111n1y1 local 1011 14021111. ktches . code (l411 · Arter


. . decoding,t the CPU (1403).
ddress knows
1
t 1a1 tt 111us1add to the conh.:nts ol . n:g1.~tcr /\ tic
l i...uy le sitting .at the nex .d ah ontents of
. . . 42
t\lkr tt hnngs the value (111 this case l ) mto I icI . l CPU ' it . . es t ·he c t kes the
prov1
rcg1~1~·r A nlong w11 h thi:-. value to the ALU lo pcriorm r the add1 . t1on · ItMt en ah'le the
resul t or the aJdit ion from the /\ LU's output and puts it in register A. canw 1
pro~ram rnunter becomes 1404 the address of the next instruction. d d
5
- Addre:.-s 140411 is put on ·the address bus and the code is fetched into the CPU, eco -
ed. and executed. This code is again add111g . a value to register . A• The program count-
er is updated to 14061-1 . ·
6
- Finally, the contems of address 1406 arc fetched in and executed. This HALT mSlruc-
tion tells the CPU to stop incrementing the program counter and asking :or the next
instruction. In the absence of the HALT, the CPU would continue updatmg the pro-
gram counter and fetching instructions.

th Now suppose that address l403H contained value 04 instead of 42H. How would
e CPU distinguish between data 04 to be added and code 04? Remember that code 04
for this CPU means move the next value into register A. Therefore, the CPU will not try
~o decode the next value. lt simply moves the contents of the following memory location
mto register A, regardless of its value.

Review Questions
1. How many bytes is 24 kilobytes?
2. What does "RAM" stand for? How is it used in computer systems?
3. What does "ROM" stand for? How is it used in computer systems?
4. Why is RAM called volatile memory?
5. List the three major components of a cornputer system.
6. What does "CPU" stand for? Explain its function in a computer.
7• List the three types of buses found in computer systems and state briefly the purpose
of each type of bus.
8. State which of the following is unidirectional and which is bidirectional.
(a) data bus (b) address bus
9. If an address bus for a given computer has 16 lines, what is the maximum amount of
memory it can access?
l 0. What does "ALU" stand for? What is its purpose?
11. How are registers used in computer systems?
12. What is the purpose of the program counter?
13. What is the purpose of the instruction decoder?

PROBLEMS

SECTION 0.1: NUMBERING AND CODING SYSTEMS

I. Convert the following decimal numbers to binary.


(a) 12 (b) 123 (c) 63 (d) 128 (e) 1000
2. Convert the following binary numbers to decimal.
(a) 1001 00 (b) 1000001 (c) 111 01 (d) _l0 l0 (e)0010001 0
3. Convert the values in Problem 2 to hexadecimal.
4. Convert the following hex numbers to binary and decimal.
(a) 28 9H (b) F44H (c) 9 12H (d) 2BH (e) FFFFH
5. Convert the values in Problem l to hex.

18
6. Fi nd the 2's complement of the fo ll owing binary numbers.
(a) \001010 (b) l 1100\ (c) 10000010 (d) I I I 110001
7. Add the following hex values .
(a) 2CH + 3FH (b) F34H + 5O6H (c) 20000H + 12FFH (d) FFFFH + 2222H
8. Perform hex subtraction for the following.
(a) 24FH - \29H (b) FE9H - SCCH (c) 2FFFF H- FFFFFH (d) 9FF25H - 4DD99H
9. Show the ASCI\ codes for numbers 0, l , 2, 3, .. ., 9 in both hex and binary.
IO. Show the ASCH code (in hex) for the fo llowing string:
''U.S.A. is a country" CR, LF
"in North America" CR, LF
CR is carriage return
LF is line feed

SECTION 0.2: DIGITAL PRIMER

11. Draw a 3-input OR gate using a 2-input OR gate.


12. Show the truth table for a 3-input OR gate.
13. Draw a 3-input AND gate using a 2-input AND gate.
14. Show the truth table for a 3-input AND gate.
15. Design a 3-input XOR gate with a 2-input XOR gate. Show the truth table for a 3-
input XOR.
16. List the truth table for a 3-input NAND.
17. List the truth table for a 3-input NOR.
18. Show the decoder for binary 1100.
19. Show the decoder for binary 11011.
20. List the truth table for a D-FF.

SECTION 0.3: INSIDE THE COMPUTER

21. Answer the following:


(a) How many nibbles are 16 bits?
(b) How many bytes are 32 bits?
(c) If a word is defined as 16 bits, how many words is a 64-bit data item?
(d) What is the exact value (in decimal) of l meg?
(e) How many K is l meg?
(t) What is the exact value (in decimal) of l giga?
(g) How many K is l giga?
(h) How many meg is l giga?
(i) If a given computer has a total of 8 megabytes of memory, how many
bytes (in decimal) is this? How many kilobytes is this?
22. A given mass storage device such as a hard disk can store 2 gigabytes of information.
Assuming that each page of text has 25 rows and each row has 80 columns of ASCII
characters (each character = l byte), approximately how many pages of information
can this disk store?
23. In a given byte-addressable computer, memory locations 10000H to 9FFFFH are
available for user programs. The first location is l OOOOH and the last location is
9FFFFH. Calculate the following:
(a) The total number of bytes available (in decimal)
(b) The total number of kilobytes (in decimal)
24. A given computer has a 32-bit data bus. What is the largest number that can be car-
ried into the CPU at a time?

CHAPTER 0: INTRODUCTION TO COMPUTING 19


25 . 13dow ar,· li :-.1cd s,·,·cia l compu ter~ w11h the ir data bu:- \\ 1d th s. h ~r each com puter, list
th,' maximum , aluc that C ll l be bniugh t 111tl1 thc C PU at a t11n e (111 both hex an d dcc-
1mal )
(a) Apple'.:;" 1t h an ~-bi t data bus
(b) IBt\1 PC \\ tth a 1(1-btt data bus
{c) IBM PC wi th a 32-h tt datn bus
(d) Cray ~u pcl"l..' tlmputl'r with a 64 -btt data bus .
26. Find thc total amount of mcmory, in the units requested, for each of the fo llowing
CPUs. g1n~n the s1 zc of thc address buses.
( a) 1b-bit addrcss bus l 111 K)
{b) 24-btt address bus (in megabytes)
(c) 32-btt addrcss bus (in megabytes and gi gabytes)
(d) -i::;-bit address bus (in megabytes, gigabytes, and terabytes)
27. Regarding the data bus and address bus, which is unidirectional and which is bidirec-
tional'?
28. \\ l1ich register of the CPU holds the address of the instruction to be fetched?
29. \\ nich section of the CPU is responsible for performing addition?
30. l ist the three bus types present in every CPU.

ANSWERS TO REVIEW QUESTIONS

SECTION 0.1: NUMBERING AND CODING SYSTEMS

1. Computers use the binary system because each bit can have one of two voltage lev-
els: on and off.
2. 341 0 = 1000102 = 2216
3. 1101012=3516 = 5310
4. 11 10001
5. 0 I 0100

SECTION 0.2 : DIGITAL PRIMER

I. AND
2. OR
3. XOR
4. Buffer
5. Storing data
6. Decoder

SECTION 0.3 : INSIDE THE COMPUTER

I . 24,576
2. Random access memory; it is used for temporary storage of programs that the CPU
is running, such as the operating system, word processing programs, etc.
3. Read-only memory; it is used for pem1anent programs such as those that control the
keyboard, etc.
4. The contents of RAM are lost when the computer is powered off.
5. The CPU, memory, and 1/0 devices
6. Central processing unit; it can be considered the "brain" of the computer; it executes

20
thl· prn~r am~ and lOlltrnl~ all other dc\, rcc.·, 111 the cc1111p1 11 cr
7 l lw nddn.· , , h11~ c.·11 11 1c.·, th e lnrn t,on (nddrc,-.) needed hy lhc CPU . the dar.1 hu-; car-
11c.• , mfomHllrPn 111 nnd 0111 of the CPU . the.· conrrol hus 1s u~cd hy the C PU to ,;c nJ
,r~nn ls con rmllmg I 'O tl cviccs
1'. (ll) h1 du~c 11nnn l (h) 11ntd1rcct1or..1I
Q <w K . t'r 6:ci.5.16 hylcs
I() An1 hmcttc/log1c uml; ,t performs all arithmetic and logic operations.
11 . 11 1s for te mporary storage of infonnat ion.
12 II holds the address of the nex1 instruction to be executed.
I J. It tells the C PU what steps to perform fo r each instruction .

CHAPTER 0: INTRODUCTION TO COMPUTING 21

Das könnte Ihnen auch gefallen