Beruflich Dokumente
Kultur Dokumente
INTRODUCTION TO
COMPUTING
OBJECTIVES
>> 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.
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.
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
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.
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.
____________________
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.
45 10 = 00 10 11 0 12 = 2D hex
Example 0-7
Convert the following hexadecimal numbers to decimal.
Solution:
Solution:
100 11 101 bi nary number
OJ 1000 10 I 's complem ent
+ I
0 1100011 2 's complemen t
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
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
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 .
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
X X Half- Carry
y Sum y Adder
Sum
Half-
-C out
Adder
Carry
C in
C in
Final Sum
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.
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.
D Clk D 0
Q D Q No X no change
1, 0 0
Clk 1,
Clk
Q Q -- x = don't care
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.
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
~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
(monitor,
(RAM , ROM) printer, etc.)
Data Bus
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
Data Bus
Read/write
Control Bus
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
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.
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:
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.
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
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
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
I. AND
2. OR
3. XOR
4. Buffer
5. Storing data
6. Decoder
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 .