Sunteți pe pagina 1din 190

FIT1001

Computer Systems
U N I T B O O K
!"#$%"#& ()*
!"#$%%$ '"( )*+ ,-. !/012,3 *) "4)*+5/,6*4 #.0-4*2*738 9*4/:- ;46<.+:6,38 64 0*4=140,6*4
>6,- ,-. ?.4,+. )*+ @./+4647 A #./0-647 '1BB*+,8 9*4/:- ;46<.+:6,3
!"+,-#& ()*
?.4,+. )*+ @./+4647 A #./0-647 '1BB*+,8
9*4/:- ;46<.+:6,38
?-1+0-6228 C60,*+6/8 D1:,+/26/8 EFGH
!6+:, I1J26:-.K D171:, H%%L
M.<6:.K A I+64,.K N.0.5J.+ H%%L
O ?*B3+67-, H%%L P H%%Q
#-6: B1J260/,6*4 6: 0*B3+67-,R DB/+, )+*5 /43 )/6+ K./2647 )*+ ,-. B1+B*:. *) B+6</,. :,1K38
+.:./+0-8 0+6,606:5 *+ +.<6.> /: B.+56,,.K 14K.+ ,-. ?*B3+67-, D0,8 4* B/+, 5/3 J.
+.B+*K10.K J3 /43 B+*0.:: *+ B2/0.K 64 0*5B1,.+ 5.5*+3 >6,-*1, >+6,,.4 B.+56::6*4R
S4T16+6.: :-*12K J. 5/K. ,* ,-. B1J26:-.+R
Contents
!"#$ &"'()*+$#(" #
,- ./ &"$)(012$#(" $( 3(*41$5) ,67$5*7 .
,- 8/ 9+$+ :54)575"$+$#(" +"0 3(*41$5) ;)#$<*5$#2 8=
,- >/ ?@5)@#5A (' B((C5+" ;CD5E)+ +"0 9#D#$+C F(D#2 =.
,- G/ 3H! &"$5)"+C B17 ?)D+"#7+$#(" I>
,- =/ &"$)(012$#(" $( &"7$)12$#(" ,5$ ;)2<#$52$1)5 JI
,- K/ 3(*41$5) H)(D)+* LM521$#(" 3("254$7 NI
,- I/ 3(*41$5) O5*()6 3(*4("5"$7 +"0 ?)D+"#7+$#(" ...
,- J/ &"41$P?1$41$ ?)D+"#7+$#(" +"0 ,$+"0+)07 .8.
,- N/ &"$)(012$#(" $( ?45)+$#"D ,67$5*7 .G.
,- .Q/ R#C5 ,67$5*7 R5+$1)57 +"0 R()*+$7 .GN
,- ../ !75) &"$5)'+257 .=N
,- .8/ &"$)(012$#(" $( ,67$5* ,('$A+)5 .KI
Unit Information
!
UNIT INFORMATION
Welcome
WeIcome lo IIT1001 Comuler Syslems.
Afler reading lhis unil informalion, and before you slarl on lhe resl of lhis
Unil ook you shouId go lo hll://muso.monash.edu.au and seIecl lhe
Iink for lhis unil and navigale lo "#!$ &#'()*+$!(#. This viII rovide any
addilionaI informalion and udales lo lhis rinled informalion.
The vebsile viII rovide you vilh imorlanl adminislralive informalion,
incIuding delaiIs on lexlbook and soflvare requiremenls, assessmenl
informalion, imorlanl dales and delaiIs on communicalion lhroughoul
lhe semesler. WhiIe you are lhere, bookmark lhe unil vebsile in your
brovser. You viII have lo visil il reguIarIy lhroughoul your sludies.
Description
IIT1001 Comuler Syslems viII inlroduce sludenls lo basic comuler
hardvare and oeraling syslems soflvare vilh emhasis on lhe concels
required lo undersland lhe Iov-IeveI and inlernaI oeralions of comuler
syslems.
IIT1001 is inlroduced as arl of lhe common core for firsl year
undergraduales in lhe IacuIly of Informalion TechnoIogy (IIT) in 2006. Ils
key ob|eclives are lo reare sludenls so lhal lhey viII:
Undersland lhe basic inlernaI archileclure and oeralion of a
comuler and ils eriheraIs
Undersland lhe basics of oeraling syslem soflvare and ils
suorl for soflvare deveIomenl looIs
Undersland crilicaI faclors lhal affecl comuler erformance.
In arlicuIar, lhis incIudes sludy of dala reresenlalion, simIe digilaI
Iogic, comuler organisalion incIuding CIU, memory and inul/oulul
devices, as veII as machine-IeveI and assembIy Ianguage rogramming,
FIT1001 Computer Systems
!!
and oeraling syslem concels vilh examIes of rocess managemenl,
fiIe syslem slruclures and user inlerfaces. The inlenlion is lo rovide
oorlunilies for sludenls lo reIale lhe hardvare knovIedge covered in
lhis unil lo lhe concels Iearned in lheir inlroduclory rogramming and
syslems anaIysis cIasses, and lo give a more comIele underslanding of
hov hardvare and soflvare are used lo buiId syslems.
Why is IIT1001 a core unil` AII IT graduales need lo have exosure lo lhis
loic area, as knovIedge of comuler archileclure and oeraling syslem
soflvare Ieads lo grealer underslanding of common IT lasks, such as dala
slorage and relrievaI, lhe rogramming rocess and lhe oeralion of
comuling equimenl. This aIIovs designers and rogrammers lo secify,
deveIo and use IT syslems more effecliveIy. Il aIso rovides
oorlunilies for sludenls lo reIale lhe use of rogramming Ianguages,
sludies of syslem design and ro|ecl managemenl lo hov lhese may be
imIemenled in comuler syslems.
1. Objectives
On comIelion of lhis unil sludenls shouId be abIe lo:
undersland basic comuler slruclure and oeralion and demonslrale
use of lhe associaled vocabuIary,
demonslrale an underslanding of lhe concels of dala reresenlalion,
comuler arilhmelic and ooIean aIgebra using aroriale melhods
of imIemenlalion,
demonslrale delaiIed knovIedge of inlernaI bus, memory, I/O
organisalions and inlerfacing slandards,
describe lhe inlernaI oeralion of lhe CIU and exIain hov il is used
lo execule inslruclions,
differenliale belveen machine Ianguage and assembIy Ianguage and
vrile assembIy Ianguage rograms lo soIve simIe robIems,
demonslrale an underslanding of lhe basics of oeraling syslems
soflvare using examIes from IiIe Syslems, User Inlerfaces and
Soflvare DeveIomenl TooIs,
idenlify faclors lhal affecl comuler erformance,
use various simuIalors lo demonslrale lhe oeralion of simIe
comuler archileclures,
Unit Information
!!!
2. Prerequisite
None.
3. Unit resources
Unit book
This Unil ook consisls of lvo arls: Unil Informalion and Sludy Guides
vilh raclicaI sessions. Unil Informalion gives some generaI informalion
regarding lhe unil. Il incIudes delaiIs on rerequisiles, lexlbooks,
assessmenl and conlacl delaiIs. More recenl coies of lhis informalion viII
be found in lhe Unil Informalion seclion of lhe unil veb sile, as
menlioned above. The second arl consisls of 12 Sludy Guides vhich heI
you go lhrough lhe sludy maleriaIs and aclivilies of lhe unil. This arl
aIso conlains informalion aboul raclicaI sessions Iinked lo sludy ilems.
Prescribed textbook
Linda NuII and }uIia Lobur, !"# %&&#'()*+& ,- .,/01(#2 324*')5*(),' *'6
728")(#8(12#9 }ones and arlIell, 2003, ISN 0-7637-0444-X
Supplementary textbooks
A. S. Tanenbaum, :(218(12#6 .,/01(#2 324*')5*(),', 5lh Idilion, Iearson
Irenlice-HaII, 2006, ISN 0-13-148521-0
W. SlaIIings, .,/01(#2 324*')5*(),' *'6 728")(#8(12#9 7
lh
Idilion, Iearson
Irenlice-HaII, 2006, ISN 0-13-185644-8
S. D. urd, :;&(#/& 728")(#8(12#9 5
lh
edilion, Thomson Course TechnoIogy,
2006, ISN 0-619-21692-1
W. SlaIIings, 30#2*()'4 :;&(#/& <'(#2'*+& *'6 =#&)4' >2)'8)0+#&9 5
lh
edilion,
Iearson Irenlice HaII, 2005, ISN 0-13-127837-1
A. SiIberschalz, I. . GaIvin and G. Gange, 30#2*()'4 :;&(#/ .,'8#0(&9
WiIey, 7
lh
edilion, 2005, ISN 0-471-69466-5
M. IaImer, M. WaIlers, T. adgell and N. }onker, ?1)6# (, 30#2*()'4
:;&(#/&9 3
rd
edilion, Thomson Course TechnoIogy, 2004, ISN 0-619-21347-
7
FIT1001 Computer Systems
!-
A. S. Tanenbaum, @,6#2' 30#2*()'4 :;&(#/&9 2
nd
edilion, Irenlice HaII,
2001, ISN 0-13-092641-8
W. S. Davis and T. M. Ra|kumar, 30#2*()'4 :;&(#/& A 7 :;&(#/*()8 7002,*8"9
6
lh
edilion, Iearson Addison WesIey, 2004, ISN 0-321-26751-6
I. M. IIynn and A. M. McHoes, B'6#2&(*'6)'4 30#2*()'4 :;&(#/&9 4
lh
edilion, Thomson Course TechnoIogy, 2006, ISN 0-534-42366-3
}. L. Iord, C)'6,D& :"#++ :82)0()'4 *'6 C:E9 Iremier Iress, 2002, ISN 1-
931841-26-8
M. G. SobeII: 7 >2*8()8*+ ?1)6# (, F)'1G9 Irenlice HaII, 2005, ISN 0-13-
147823-0
I. IngIander: !"# 728")(#8(12# ,- .,/01(#2 E*26D*2# *'6 :;&(#/& :,-(D*2#H
7' <'-,2/*(),' !#8"',+,4; 7002,*8", 3
rd
Idilion, WiIey, 2003, 0-471-07325-3
AddilionaI on-Iine maleriaI / documenls are avaiIabIe from lhe unil
vebsile or can be Iocaled on an inlernel search by using aroriale
keyvords.
4. Workload
Leclures: 3 hours er veek
IraclicaI cIasses / TuloriaIs: 2 hours er veek
Irivale sludy (incIuding revision, homevork and rearalion): 7 hours
er veek
These are eslimales, limes may vary for each sludenl.
5. Assessment
1. IraclicaI: TuloriaI/Laboralory Assignmenls and cIass lesls (40%)
2. Theory: A lhree hour examinalion (60%)
No books or aers are ermilled in lhe examinalion (cIosed book
examinalion). Sludenls musl oblain salisfaclory marks in bolh
comonenls lo oblain an overaII ass in lhe unil.
Unit Information
-
OCL sludenls viII underlake lhe equivaIenl assessmenl of lheory lhrough
an OCL examinalion rocess, vilh on-Iine submission for cIass lesl and
assignmenls. The on-camus sludenls viII be assessed in a suervised
Iaboralory cIass.
The assignmenls and cIass lesl viII have a veighling of 40% and lhe exam
a veighling of 60% overaII. Hovever, lo encourage consislenl
erformance, lhe finaI mark cannol be more lhan 10 marks higher lhan lhe
assignmenl vork ercenlage. AIso, since assignmenl vork is nol
comIeled in a conlroIIed environmenl, lhe finaI mark cannol be more
lhan 10 marks higher lhan lhe exam ercenlage.
A labIe shoving hov lhe finaI resuIl mighl resond under lhe above
formuIa is given beIov vhere lhe shaded area reresenls lhe ass
marks:
Ixam ercenlage
0 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100
0 0 4 7 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10
5 2 5 9 12 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15
10 3 7 10 14 17 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
15 5 8 12 15 19 22 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25
20 6 10 13 17 20 24 27 30 30 30 30 30 30 30 30 30 30 30 30 30 30
25 8 11 15 18 22 25 29 32 35 35 35 35 35 35 35 35 35 35 35 35 35
30 9 13 16 20 23 27 30 34 37 40 40 40 40 40 40 40 40 40 40 40 40
35 10 14 18 21 25 28 32 35 39 42 45 45 45 45 45 45 45 45 45 45 45
40 10 15 19 23 26 30 33 37 40 44 47 50 50 50 50 50 50 50 50 50 50
45 10 15 20 24 28 31 35 38 42 45 49 52 55 55 55 55 55 55 55 55 55
50 10 15 20 25 29 33 36 40 43 47 50 54 57 60 60 60 60 60 60 60 60
55 10 15 20 25 30 34 38 41 45 48 52 55 59 62 65 65 65 65 65 65 65
60 10 15 20 25 30 35 39 43 46 50 53 57 60 64 67 70 70 70 70 70 70
65 10 15 20 25 30 35 40 44 48 51 55 58 62 65 69 72 75 75 75 75 75
70 10 15 20 25 30 35 40 45 49 53 56 60 63 67 70 74 77 80 80 80 80
75 10 15 20 25 30 35 40 45 50 54 58 61 65 68 72 75 79 82 85 85 85
80 10 15 20 25 30 35 40 45 50 55 59 63 66 70 73 77 80 84 87 90 90
85 10 15 20 25 30 35 40 45 50 55 60 64 68 71 75 78 82 85 89 92 95
90 10 15 20 25 30 35 40 45 50 55 60 65 69 73 76 80 83 87 90 94 97
95 10 15 20 25 30 35 40 45 50 55 60 65 70 74 78 81 85 88 92 95 99
O
v
e
r
a
I
I
a
s
s
i
g
n
m
e
n
l

e
r
c
e
n
l
a
g
e
100 10 15 20 25 30 35 40 45 50 55 60 65 70 75 79 83 86 90 93 97 100
FIT1001 Computer Systems
-!
The formuIa used is:
'!#+. /)+01 2 *!# 34567, 8567, 89:54936;:<<
4 overaII assignmenl and lesl ercenlage
8 examinalion ercenlage
: exam veighling (0.6)
6. Late assignments
Assignmenls submilled afler lhe due dale viII be acceled onIy in
excelionaI circumslances. If an assignmenl viII be Iale, il is necessary lo
conlacl lhe Ieclurer al Ieasl 2 days before lhe due dale and submil a
vrillen aIicalion for exlension. You shouId rovide documenlalion lo
suorl a requesl for Iale submission (Ig. Doclor's Cerlificale). The
aIicalion for exlension form is avaiIabIe from lhe unil veb sile. Al lhe
discrelion of lhe Ieclurer, assignmenls submilled afler lhe due dale may
incur a enaIly for Ialeness. An assignmenl submilled more lhal seven
days afler lhe due dale viII be given a score of zero.
7. Plagiarism
IIease read lhe foIIoving on chealing and coying.
Cheating
Sludenls shouId nole lhal chealing is regarded as a very serious offence
vhich is IikeIy lo Iead nol onIy lo faiIure in lhe unil concerned bul aIso lo
addilionaI enaIlies incIuding excIusion. Sludenls shouId carefuIIy nole
lhal lhe laking of any unaulhorised maleriaI inlo examinalions such as
noles and unaulhorised diclionaries viII be regarded as chealing.
Sludenls shouId aIso nole lhal essays, assignmenls and olher vork
generaIIy underslood lo be lhe sludenl's ovn vork and vhere such vork
is idenlicaI vilh, or simiIar lo, anolher sludenl's vork, an assumlion of
chealing may arise. Where sludenls vish lo underlake vork in
con|unclion vilh olher sludenls, il is suggesled lhal lhe maller be
discussed vilh lhe Ieclurer concerned.
Unit Information
-!!
Copying
The assignmenls sel in lhis unil are designed rimariIy as Iearning
exercises, bul lhey aIso conlribule lo your finaI grade. Coying of olher
sludenl's assignmenl soIulions is unaccelabIe. AII sludenls have a
resonsibiIily lo ensure lhal lheir assignmenl soIulions are lheir ovn
vork.
You musl ensure lhal olhers do nol oblain access lo your soIulions for lhe
urose of coying a arl of lhem. Where such Iagiarism is delecled,
bolh of lhe assignmenls invoIved viII receive no marks.
In significanl cases of Iagiarism, aclion may be laken againsl lhe
offenders under lhe Universily's disciIinary reguIalions.
8. Library requirements
You viII need lo be abIe lo access al Ieasl one of lhe Monash Iibraries,
eilher ersonaIIy or on-Iine. Access lo a lechnicaI Iibrary viII aIso heI
you. e sure lo oblain a coy of lhe Library Guide, and if necessary, lhe
inslruclions for remole access. If you have any secific queries afler
reading lhe Library Guide, Iease ring lhe IxlernaI Services Unil on 1800
331194 or (03) 9902 6313 or (03) 5122 6313. If you are using lhe Monash
Iibrary ersonaIIy, you may make arrangemenls for luloriaIs on use of lhe
comuler calaIogue and CD-ROMs vilh lhe User Services slaff. IIease
discuss vilh your Ieclurer or Iibrary slaff if you have any concern aboul
Iibrary access.
9. Newsgroups and Web pages
AII sludenls in lhis unil viII have access lo message areas knovn as
'#D&42,10& for unil discussion and informalion on lhe unil veb sile. You
may osl any queslions you have lo lhe aroriale nevsgrou. You may
aIso use lhese message areas lo inleracl vilh slaff and sludenls. There viII
be al Ieasl lhree nevsgrous, vhich are:
Nolices
GeneraI
Assignmenls
FIT1001 Computer Systems
-!!!
AII imorlanl announcemenls aboul lhe unil viII be made in lhe firsl
nevsgrou. You can access lhese nevsgrous from Monash IorlaI veb
sile, al hll://my.monash.edu.au and al lhe IIT1001 unil veb sile al
hll://muso.monash.edu.au. You shouId visil lhese message areas al Ieasl
veekIy, lo gel lhe Ialesl informalion aboul your sludies.
Leclure noles, TuloriaI exercises and olher imorlanl sludy resources viII
aIso be avaiIabIe on lhe above unil vebage. You shouId have received a
coy of Monash Universily Comuler Resources, vhich rovides
essenliaI informalion on hov lo use Monash Comuler Resources. You
are encouraged lo read il.
If you have difficuIly accessing lhe unil vebage, Iease conlacl lhe
IacuIly of Informalion TechnoIogy Sludenl Services Officer al your
nearesl camus.
Study
Guide
1
Introduction to
Computer Systems
LEARNING OBJECTIVES
Al lhe comIelion of lhis sludy guide you viII be abIe lo:
use and undersland a vocabuIary of lerms associaled vilh
comulers,
Iisl and describe lhe comonenls of a generaI urose comuler
syslem, incIuding CIU, memory and Inul-Oulul devices,
areciale lhe rough lime Iine and hislory of lhe deveIomenl
of lhe digilaI comuler,
undersland lhe comonenls of lhe basic von Neumann modeI
of a comuler syslem and lhe imorlanl issues in ils oeralion,
areciale a viev of lhe underIying siIicon comonenls lhal
encomasses severaI Iayers of abslraclion as an aid lo
underslanding lhe hardvare/soflvare oeralion of lhe syslem
as a vhoIe,
undersland lhe imorlance of various numbering syslems lo a
sludy of digilaI comuler syslems,
describe lhe melhods used for dala conversion belveen ma|or
number syslems, decimaI, binary and hexadecimaI,
demonslrale decimaI, binary and hexadecimaI conversions.
FIT1001 Computer Systems
2
Contents
1.1 Inlroduclion
1.2 Comonenls of a Comuler
1.3 TerminoIogy and }argon
1.4 Hislory of Comuler TechnoIogy: Generalions of Comulers
1.5 Layered Archileclure
1.6 ModeI of Comuler Slruclure: Von Neumann Archileclure
1.7 AnaIog-vs-DigilaI, A-lo-D/D-lo-A Conversion
1.8 Overviev of Number Syslems
Reading
Prescribed readings
NuII and Lobur, !""#$%&'(" *+ ,*-./%#0 102'$&3'%&*$ 4 5067&%#6%/0#8
Chaler 1: Inlroduclion
Chaler 2: Dala Reresenlalion in Comuler Syslems
Study Guide 1: Introduction to Computer Systems
3
1.1 Introduction
WeIcome lo your firsl sludy guide. To slarl lhis session il is recommended
lhal you read lhe inlroduclory maleriaI al lhe slarl of lhis Unil ook. This
maleriaI rovides imorlanl informalion lhal you viII need lo read and
execule in order lo comIele lhe Sludy Guides in lhis Unil ook. IIease do
lhis nov if you have nol aIready done so. If you have, read on.
This session is viII inlroduce you lo a number of imorlanl concels lhal
viII be covered in delaiI during Ialer sludy guides.
1.2 Components of a Computer
A comuler is a rogrammabIe machine. A prngram is a coIIeclion or
sequence of inslruclions lo vhich a comuler viII resond in a veII-
defined manner. Irograms erform lasks by foIIoving aIgorilhms. An
a!gnrithm is a sel of sles lhal define hov a lask is erformed.
CoIIecliveIy, rograms (and lhe aIgorilhms lhey encode) are knovn as
snItwarc. The hysicaI comonenls uon vhich a rogram execules are
knovn as hardwarc.
In raclice, comulers execule rograms by foIIoving lhese lhree
funclions:
1) Input Iirsl, data, or rav unrocessed facls, are fed inlo lhe
comuler as input. Nolice lhal here dala is a generaI lerm
and incIudes bolh lhe numbers needing lo be rocessed and
lhe rogram lhal describes lhe required rocessing. The
inul is accumuIaled in a stnragc unil.
2) Prnccss The comuler viII lhen prnccss lhe inul numbers using
IogicaI and malhemalicaI oeralions. This is knovn as
prngram cxccutinn, lhe inul numbers are rocessed in
accord vilh a sequence of inslruclions (lhe rogram).
During rocessing, stnragc may be needed lo lemorariIy
hoId lhe resuIls of various caIcuIalions.
3) Output The comuler lhen relurns lhe rocessed informalion as
nutput.
FIT1001 Computer Systems
4
This Inul-Irocess-Oulul modeI of comuling is iIIuslraled beIov:
Fig 1.2.1 Input-Output Mndc!
In lhis modeI, dala is enlered as inul, some rocessing occurs (using
slorage as necessary) and informalion is lhen avaiIabIe as oulul. The
hysicaI comonenls necessary lo suorl lhe inul-rocess-oulul
modeI of comuling are:
Inul devices Input dcviccs are resonsibIe for lransmilling dala from
lhe exlernaI environmenl lo lhe comuler in a form lhe
comuler can readiIy undersland. You are aIready
famiIiar vilh many examIes of inul devices:
keyboard, mouse, scanner, elc.
CenlraI
Irocessing
Unil
(or CIU)
The CPU is lhe hearl of lhe comuler as il erforms aII
lhe rocessing done by lhe machine. Il execules
inslruclions read from a slored rogram. The CIU has
four ma|or comonenls:
Cnntrn! unit: 0#".*$"&9(# +*0 *067#"%0'%&$2 '(( '6%&*$" *+ %7#
,:; /$&% &%"#(+ '$< 7#$6# %7# 6*-./%#0 '" ' =7*(#>
Arithmctic and Lngic Unit (ALU): 0#".*$"&9(# +*0 '6%/'((?
.#0+*0-&$2 %7# '0&%7-#%&6 '$< (*2&6'( *.#0'%&*$" %7'% '0#
0#@/&0#< %* 6'00? */% #'67 ,:; &$"%0/6%&*$>
Rcgistcrs: +'"% (*6'( "%*0'2# +*0 A'(/#" 6/00#$%(? 9#&$2
=*0B#< *$ 9? %7# 5C;D *0 $/-9#0" $##<#< +*0 *.#0'%&$2 %7#
,:; &%"#(+>
Intcrna! Buscs: .'%7='?" $##<#< %* -*A# A'(/#" 9#%=##$ %7#
"#% *+ 0#2&"%#0"D *0 9#%=##$ ' 0#2&"%#0 '$< %7# 5C;E
Slorage 5tnragc, or memory, is used lo lemorariIy or
ermanenlIy slore rograms and dala. Primary stnragc
refers lo lhe "on-board" or semiconduclor memory of a
Study Guide 1: Introduction to Computer Systems
5
comuler. 5ccnndary stnragc refers lo devices for Iong
lerm slorage of rograms and dala. IxamIes are, hard
disk drives (HDDs), comacl disks (CDs), digilaI
versaliIe disks (DVDs), magnelic laes.
Oulul
devices
Output dcviccs lransmil informalion from lhe comuler
lo lhe exlernaI environmenl in a form eoIe can
undersland. IxamIes are, video disIays, rinlers,
seakers, Iollers, elc.
CoIIecliveIy inul and oulul devices, slorage and lhe CIU comrise lhe
rimary hysicaI comonenls lhal make u a digita! cnmputcr. Many of
lhe vorId's comuler syslems in facl send reIaliveIy IillIe lime
inleracling vilh human beings and lheir Inul/Oulul aclivilies are
mainIy "laIking" lo olher comulers, various eIeclronic circuils, or
assorled mechanicaI machinery.
1.3 Terminology and Jargon
DigilaI comulers can onIy rocess informalion lhal is exressed as a
sequence of digils. Non-numericaI lyes of informalion are converled inlo
allerns of digils using various forms of numericaI coding schemes. This
loic viII be inlroduced Ialer in lhis Sludy Guide, and covered in far more
delaiI in Sludy Guide 2.
To reresenl and maniuIale our famiIiar base len numbers using
eIeclricaI signaIs is difficuIl. This is due lo bolh lhe need lo have len
dislincl signaI IeveIs and aIso lhe Iarge number of ruIes needed lo do
decimaI arilhmelic. y far lhe besl number syslem lo use is lhe binary (or
base lvo) number syslem. This number syslem aIIovs onIy lhe lvo digil
vaIues 0 and 1. A digil in lhis syslem is lermed a bit (slanding for binary
digit). ils are very easy lo reresenl using eIeclricaI signaIs, as ve need
onIy lvo IeveIs. Tvo IeveIs of eIeclric voIlage is lhe mosl common vay,
aIlhough lvo IeveIs of eIeclric currenl are aIso used for some aIicalions.
ils may aIso be easiIy reresenled in various non-eIeclric vays such as
using lvo dislincl IeveIs of magnelic fieId or olicaI refIeclance.
IIeclronic circuils lo maniuIale, slore, and erform arilhmelic on binary
vaIues are covered in Sludy Guide 3. This area is caIIed digilaI eIeclronics.
The lerm digilaI Iogic circuil is aIso commonIy used. This calures
FIT1001 Computer Systems
6
anolher asecl of comuling vhere eIeclronic circuils make IogicaI
decisions based on eIeclric signaIs lhal reresenl lhe vaIues truc and Ia!sc.
To reresenl ilems lhal may have a Iarger range of vaIues, ve use a grou
of bils. One very common grouing lhal deveIoed earIy in lhe hislory of
comuling is caIIed a bytc and is comosed of 8 bits. The 256 ossibIe bil
allerns of a byle aIIov a fuII sel of aIhabelic and numericaI characler
shaes lo be reresenled by using one bil allern or code lo reresenl
each lexl characler. Through ils common usage as a fundamenlaI unil in
lexl fiIes, lhe byle remains lhe slandard base unil for measuring of size
of rograms and eIeclronic fiIes of aII sorls as veII as lhe caacily of a
comuler's main memory.
Rcad NuII and Lobur, chaler 1, ages 4 (from 1.3) -10 (lo 1.4)
1.4 History of Computer Technology
You may lhink lhal lhe hislory of comulers is fairIy shorl. In facl vhiIe
modern comulers (as ve knov lhem loday) have onIy been around for
50 or so years bul lhe acluaI hislory of comulers can be lraced lo lhe
1600's. Irom lhis lime onvards names such as Naier, Schikard, IascaI,
von Leibniz, aggage, ooIe, HoIIerilh and Zuse aII conlribuled, direclIy
or indireclIy, lo modern day comulers. Comulers before lhe mid 1940's
vere mechanicaI and designed rimariIy lo do one lask.
One viev of lhe hislory of modern comulers is lhal of lheir lechnoIogicaI
evoIulion. U lo lhe resenl day five generalions of modern comulers
can be differenlialed. These generalions are summarised as foIIovs vilh
lhe range of years lhey cover and lheir ma|or dislinguishing
characlerislics:
Gcncratinn Tcchnn!ngica! Evn!utinn
Irehislory (1650-1945) MechanicaI gears
Iirsl generalion (1945-1953) Vacuum lubes
Second generalion (1954-1965) Transislors
Third generalion (1965-1970) Inlegraled circuils (ICs)
Iourlh generalion (1971-resenl) Microrocessors or very Iarge-
scaIe inlegralion (VLSI)
Study Guide 1: Introduction to Computer Systems
7
Iiflh generalion (fulure) ArlificiaI inleIIigence, quanlum
comuling, nanolechnoIogy,
naluraI Ianguage
Rcad NuII and Lobur, chaler 1, ages 12 (from 1.5) -25 (lo 1.6)
1.5 Layered Architecture
A digilaI comuler is a very comIex device comrised of a mixlure of
bolh hardvare and soflvare comonenls. A heIfuI looI lo avoid being
overvheImed by lhe comuler's comIexily is lo viev ils organizalion as
a number of Iayers, vilh each Iayer reresenling a more abslracl and Iess
delaiIed viev of aII lhe Iayers benealh lhal one.
A comuler is imIemenled by slarling vilh a semiconduclor base
maleriaI (usuaIIy SiIicon) and forming on lhis surface a coIIeclion of u lo
severaI lens of miIIions of minule eIeclronic comonenls, mosl of vhich
are caIIed lransislors. This is lhe Iovesl or so caIIed physica! !aycr and is
exlremeIy comIex in ils design. Hovever ve find lhal from an
oeralionaI oinl of viev, lhe miIIions of lransislors can be cIuslered inlo
grous lhal are caIIed digilaI Iogic gales. These have veII defined inul
and oulul behaviours lhal can be exressed in lerms of binary signaI
IeveIs. To discuss lhe oeralion of lhe comuler al lhis Iogic gale IeveI,
ve onIy need lo knov vhal lhe gales do, and nol hov lhe gales are
conslrucled lo behave in lhis vay. As a refinemenl of lhe viev of lhis
digita! !ngic !aycr, ve may see lhe Iogic gales lhemseIves are cIuslered
logelher lo form numerous Iogic gale circuils or Iogic bIocks.(!2 0#2&"%#0
9(*6B"D <#6*<#0 9(*6B"D '$ 5C;D #%6E). Iach of lhese unils has a cIear and veII
defined funclion. We can discuss lhe oeralion of lhe comuler on lhis
IeveI by knoving lhe oeralion of lhe bIocks vilhoul knoving lhe delaiIs
of exaclIy hov lhey are conslrucled.
The nexl higher IeveI of abslraclion is oflen caIIed lhe cnntrn! !aycr. Al
lhis IeveI lhe fIov of signaIs is in grous of bils lhal are moved belveen
regislers or have various oeralions done on lheir vaIues. Comuler
oeralion al lhis IeveI is usuaIIy exressed in lerms of microoeralions,
each of vhich Iays some smaII arl in execuling a comIele rocessor
inslruclion. The nexl IeveI u is usuaIIy lermed lhe machinc !cvc! and is
lhe lo hardvare IeveI. We viev lhis IeveI has forming a machine lhal is
caabIe of felching, decoding, and execuling lhe coded machine
FIT1001 Computer Systems
8
inslruclions lhal are resenl in lhe memory unil as lhe finaI execulabIe
form of lhe comuler's rogram.
Silling above lhe hardvare Iayers are severaI soflvare Iayers beginning
vilh lhe oeraling syslem code and ils Iibraries. This is recomiIed
soflvare and is in lhe form of machine inslruclion codes. The nexl IeveI
of abslraclion u from machine code is asscmb!y !anguagc. Here lhe
CIU's machine inslruclions are reresenled in a more or Iess human
readabIe form using lexl characlers lo form shorl inslruclion names caIIed
mnemonics. Regisler names, numericaI vaIues and seciaI symboIs aIso
used in lhe Ianguage. Iach CIU lye has ils ovn arlicuIar assembIy
Ianguage aIlhough many of lhese Ianguages are broadIy simiIar.
Irograms vrillen in an assembIy Ianguage need lo be assembIed (and
ossibIy Iinked) before lhey can be execuled. A rime ob|eclive of lhis
unil is for you lo become famiIiar vilh lhe assembIy IeveI, lhe machine
IeveI, and lhe conlroI IeveI of oeralion of a smaII reresenlalive
comuler.
Rcad NuII and Lobur, chaler 1, ages 25 (from 1.6) -27 (lo 1.7)
Nole lhal many olher lexls have a four Iayered modeI of lhe
hardvare: .7?"&6'( ('?#0D <&2&%'( (*2&6 ('?#0D 6*$%0*( ('?#0 '$< %7#
-'67&$# ('?#0E Iigure 1.3 on age 26 is consislenl vilh lhis in lhal
il shovs onIy lhe abslraclions above lhe hysicaI Iayer. Hovever
lhe lexl al lhe end of lhe seclion faiIs lo adequaleIy dislinguish
lhe digilaI Iogic Iayer from lhe hysicaI comonenl Iayer.
1.6 Model of Computer Structure
Many modern comuler archileclures are based on lhe von Neumann
modeI afler lhe Hungarian born malhemalician }ohn von Neumann. A
cenlraI Iank in lhis modeI is lhal a bolh lhe dala lo be rocessed and lhe
coded inslruclions lhal define lhe rocessing aIgorilhm (or rogram), are
Iaced vilhin lhe same memory unil. There is no marker lo dislinguish a
dala code from an inslruclion code so lhe lvo grous of codes are kel in
searale regions of lhe memory vhich are dislinguishabIe by lheir
addresses. The CIU is equied vilh a seciaI regisler lhal hoIds lhe
memory address of lhe nexl byle of lhe rogram code lhal needs lo be
felched. In many machines lhis CIU regisler is caIIed lhe prngram cnuntcr
(PC). In CIU designs roduced by lhe InleI cororalion il is knovn as lhe
instructinn pnintcr, a name vhich more accuraleIy refIecls ils roIe.
Study Guide 1: Introduction to Computer Systems
9
The vires lhal convey lhe binary inslruclion and dala codes belveen lhe
memory and lhe CIU are knovn as a bus. Somelimes lhe lerm data bus is
used even lhough of lhe ma|orily of lhe codes being carried by lhis bus
viII be inslruclion codes ralher lhan dala codes. Never lhe Iess, lhis name
dislinguishes lhis bus from anolher grou of vires knovn as lhe addrcss
bus. This bus is used by lhe CIU lo signaI lhe memory unil reciseIy
vhich memory Iocalion il vishes lo access. A lhird grou of vires,
knovn as lhe cnntrn! bus, carries various signaIs lo conlroI differenl arls
of lhe comuler. IncIuded here is a signaI lo inform lhe memory unil
vhelher lhe addressed Iocalion is being read from or vrillen lo.
A CIU runs a rogram by reealedIy cycIing lhrough a rocess knovn
as lhe Ictch-dccndc-cxccutc cycIe. In lhe felch hase, lhe CIU uses lhe
vaIue in ils rogram counler lo address a nev inslruclion in memory and
lhen erform a memory read. The rogram counler vaIue is lhen
incremenled. The felched informalion is Iaced in lhe CIU's instructinn
rcgistcr (IR). Some CIUs viII felch lhe enlire inslruclion vhiIe olhers may
onIy felch lhe firsl arl of il.
The decode hase uses digilaI Iogic circuils lo anaIyse lhe bil allern in
lhe inslruclion regisler inlo differenl fieIds. TyicaIIy lhe bil allern in
one fieId mighl idenlify lhe oeralion lo be erformed vhiIe lhe bil
allerns of lhe remaining fieIds viII idenlify hov lhe CIU is lo oblain lhe
vaIues lo be oeraled on. These vaIues are caIIed npcrands. An oerand
mighl be heId vilhin lhe inslruclion ilseIf, or heId in a secified regisler,
or heId in a secified memory Iocalion, or ils vaIue may be inherenlIy
knovn for lhal oeralion lye.
The execulion hase is resonsibIe for coIIecling lhe oerands and
deIivering lhem lo lhe ALU so lhe coded oeralion may occur. This hase
may invoIve addressing memory lo Iocale an oerand. Where lhis occurs,
lhe CIU may eilher use an address incIuded in lhe Ialer arl of lhe
inslruclion, or il may comule lhe address using a hardvare aIgorilhm
idenlified by some bils in lhe inslruclion. The resuIl of lhe oeralion may
be relurned lo a secified regisler, or be vrillen lo a Iocalion in main
memory, or erhas an oulul device.
Al lhe end of lhe execulion hase lhe rogram counler viII normaIIy be
hoIding lhe address of lhe nexl inslruclion in lhe rogram. An excelion
lo lhis is if lhe inslruclion ilseIf has modified lhe vaIue in lhe rogram
counler. Inslruclions lhal eilher modify lhe rogram counler's vaIue, or
inslaII a comIeleIy nev vaIue, are caIIed branchcs and |umps. They are
used for rogram fIov conlroI.
FIT1001 Computer Systems
10
One unforlunale consequence of lhe von Neumann archileclure is lhal a
serious bollIeneck is crealed al lhe dala bus because aII lhe inslruclions
and dala musl fIov lhrough lhal ie. AIlhough bus seeds have
increased significanlIy over lhe years, so have CIU and memory seeds
so lhe von Neumann bollIeneck robIem remains an issue. The use of
vide dala buses and smaII bul high seed cache memories is a common
aroach lo aIIevialing lhis robIem.
An aIlernale archileclure knovn as lhe Harvard architccturc is used in
some syslems. Il kees lhe inslruclions and dala in lolaIIy searale
memories and aIIovs simuIlaneous access lo inslruclions and dala
lhrough searale buses. WhiIe lhis arrangemenl does aIIov some
erformance gains, lhe convenience of a singIe mechanism for Ioading
rograms and dala from secondary slorage has kel lhe von Neumann
aroach ouIar.
Rcad NuII and Lobur, chaler 1, ages 27 (from 1.7) - 29 (lo 1.8)
1.7 Analog vs Digital representation
A signaI is carried on a communicalion channeI as an eIeclricaI voIlage, an
eIeclromagnelic radio vave, or a svilched Iighl. Iigure 1.7.1 deicls a
communicalion channeI. Dala is reresenled by changes in signaI as a
funclion of lime. Dala and signaIs can be anaIog or digilaI. Dala is vhal
ve vanl lo lransmil. SignaIs are vhal ve use lo lransmil lhe dala.
IxamIes of dala incIude: comuler fiIes, movie on a DVD, music on a
comacl disc, elc. IxamIes of signaIs incIude: leIehone conversalion
over a leIehone Iine, Iive leIevision nevs inlerviev from Iuroe, veb
age dovnIoad over your leIehone Iine via lhe Inlernel, elc.
Figurc 1.7.1 Cnmmunicatinn Channc!
The signaI may lake on a conlinuous range of vaIues, in vhich case il is
knovn as an ana!ng signaI, or il can lake on onIy discrele vaIues, in vhich
case il is knovn as discrctc signaI. A 9&$'0? discrele signaI is usuaIIy
Study Guide 1: Introduction to Computer Systems
11
caIIed a digita! signaI. Iigure 1.7.2 shovs an anaIog signaI and a digilaI
signaI. A signaI shovn as a funclion of lime is caIIed a wavcInrm.
Figurc 1.7.2 Ana!ng and Digita! WavcInrms
Comuler dala is digilaI in nalure. A digilaI vaveform may reresenl a
sequence of bils of dala on a bus Iine, for examIe. Sound is anaIog. The
Ioudness of sound coming from a slereo seaker vouId be reresenled by
a conlinuousIy changing anaIog vaveform.
Il is oflen desirabIe lo be abIe lo converl a digilaI signaI lo some
equivaIenl anaIog reresenlalion or vice versa. Ior examIe, anaIog sound
is slored digilaIIy on a comacl disc. ConverseIy, lo lransmil comuler
dala on an ordinary voice-grade hone Iine requires lhal lhe comuler
dala musl be reresenled by an anaIog signaI, since lhe hone Iine is
designed lo carry sound. IdeaIIy, lhe lransformalion belveen digilaI and
anaIog shouId be reversibIe. In raclice, aII syslems, bolh digilaI and
anaIog, are sub|ecl lo noise, allenualion, and dislorlion, and il is oflen
necessary lo rovide comensalion in lhe form of error correclion. When
anaIog dala is converled lo digilaI form, a smaII amounl of informalion is
Iosl during lransformalion, and il is nol ossibIe lo recover lhe originaI
anaIog vaveform exaclIy, aIlhough lhe error can be reduced lo lhe oinl
lhal il doesn'l maller.
In order lo converl anaIog dala lo digilaI, anaIog vaveform is samIed al
reguIar lime inlervaIs, as shovn in Iigure 1.7.3. The maximum ossibIe
amIilude of lhe vaveform is divided inlo inlervaIs corresonding lo a
range of binary numbers. Ior examIe, 256 IeveIs require 8 bils er
samIe.
Figurc 1.7.3 Thc A-tn-D Cnnvcrsinn Prnccss
FIT1001 Computer Systems
12
SamIed vaIues are each converled inlo lheir corresonding number
vaIue. The device lhal erforms lhis conversion is caIIed an A-tn-D
cnnvcrtcr, or ADC. The device vhich converls digilaI dala lo anaIog is
caIIed a D-tn-A cnnvcrtcr or DAC.
1.8 Number Systems
Numbers are reresenled in binary form in (mosl) comulers, vhiIsl
humans use decimaI arilhmelic. To be abIe lo undersland binary
reresenlalion of dala, ve musl be abIe lo reIale lo numbers ve are
famiIiar vilh. Numbers in binary form are difficuIl for humans lo deaI
vilh, hovever, ve find lhal il is easy lo converl belveen binary and
hexadecimaI numbers. Ior lhis course, ve vanl lo be abIe lo use lhe
Ianguage of hexadecimaI and binary arilhmelic vilh confidence lhal
sludenls viII undersland.
The foIIoving discussions have been made deIiberaleIy quile reelilive.
The inlenlion here is lo emhasise lhe simiIarily of ideas and lechniques
lhal are used in lhe differenl number syslems.
These noles discuss:
Number Syslems: Arilhmelic in Differenl ases.
The DecimaI syslem, radix 10, uses 10 digils (symboIs): 0 1 2 3 4 5 6
7 8 9
DecimaI Iraclions
Scienlific Nolalion (DecimaI)
The inary syslem: OnIy 2 digils: 0 1
inary Iraclions
The HexadecimaI syslem: 16 digils: 0 1 2 3 4 5 6 7 8 9 A C D I I
HexadecimaI Iraclions
Number Systems: Arithmetic in Different Bases
Humans counl in muIliIes of 10 and overs of 10 because lhey have 10
fingers. We use base 10 arilhmelic. These noles discuss base-10
arilhmelic, base-2 arilhmelic, and base-16 arilhmelic.
AIlhough comulers moslIy reresenl numbers in binary form, humans
refer lo use lhe hexadecimaI equivaIenl of binary numbers as a kind of
Study Guide 1: Introduction to Computer Systems
13
shorlhand il is cIoser lo decimaI reresenlalion, and uses 75% fever
digils lhan binary.
Radix is an aIlernalive lerm for ase. We can use lhe lerms decimaI
oinl and radix oinl inlerchangeabIy. GeneraIIy ve vouId say radix
oinl ralher lhan binary oinl or hexadecimaI oinl lo indicale lhe
marker lhal searales lhe inleger arl of a number and ils fraclionaI arl.
The Decimal system
This has radix 10, i.e., il uses 10 digils (symboIs): 0 1 2 3 4 5 6 7 8 9
IxamIe:
4792 4 1000 + 7 100 + 9 10 + 2 1
4 10
3
+ 7 10
2
+ 9 10
1
+ 2 10
0
Nole: lhe overs of 10 increases from righl lo Iefl. The size of lhe quanlily
reresenled by each digil deends on lhe osilion of lhe digil in lhe
number. So slarling from lhe righl, and counling uvards beginning al 0,
ve gel lhe successive overs of 10.
The Mosl Significanl Digil (MSD) is on lhe Iefl, and lhe Leasl Significanl
Digil (LSD) is on lhe righl.
We read and vrile from Iefl lo righl, and lhus ve encounler lhe more
imorlanl informalion firsl.
Nolalion: We vrile: 479210 lo indicale lhe decimaI (base 10) syslem.
A simIe aIgorilhm vhich viII give us lhe successive digils of a decimaI
inleger X, slarling from lhe righl hand end is as foIIovs:
ReealedIy,
Gel lhe remainder from dividing X by 10,
Divide X by 10,
unliI X is zero.
Ior examIe, if X is 4792, lhe rocess viII be reealed four limes.
Iirsl, ve gel lhe remainder 2, and X becomes 479.
FIT1001 Computer Systems
14
Second, ve gel lhe remainder 9, and X becomes 47.
Third, ve gel lhe remainder 7 and X becomes 4.
Iourlh, ve gel lhe remainder 4, and X is reduced lo zero.
The digils 2, 9, 7, 4 have been generaled, from righl lo Iefl, in succession.
Decimal Fractions
Iovers of 10 are again imIicil vhen ve vrile a decimaI fraclion,
decreasing (becoming more negalive), from Iefl lo righl. Ior examIe:
0.5803 5 / 10 + 8 / 100 + 0 / 1000 + 3 / 10000
5 10
--1
+ 8 10
-2
+ 0 10
-3
+ 3 10
-4
Nov, a simIe aIgorilhm vhich viII give us lhe successive digils of a
decimaI fraclion X, slarling from lhe Iefl hand end is as foIIovs:
ReealedIy,
MuIliIy X by 10,
Remove lhe digil on lhe Iefl on lhe decimaI oinl.
Nole lhal vhen deaIing vilh fraclions, ve nov generale lhe digils from
Iefl lo righl (nol righl lo Iefl). The rocess differs in a number of vays
from lhal discussed above for converling vhoIe numbers. Ior examIe,
suose X 0.5803, and aIso lhal ve vanl lhe firsl five digils.
1
sl
ileralion: X 5.803 Remove lhe digil 5, X becomes 0.803,
2
nd
ileralion: X 8.03 Remove lhe digil 8, X becomes 0.03,
3
rd
ileralion: X 0.3 Remove lhe digil 0, X becomes 0.3,
4
lh
ileralion: X 3.0 Remove lhe digil 3, X becomes 0.0,
5
lh
ileralion: X 0.0 Remove lhe digil 0, X becomes 0.0.
We have oblained five successive digils 5, 8, 0, 3, 0.
Scientific Notation (Decimal)
Many simp!c 'ratinna! Iractinns' have non-lerminaling (reealing)
decimaI exansions:
82 / 3 27.33333 33333 33333 33333 33333 (aroximaleIy).
Study Guide 1: Introduction to Computer Systems
15
Many numbcrs arc irratinna!, i.e. cannol even be reresenled as ralionaI
fraclions:
3.1415 92653 58979 32384 62643 (aroximaleIy).
2 1.4142 13562 37309 50488 (aroximaleIy).
e
10
22026.46579 48067 16516 9579 (aroximaleIy).
Such numbers are usuaIIy adequaleIy aroximaled using fever
significanl figures.
5nmc numbcrs arc vcry !argc: Avogadro's conslanl (lhe number of
moIecuIes in 22.421 Iilres of gas al NormaI lemeralure and ressure) is
aroximaleIy 602,252,000,000,000,000,000,000.
5nmc numbcrs arc vcry sma!!: The resl mass (veighl) of an eIeclron is
aroximaleIy
0.000,000,000,000,000,000,000,000,000,000,910,91 Kg.
Il is difficuIl for humans immedialeIy lo comrehend lhe size of lhese
very Iarge and very smaII numbers.
F6&#$%&+&6 $*%'%&*$, used mainIy by scienlisls and engineers, aIIovs us lo
reresenl numbers convenienlIy (oflen as an aroximalion), and lo be
abIe lo see immedialeIy |usl hov big or smaII a number is.
The slandard form is d0.d1d2d3d4d5d6d7d8d9 10
E
(bul nole lhal lhere can
be any number of digils). Here, d0, d1, d2, ..., d9 are decimaI digils. I is an
inleger, caIIed lhe Ixonenl of 10, i.e. lhe over lo vhich 10 is raised.
There can be a Ieading minus sign. The ruIes for lhis slandard form are:
1. UnIess lhe number is zero, lhe digil d0 on lhe Iefl of lhe decimaI oinl
musl be a non-zero digil,
i.e. 1, 2, ..., 9.
2. There musl be exaclIy one non-zero digil d0 before lhe decimaI oinl.
These ruIes ensure lhal everybody viII vrile numbers in lhe same vay
(excel erhas for lhe number of significanl figures used).
Ior lhe numbers given in lhe examIes above, ve vouId vrile, lyicaIIy,
82 / 3 2.7333333333 10
1
3.141592 10
0
2 1.414213562 10
0
FIT1001 Computer Systems
16
e
10
2.20264658 10
4
Avogadro's conslanl 6.02252 10
23
IIeclron mass 9.1091 10
-31
Kg
Nolice lhal in lhis nolalion ve have lo vrile %=* numbers lhal leII us
differenl lhings:
E, lhe over of 10, is caIIed lhe #G.*$#$%. Il can be osilive, negalive or
zero. The exonenl I leIIs us aboul lhe "&3# of lhe number.
d0.d1d2d3d4d5d6d7d8d9 is oflen caIIed lhe -'$%&""' or "&2$&+&6'$<. Il shovs us
lhe fine delaiI informalion.
IxamIes of incorrecl usage are:
0.01234 10
56
shouId be 1.234 10
54
. The digil before lhe decimaI
oinl -/"% $*% be a 0.
1234.567 10
89
shouId be 1.234567 10
92
. There are four digils, nol
#G'6%(? *$#D before lhe decimaI oinl.
Il is imorlanl lo undersland lhe formal of scienlific nolalion, because lhe
same concels are used in a comuler lo reresenl reaI numbers (binary
inslead of decimaI). This is knovn as fIoaling oinl reresenlalion.
The Binary System
This has radix 2, i.e., uses onIy 2 digils: 0 1
IxamIe:
101011 1 32 + 0 16 + 1 8 + 0 4 + 1 2 + 1 1
1 2
5
+ 0 2
4
+ 1 2
3
+ 0 2
2
+ 1 2
1
+ 1 2
0
Iovers of 2 increase from righl lo Iefl.
The Mosl Significanl Digil is on lhe Iefl, and lhe Leasl Significanl Digil is
on lhe righl.
Nolalion: Wrile 1010112 lo indicale lhe binary (base 2) syslem.
Cnnvcrsinn bctwccn dccima! and binary systcms:
1010112 1 32 + 0 16 + 1 8 + 0 4 + 1 2 + 1 1
Study Guide 1: Introduction to Computer Systems
17
32 + 0 + 8 + 0 + 2 + 1
4310
An aIgorilhm simiIar lo lhal given above viII give us lhe successive
binary digils of a decimaI inleger X, slarling from lhe righl-hand end, as
foIIovs:
ReealedIy,
Gel lhe remainder from dividing X by 2 (il viII be 0 or 1),
Divide X by 2,
unliI X is zero.
Ior examIe, if X 4310 1010112 lhe rocess viII be erformed 6 limes.
The digils 1, 1, 0, 1, 0, 1 viII be generaled, from righl lo Iefl, in
succession.
1
sl
ileralion: Digil 1 43 / 2 gives X 21
2
nd
ileralion: Digil 1 21 / 2 gives X 10
3
rd
ileralion: Digil 0 10 / 2 gives X 5
4
lh
ileralion: Digil 1 5 / 2 gives X 2
5
lh
ileralion: Digil 0 2 / 2 gives X 1
6
lh
ileralion: Digil 1 1 / 2 gives X 0
Here, lhe successive divisions by 2 shov lhal:
43 2 21 + 1
2 (2 10 + 1) + 1
2 (2 (2 5 + 0) + 1) + 1
2 (2 (2 (2 2 + 1) + 0) + 1) + 1
2 (2 (2 (2 (2 1 + 0) + 1) + 0) + 1) + 1
Nole lhe binary digils: 1 0 1 0 1 1
y examining lhe 2s lhal are muIliIying oulside lhe brackels, you can
vork oul lhe over of 2 vhich muIliIies each binary digil: 2
5
2
4
2
3
2
2
2
1
2
0
1 0 1 0 1 1
Pnwcrs nI 2
In lhis course, you viII find il vorlhvhiIe lo memorise lhe foIIoving
numbers:
FIT1001 Computer Systems
18
2
0
1 2
1
2 2
2
4 2
3
8
2
4
16 2
5
32 2
6
64 2
7
128 2
8
256
Binary Fractions
y anaIogy vilh decimaI fraclions (invoIving descending negalive overs
of 10), binary fraclions invoIve descending negalive overs of 2.
0.1010112 1 / 2 + 0 / 4 + 1 / 8 + 0 / 16 + 1 / 32 + 1 / 64
1 2
-1
+ 0 2
-2
+ 1 2
-3
+ 0 2
-4
+ 1 2
-5
+ 1 2
6
(converling lo decimaI)
0.5 + 0 + 0.125 + 0 + 0.03125 + 0.015625
0.67187510
43 / 64, as vouId be execled from lhe revious
discussion.
Cnnvcrting a dccima! Iractinn tn a binary Iractinn. This aIgorilhm viII
oblain lhe successive binary digils of a decimaI fraclion, slarling al lhe big
end (on lhe Iefl, |usl afler lhe radix (decimaI) oinl):
Il is essenliaIIy lhe same as lhal for lhe decimaI syslem.
Nov, a simIe aIgorilhm vhich viII give us lhe successive digils of a
decimaI fraclion X, slarling from lhe Iefl-hand end, is as foIIovs:
ReealedIy,
MuIliIy X by 2,
Remove lhe (binary) digil on lhe Iefl on lhe decimaI oinl.
eIov, ve check lhal lhe decimaI fraclion oblained above gives lhe
execled binary fraclion exansion.
We shaII find lhe fisl seven binary digils
IniliaIIy, X 0.671875
1
sl
ileralion: X 1.34375 Digil 1 X becomes 0.34375
2
nd
ileralion: X 0.6875 Digil 0 X becomes 0.6875
3
rd
ileralion: X 1.375 Digil 1 X becomes 0.375
4
lh
ileralion: X 0.75 Digil 0 X becomes 0.75
5
lh
ileralion: X 1.5 Digil 1 X becomes 0.5
6
lh
ileralion: X 1.0 Digil 1 X becomes 0.0
7
lh
ileralion: X 0.0 Digil 0 X becomes 0.0
Study Guide 1: Introduction to Computer Systems
19
As execled, lhe rocess has generaled successive binary digils 1, 0, 1, 0,
1, 1, 0.
Annthcr cxamp!c:
Nov Iel lhe decimaI fraclion X 0.7 7 / 10 (a very simIe decimaI
fraclion).
This lime, Iel NrWanledDigils 10, i.e. ve roose lo oblain 10 successive
binary digils.
IniliaIIy, X 0.7
1
sl
ileralion: X 1.4 Digil 1 X becomes 0.4
2
nd
ileralion: X 0.8 Digil 0 X becomes 0.8
3
rd
ileralion: X 1.6 Digil 1 X becomes 0.6
4
lh
ileralion: X 1.2 Digil 1 X becomes 0.2
5
lh
ileralion: X 0.4 Digil 0 X becomes 0.4
6
lh
ileralion: X 0.8 Digil 0 X becomes 0.8
7
lh
ileralion: X 1.6 Digil 1 X becomes 0.6
8
lh
ileralion: X 1.2 Digil 1 X becomes 0.2
9
lh
ileralion: X 0.4 Digil 0 X becomes 0.4
10
lh
ileralion: X 0.8 Digil 0 X becomes 0.8
The rocess has generaled successive digils 1 0110 0110 0 lo give lhe
binary equivaIenl:
0.710 0.1 0110 0110 0110 01102 ......
Il is obvious lhal ileralions 6 lo 9 simIy reeal ileralions 2 lo 5, (and lhal
lhis rocess vouId conlinue indefinileIy if ve had nol reslricled lhe
number of digils), so lhal a 0#.#'%&$2 9&$'0? fraclion has been generaled.
There is nolhing very myslerious aboul lhis ve have aIready seen lhe
0#.#'%&$2 <#6&-'( fraclion
82 / 3 27.333333333333333 ...
Hovever il is imorlanl lo nole lhal a fraclion lhal can be reresenled
exaclIy in lhe decimaI syslem may have a reealing reresenlalion in lhe
binary syslem (bul lhe converse is nol lrue). This means lhal binary
comulers oflen inlroduce smaII round-off errors vhen sloring fraclionaI
quanlilies.
FIT1001 Computer Systems
20
Using lhe binary syslem is very ledious. inary is unmanageabIe for
humans. We lherefore nov Iook al lhe hexadecimaI syslem, vhich
rovides a very convenienl bridge belveen binary and decimaI.
The Hexadecimal System
This has radix 16, using 16 digils: 0 1 2 3 4 5 6 7 8 9 A C D I
I
Nolalion: Wrile 3CA816 lo indicale lhe hexadecimaI (base 16) syslem.
A16 1010 16 1110 C16 1210 D16 1310 I16 1410 I16
1510
HI7# "/9"60&.% JK &" 0'0#(? <&".('?#< *$ 7#G'<#6&-'( <&2&%" 5 L , M ! N '"
"##$ '9*A#E O% &" /"#< +*0 #G.('$'%*0? ./0.*"#" &$ %7#"# $*%#"PE
In lhe labIe beIov, lry lo recognise and memorise lhe allerns in lhe
coIumns of binary digils lhal are headed 8, 4, 2 and 1. You can easiIy vork
oul lhe binary equivaIenl of any number Iess lhan 16 by sIilling il inlo
lhese four vaIues.
DecimaI HexadecimaI inary
8 4 2 1
0 0 0 0 0 0
1 1 0 0 0 1
2 2 0 0 1 0
3 3 0 0 1 1
4 4 0 1 0 0
5 5 0 1 0 1
6 6 0 1 1 0
7 7 0 1 1 1
8 8 1 0 0 0
9 9 1 0 0 1
10 A 1 0 1 0
11 1 0 1 1
12 C 1 1 0 0
13 D 1 1 0 1
14 I 1 1 1 0
15 I 1 1 1 1
Dccima!, Hcxadccima! and Binary Equiva!cnts
Our immediale inleresl in lhis course is in converling belveen decimaI
and binary numbers. The Iesson lhal viII become aarenl is:
Dccima! /$-'$'2#'9(# Binary
Study Guide 1: Introduction to Computer Systems
21
Dccima! #'"? Hcxadccima! %0&A&'( Binary
An examIe of a hexadecimaI number:
3CA816 3 16
3
+ C 16
2
+ A 16
1
+ 8 16
0
3 4096 + 12 256 + 10 16 + 8 1
12288 + 3072 + 160 + 8
1552810
Again, overs of 16 increase from righl lo Iefl.
The Mosl Significanl Digil is on lhe Iefl, and lhe Leasl Significanl Digil is
on lhe righl.
Cnnvcrsinn bctwccn dccima! and hcxadccima! systcms:
ReealedIy,
Gel lhe remainder from dividing X by 16,
Divide X by 16,
unliI X is zero.
If X 1552810 lhe rocess viII be erformed 4 limes:
1
sl
ileralion: Digil 810 8 X 15528 / 16 970 (vilh 8 remainder)
2
nd
ileralion: Digil 1010 A X 970 / 16 60 (vilh 10 remainder)
3
rd
ileralion: Digil 1210 C X 60 / 16 3 (vilh 12 remainder)
4
lh
ileralion: Digil 310 3 X 3 / 16 0 (vilh 3 remainder)
The hexadecimaI digils 8, A, C, 3 have been generaled from righl lo Iefl,
in succession.
As a second examIe, ve converl 4310 lo hexadecimaI:
43 / 16 2 and 11 remainder. So 4310 216. }usl one division vas
required here.
Refer back lo lhe binary conversion discussion lo reviev hov much efforl
vas required for lhe decimaI lo binary conversion 4310 lo 1010112 - six
oeralions.
Nov consider 216 , and vrile lhe hexadecimaI digils in binary:
FIT1001 Computer Systems
22
2 (hex) 0010 (binary)
(hex) 1011 (binary)
So 0010 10112 216 4310 and il can be seen lhal lhe binary
reresenlalion of 4310 has been very quickIy oblained by using lhe
hexadecimaI syslem as a haIfvay house.
SimiIarIy, for 1552810 3CA816, lhe binary reresenlalion is oblained as
0011 1100 1010 10002 .
Hexadecimal Fractions
Again by anaIogy vilh decimaI fraclions, hexadecimaI fraclions invoIve
negalive overs of 16.
0.3CA816 3 / 16 + 12 / 256 + 10 / 4096 + 8 / 65536
3 16
-1
+ 12 16
-2
+ 10 16
-3
+ 8 16
-4
0.1875 + 0.046875 + 0.00244140625 + 0.0001220703125
0.23693 84765 62510
15528/65536, as vouId be execled from lhe revious
discussion.
Cnnvcrting a dccima! Iractinn tn a hcxadccima! Iractinn. This aIgorilhm
viII oblain lhe successive hexadecimaI digils of a decimaI fraclion,
slarling al lhe big end (on lhe Iefl, |usl afler lhe radix (decimaI) oinl). As
before, il is simiIar lo lhose for lhe decimaI and binary syslems.
ReealedIy,
MuIliIy X by 16,
Remove lhe (hexadecimaI) digil on lhe Iefl on lhe decimaI oinl.
Check lhal lhe decimaI fraclion oblained above gives lhe execled
hexadecimaI fraclion exansion.
Lel X 0.23710, (an aroximalion of 0.23693 84765 62510 ), and find lhe
firsl 6 digils:.
IniliaIIy, X 0.237
1
sl
ileralion: X 3.792 Digil 3 X 0.792
Study Guide 1: Introduction to Computer Systems
23
2
nd
ileralion: X 12.672 Digil C X 0.672
3
rd
ileralion: X 10.752 Digil A X 0.752
4
lh
ileralion: X 12.032 Digil C X 0.032
5
lh
ileralion: X 0.512 Digil 0 X 0.512
6
lh
ileralion: X 8.192 Digil 8 X 0.192
The rocess has generaled 6 successive hexadecimaI digils 3, C, A, C, 0, 8,
bul lhe conversion is nol yel comIeled, as lhere is sliII a remainder. In
facl, here ve are on lhe vay lo generaling a 0#.#'%&$2 7#G'<#6&-'( +0'6%&*$.
Al some slage lhe hexadecimaI lerms viII begin lo duIicale.
|In facl, lhe firsl remainder 0.792 is reealed on lhe 26
lh
ileralion. The
reealing hexadecimaI has a eriod of 25. So. .
0.23710 0.3 CAC08 3126I 978D4 IDI3 645A1 CAC08 3126I 978D4
IDI3 645A1 CAC08.
We can say lhal 0.23710 0.3CAC0816, vhich agrees vilh lhe revious
anaIysis lhal gave
0.23693 84765 62510 0.3CA816.
Nole lhal ve can aIso immedialeIy vrile dovn lhe aroximale binary
reresenlalion of
0.23710 0.0011 1100 1010 1100 0000 10002.
Rcad NuII and Lobur, chaler 2, ages 37 - 44 (lo 2.4)
Web Access
Wcb Acccss Access 5tudy Guidc 1 seclion of lhe unil vebsile and
comIele Iab / luloriaI exercises.
FIT1001 Computer Systems
24
Study
Guide
2
Data Representation
and Computer
Arithmetic
LEARNING OBJECTIVES
Al lhe comIelion of lhis sludy guide you viII be abIe lo:
exIain lhe concel of byle ordering in lerms of endian
reresenlalion
exIain lhe various reresenlalions for inleger, signed,
fraclionaI, fIoaling-oinl and characler dala,
demonslrale conversion melhods for inleger, signed, fraclionaI
and fIoaling-oinl numbers,
demonslrale basic malhemalicaI oeralions on signed inlegers,
undersland lhe origins and melhods of slorage used for binary
dala.
FIT1001 Computer Systems
26
Contents
2.1 Inlroduclion
2.2 yle Ordering: Indian Reresenlalion
2.3 Unsigned Inlegers
2.4 Signed Inlegers
2.5 Characler Dala
2.6 IIoaling-Ioinl Reresenlalion
Reading
Prescribed readings
NuII and Lobur, |sscniia|s cj Ccnpuicr Organizaiicn c Arcniicciurc.
Chaler 2: Dala Reresenlalion in Comuler Syslems
Study Guide 2: Data Representation and Computer Arithmetic
27
2.1 Introduction
This Sludy Guide resenl an overviev of comuler main memory, and lhe
various lyes of dala lhal can be slored in a comuler. The design and
slruclure of memory viII be discussed Ialer in lhe course. Mosl of lhis
discussion cenlres on lhe reresenlalion of differenl lyes of numericaI
dala.
Il is loo earIy in lhe course lo examine in delaiI lhe slruclure, design and
managemenl of comuler memory. There are severaI inleresling queslions
lo be resoIved, vhich firsl require a knovIedge of lhe lyes of informalion
lhal can be slored in lhe memory, and since lhe comuler comrises nol
|usl memory, bul aIso a CIU, buses and eriheraIs, lhese musl be laken
inlo accounl in lhe design rocess.
The simIesl viev of memory is lhal il comrises a huge Iinear array of bils
(each bil is a liny hardvare circuil), numbered 0, 1, 2, ..., N. In a Ienlium
vilh 512 Megabyles of memory, N 4,000,000,000.
In lhis seclion of lhe course ve are arlicuIarIy inleresled in smaII
reresenlalive hunks of memory, lo examine vhal sorl of informalion can
be slored lhere. In lhe binary comuler vorId, execl aII informalion lo be
organised and shaed in some vay as a over of 2. Novadays, lhere is
more-or-Iess common agreemenl aboul lhe foIIoving lerminoIogy.
Units of Data Storage
A bit is lhe smaIIesl unil of informalion slored in a comuler. The ta|uc lhal
il slores can be vieved in various vays. Regarding lhe circuil as a svilch,
ve can say lhal il is eilher nn or nII, i.e. il has 2 slales, vhich is vhy lhe
machine is caIIed a |inarq comuler. If il is nn, il can be seen as sloring a
one (1), if nII, a zero (0). In anolher conlexl, TRUI and IALSI, in anolher,
nn may indicale negalive (-) and nII, osilive (+).
A Bytc is oblained by grouing logelher 8 ad|acenl bils. Since each of lhe 8
bils has 2 aIlernale slales, lhe number of differenl allerns lhal can be
oblained is 2 2 2 2 2 2 2 2 2
8
256. The rogrammer or
comuler user has a choice as lo hov lhese 256 allerns may be inlerreled,
lyicaIIy:
(1) a number belveen 0 and 255, (2) a number belveen 128 and + 127, (3) a
charactcr such as 'A', 'v', '(', '`'.
A Nibb!c is a grouing of 4 bils. The name is derived as a un, in lhal il is
smaIIer lhan a byle (bile). Tvo nibbIes logelher make u a byle. This lerm
has Iimiled use.
FIT1001 Computer Systems
28
The lerm Wnrd can be used in lhe generaI sense, lo simIy mean a grouing
of bils, number unsecified. Il is commonIy used nov lo mean 16
conliguous bils, comrising lvo ad|acenl byles. The number of differenl
allerns il can reresenl is 2
16
65536. This number is vorlh remembering.
The Lnngwnrd, somelimes Dnub!c-wnrd, somelimes DWord, is 32
conliguous bils.
The Quadwnrd is 64 bils. The Octawnrd is 128 bils.
Thus, main memory is a Iinear array of bils, nibbIes, byles, vords, shorl
vords, Iong vords or vhalever lhe comuler designer has chosen for lhe
basic addressabIe unil. Mosl commonIy lhe addressabIe unil is byles. This
Iinear array is aII ve have lo reresenl aII lhe dala slruclures, vhich a
rogrammer may vish lo use (Iisls, arrays, lrees, records elc.) As far as ve
knov, nobody has buiIl a comuler for vhich lhe memory is accessed as a
muIlidimensionaI array e.g. secifying M(I,},K) Ieads lo lhe comuler
vorking oul an absoIule memory address vhere lhe eIemenl is slored. Mosl
comulers rovide lhe equivaIenl of A(I) in lhe form of being abIe lo
secify a base address for A and a disIacemenl from il of I.
Given a Iinear memory array, a robIem is hov lo organise lhe memory and
hov lo ma lhe rogrammer's dala slruclures inlo il easiIy. If ve choose
lhe byle as lhe basic eIemenl and make memory access one byle vide ve
have lhe Iovesl common muIliIe soIulion. This aroach vas used in
many earIy commerciaI comuler designs. A vider alh lo memory
roduces beller erformance because more informalion is lransmilled in
one memory access. Say ve seIecl a 32-bil vide alh, vhich is fine for mosl
oerands, in simIe lechnicaI caIcuIalions. 32-bil vide and 64-bil vide
alhs are lhe mosl common arrangemenls in use loday (and nov veII
imIemenled on ersonaI comulers). There are lvo common robIems.
If ve imIemenl a vord addressing scheme for memory hov do ve address
byle slrings vhich are nol 32-bils in Ienglh` The RISC (Reduced Inslruclion
Sel Comuler) archileclures vhich are aimed al simIifying machines and
gelling more erformance for money, lend lo secify lhal aII byle slrings
vhich are decIared in a rogram, have lo slarl on a Iongvord boundary e.g.
if a Iongvord is 4 byles, lhen lhe firsl byle of a slring musl aear as lhe
firsl byle of lhe Iongvord and nol lhe lhird byle of lhe revious Iongvord
vhere, say, lhe revious slring ends in lhe second byle. If lhe soflvare
(comiIers elc.) can enforce lhal, lhen ve are in good shae. If lhey cannol,
lhen ve may have serious robIems vilh some cIasses of rogram.
DifficuIlies may occur vhen a dalabase from a foreign machine, vhich does
nol observe lhal conslrainl, is lo be moved lo lhe RISC machine because lhe
vord boundary reslriclion for lhe slarl of a byle slring may be an obslacIe.
Study Guide 2: Data Representation and Computer Arithmetic
29
2.2 Byte Ordering Endian
Representation
Hov shouId ve drav diagrams of lhese eIemenls if ve are lo exIain lhe
slruclure of memory` This lurns oul lo be a nol enlireIy lriviaI queslion.
}onalhon Svifl's Gu||itcrs Tratc|s (1726) is usuaIIy vieved as a good fun
chiIdren's book (rovided lhal aII lhe scaloIogicaI bils have been removed),
bul ils uncensored version is an aduIl oIilicaI salire. In one eisode,
Svifl's hero, GuIIiver, is shivrecked and vashed ashore on LiIIiul,
vhose minialure six-inch-laII inhabilanls are required by a nevIy
rocIaimed Iav lo break lheir breakfasl eggs onIy al lhe IillIe end. Of
course, aII lhose cilizens vho habiluaIIy break lheir eggs al lhe big end are
grealIy angered by lhe rocIamalion. CiviI var breaks oul belveen lhe
LillIe-Indians and ig-Indians, resuIling in lhe ig-Indians laking refuge
on a nearby isIand, lhe kingdom of Iefuscu. The conlroversy is elhicaIIy
and oIilicaIIy imorlanl for lhe LiIIiulians. In facl Svifl has 11,000
LiIIiulian rebeIs die over lhe egg queslion. The issue does seem siIIy, bul
Svifl is salirising lhe acluaI causes of reIigious or hoIy vars.
Svifl's oinl is lhal lhe difference belveen breaking an egg al lhe IillIe end
and breaking il al lhe big end is lriviaI. He suggesls lhal everyone be
aIIoved lo do il in lheir referred vay. There is a simiIar var going on
around lhe vorId loday. ul by conlrasl vilh Svifl's soIulion, lhe oinl al
issue is nol so lriviaI.
Comuler memory is besl considered lo be a Iinear sequence of bils
organised inlo byles, vords, Iongvords, ages, elc. Iach unil is a sub-unil
of lhe nexl higher IeveI. This is an hierarchicaI slruclure. We vouId execl
lhe order in vhich sub-unils are arranged in unils lo be consislenl, so lhal
lhe order of bils in a byle, byles in a Iongvord, elc., is lhe same.
We have seen lhal memory comrises bils (), byles/characlers (C) vilh 8
bils er byle, vords (W) of 16 bils 2 byles, and Iongvords (L) of 2 vords
4 byles 32 bils. We shaII number Iongvords L0, L1, L2, ..., vords W0, W1,
W2, ..., byles/characlers C0, C1, C2, ..., and bils 0, 1, 2, ...
Here ve adol a common comuler induslry concel of counling uvards
slarling al 0 ralher lhan 1. This makes a Iol of lhe inlernaI DIV/MOD
arilhmelic much simIer.
To iIIuslrale lhe hierarchicaIIy consislenl order grahicaIIy, ve musl firsl
decide lhe order in vhich lo vrile comuler vords on aer. Do lhey go
from Iefl lo righl, or righl lo Iefl` IngIish, Iike mosl modern veslern
Ianguages, suggesls lhal ve arrange (Iong)vords from Iefl lo righl: To be
FIT1001 Computer Systems
30
consislenl vilhin each Iongvord, 0 shouId be on lhe Iefl of 31, byle C0
Iefl of C3, elc.
L0 L1 L2 L3
W0 W1 W2 W3 W4 W5 W6 W7
C0 C1 C2 C3 C4 C5 C6 C7 C8 C9 C10C11 C12C13C14C15
0 1 2 . . . . .31 32 33 . . . . . .63 64 65 . . . . . .95 96 . . . . . . . . .127
MS LS MS LS MS LS MS LS
Big-Endian Vicw nI thc Wnr!d
The convenlion inlroduced by lhis syslem uls lhe big end (Mosl
Significanl il MS) on lhe Iefl, and lhe IillIe end (Leasl Significanl il LS)
on lhe righl. This is a erfeclIy consislenl vorId-viev according lo lhe ig-
Indians, The significance decreases vilh increasing ilem number (memory
address). IngIish lexl slrings are slored in lhe usuaI order, lhe firsl
characler in C0 of W0, lhe nexl in C1 of W0, elc., consislenl inlernaIIy and
vilh lhe IngIish Ianguage: (eam me u Scolly).
W0 W1 W2 W3 W4 W5 W6 W7
e a m m e u S c o l l
In IngIish ve vrile and seak numbers in ig-Indian, e.g. lvenly-four.
This vas nol aIvays lhe case, recaII lhe nursery rhyme vhere lhere vere
Iour and lvenly bIackbirds baked in a ie (LillIe-Indian). In German il is
Vier und Zvanzig (LillIe-Indian).
The LillIe-Indians have a differenl scheme, aIso seIf-consislenl. They
beIieve in slarling vilh lhe IillIe end of every vord, and lhal Iover
addresses are of Iover order lhan high addresses, They ul lheir
(Iong)vords on aer as if lhey vere vrillen in Hebrev, and lhey mainlain
a consislenl order of lhe sub-unils in lhe Iongvords:
L3 L2 L1 L0
W7 W6 W5 W4 W3 W2 W1 W0
C15C14C13C C11C10 C9 C8 C7 C6 C5 C4 C3 C2 C1 C0
127 . . . . . . . . . 95 . . . . . . 65 64 63 . . . . . . 33 32 31 . . . . .2 1 0
MS LS MS LS MS LS MS LS
Litt!c-Endian Vicw nI thc Wnr!d
IngIish lexl slrings are slored in lhe same order as in ig-Indian, vilh lhe
firsl characler in C0 of W0, lhe nexl in C1 of W0, elc. The order is consislenl
vilh ilseIf, vilh lhe Hebrev Ianguage, and ncsi inpcriani|q uiin
Study Guide 2: Data Representation and Computer Arithmetic
31
naincnaiics, because significance increases vilh increasing ilem number
(address).
W7 W6 W5 W4 W3 W2 W1 W0
l l o c S u e m m a e
The disadvanlage of lhis is lhal IngIish characler slreams aear lo be
vrillen backvards
There is absoIuleIy no significance lo lhe nolion of Iefl and righl in lhe bil
order of a comuler memory. Il couId |usl as easiIy be u and dovn or
mirrored by lhe syslemalic inlerchange of aII Iefls vilh aII righls. This idea
slems nol from a Ianguage modeI bul from lhe concel lhal comuler
vords reresenl numbers. y malhemalicaI lradilion, lhe big end is on lhe
Iefl and lhe IillIe end righl, as indicaled by MS and LS in lhe receding
diagrams. This malhemalicaI convenlion is lhe oinl of reference for lhe
designalion of Iefl and righl in lhis discussion.
These are nol |usl mallers of nolalion. Things can gel reaIIy horrendous
vhen allemling lo lransfer dala from a big Indian machine lo IillIe Indian
machine or vice versa, or vhen inlerfacing lvo differing rocessors lo a
common bus. Serious difficuIlies can occur vhen lrying lo move rograms
and dala belveen comulers for vhich designers make differenl decisions
aboul lhe vay in dala is reresenled. Il is lherefore mosl imorlanl lhal lhe
robIems of and soIulions lo reresenling dala and dala slruclures in a
comuler are underslood.
Irom a LillIe-Indian oinl of viev, lhe foIIoving diagram deicls lhe firsl
72 bils of memory, lhe firsl 9 byles, lhe firsl 4 vords, and lhe firsl 2
Iongvords. The address vaIues in lhe diagram increase from righl lo Iefl.
The aim is mainIy lo resenl a viev for underslanding Iiii|c-|n!ian
archileclure comulers. There is more exIanalion beIov.
Longvord 1 Longvord 0
4 Word 3 Word 2 Word 1 Word 0
yle 8 yle 7 yle 6 yle 5 yle 4 yle 3 yle 2 yle 1 yle 0
. . . . . .
. .
. . . . . .
. .
. . . . . .
. .
. . . . . . .
.
. . . . . .
. .
. . . . . . .
.
. . . . . . .
.
. . . . . . .
.
. . . . . .
. .
71 64 63 56 55 48 47 40 39 32 31 24 23 16 15 8 7 0
LS MS LS MS LS
! # # $ % & & % & ' ( ) $ % * & % + $ , - . ' / 0 1 1 , 2 % + 1
In lhe diagram, nole lhe bollom Iine, vhich indicales lhe MS (Mosl
Significanl il) and lhe LS (Leasl Significanl il) of lhe 32-bil Iongvords.
These say lhal a binary number slored in lhe Iongvord is reresenled in lhe
FIT1001 Computer Systems
32
convenlionaI vay, vilh lhe more imorlanl (significanl) digils lovards lhe
Iefl, in lhe same vay lhal ve reresenl decimaI numbers, i.e. for 159210 , lhe
1 (indicaling 1000) is on lhe Iefl. The MS / LS concel aIies simiIarIy lo
lhe subordinale vords and byles shovn in lhe slruclure.
Ixamine lhe bil numbers of Iongvord 0. The vaIue slored in bil 0 reresenls
2
0
, lhe vaIue in bil 1 reresenls 2
1
, and so on. So lhe LillIe-Indian aroach
makes sense.
2.3 Unsigned Integer Data
y unsigned, ve mean lhal here ve are nol allemling lo reresenl
negalive vaIues. We vanl lo reresenl lhe numbers 0, 1, 2, ... 254, 255, 256,
257, .... 65535, 65536, 65537, ... 2000000000, 2000000001, ...
The idea here is quile slraighlforvard, and foIIovs naluraIIy from lhe
discussion of lhe binary number syslem.
WhiIe comuler memory is nol exensive, il is sliII sensibIe lo conserve ils
use. Ixerl rogrammers carefuIIy choose lhe dala lye aroriale for lhe
aIicalion. Ior examIe, in an array lo slore lhe ages of 1,000,000 eoIe,
use one Myle of memory (1,000,000 8-bil inlegers) ralher lhan four Myles
( 1,000,000 32-bil inlegers). Nobody has Iived beyond lhe age of 255.
A Bit can slore unsigned inlegers from 0 lo 1. A bil is nol usuaIIy direclIy
addressabIe, for examIe, il is nol normaIIy ossibIe lo decIare an array of
bils.
A Bytc of 8 bils can slore unsigned inlegers from 0 lo 255 2
8
1.
In binary arilhmelic, if lhe Ienglh of lhe number is reslricled lo 8 digils (0s
and 1s), lhe Iargesl vaIue is 1111 11112 255, and lhe smaIIesl is 0.
A Wnrd of 16 bils can slore unsigned inlegers from 0 lo 65535 2
16
1.
In binary arilhmelic, if lhe Ienglh of lhe number is reslricled lo 16 digils (0s
and 1s), lhe Iargesl vaIue is 1111 1111 1111 11112 65535, and lhe smaIIesl is
0.
A Lnngwnrd of 32 bils can slore unsigned inlegers from 0 lo
4,294,967,295 2
32
1.
A Quadwnrd of 64 bils can slore unsigned inlegers from 0 lo
18,446,744,073,709,551,615 2
64
1.
Study Guide 2: Data Representation and Computer Arithmetic
33
elc.
Arithmetic with Unsigned Data
Using lhe decimaI syslem, if ve agree lo use lhree digils for our unsigned
numbers, ve can reresenl aII vaIues belveen 000 and 999. Whal arilhmelic
difficuIlies can occur`
On additinn, ve may add lvo vaIues such lhal an overfIov occurs:
301
812
Add: 1 113
The vaIue 1113 cannol be accommodaled by our lhree-digil syslem.
A carry of 1 has been generaled on lhe Iefl.
On subtractinn, ve may sublracl lvo vaIues such lhal an underfIov occurs:
301
812
Sublracl: 1 489
The 1 on lhe Iefl here reresenls a borrov of 1000.
The correcl ansver, 511, is seen as 1000 + 489.
2.4 Signed Integers
Representing Negative Numbers
Many simIe and effeclive schemes have been used for sloring negalive
numbers and erforming sublraclion in a comuler.
The Complement of a Number
The vord is comIemenl, nol comIimenl. In comulers comIemenls are
used lo simIify sublraclions, reresenl negalive numbers, and for IogicaI
oeralions. In base arilhmelic ve can comule lvo comIemenls: lhe 's
comIemenl, and lhe (-1)'s comIemenl. Ior binary numbers ve can use
2's comIemenl and 1's comIemenl, in decimaI arilhmelic ve have 10's
comIemenl and 9's comIemenl. In generaI, comIemenls are defined for
numbers lhal have bolh inleger and fraclionaI arls. This discussion is
reslricled lo comIemenls of inlegers. Since ve are more famiIiar vilh
FIT1001 Computer Systems
34
decimaI arilhmelic, 10's and 9's comIemenls are discussed firsl, lo rovide
anaIogies vilh binary 2's and 1's comIemenl reresenlalion.
10s Complement Representation
The 10's comIemenl of a decimaI number N vilh d digils is 10
d
N
(excel lhal lhe 10's comIemenl of 0 is 0).
418930 has 6 digils, so d 6, so il is sublracled from 100000010.
The 10's comIemenl of 418930 is 10
6
418930 1000000 418930 581070.
A second vay lo oblain lhe 10's comIemenl is:
Irom righl lo Iefl: Ieave aII lraiIing zeroes unchanged, sublracl lhe firsl
non-zero digil from 10, sublracl aII lhe remaining digils from 9.
2s Complement Representation
The 2's comIemenl of a binary number N vilh d digils is 2
d
N
(excel lhal lhe 2's comIemenl of 0 is 0).
010110 has 6 digils, so d 6, so lhe number is sublracled from 10000002.
The 2's comIemenl of 010110 is 2
6
010110 1000000 010110 101010.
A second vay lo oblain lhe 2's comIemenl is:
Irom righl lo Iefl: Ieave aII lraiIing zeroes unchanged, kee lhe firsl 1,
reverse lhe remaining 0s and 1s.
9s Complement Representation
The 9's comIemenl of a decimaI number N vilh d digils is 10
d
1 N.
The 9's comIemenl of 418930 is 10
6
1 418930 999999 418930 581069
(of course, 1 Iess lhan lhe 10's comIemenl).
418930 has 6 digils, so d 6, so lhe number is sublracled from 999999.
A second vay lo oblain lhe 9's comIemenl is: Sublracl every digil from 9.
Study Guide 2: Data Representation and Computer Arithmetic
35
1s Complement Representation
The 1's comIemenl of a binary number N vilh d digils is 2
d
1 N.
010110 has 6 digils, so d 6, so lhe number is sublracled from 111111.
The 1's comIemenl of 010110 is 1000000 1 010110 111111 010110
101001 (of course, 1 Iess lhan lhe 2's comIemenl).
A second vay lo oblain lhe 1's comIemenl is: Reverse aII 0's and 1's.
The imorlanl lhing lo reaIise in lhe receding discussion is lhal in aII four
cases, a sublraclion has been erformed. This suggesls lhal ve can rcprcscni
inc ncgaiitc ta|uc cj a nun|cr using iis ccnp|cncni. Nolice lhal laking lhe
comIemenl of lhe comIemenl reslores lhe originaI number.
Restricting the Range of Values
Suose ve agree lo use 10's comIemenl lo reresenl aII osilive and
negalive numbers, and lhal lhe numbers are al mosl lhree digils. The
roosilion is lhal ve shouId reresenl aII vaIues, incIuding zero, from -999
lo (+)999. In lhe normaI reresenlalion ve require lhe use of lhe minus sign,
vhich is an exlra iece of informalion, lhree digils aIone are nol enough lo
reresenl numbers. There is a enaIly for allemling lo use |usl lhree digils
(and no minus sign) lo reresenl bolh osilive and negalive numbers: ve
musl reduce lhe range of vaIues ve can use, il is effecliveIy haIved.
TyicaIIy, ve vouId use 000 lo 499 in lhe normaI vay, as zero and osilive
vaIues. And ve vouId use 500 lo 999 lo reresenl negalive vaIues, as
defined by lhe 10's comIemenl. Thus, -500 vouId be reresenled by 1000
500 (+)500, -499 vouId be reresenled by 1000 499 (+)501, -321 vouId
be reresenled by 1000 321 (+)679, and -1 by 1000 1 (+)999. This
obviousIy aIIovs aII vaIues from (-1) lo (-500) lo be reresenled (500
differenl vaIues in lolaI). We have a singIe zero, 000, and ve have |usl 499
osilive vaIues avaiIabIe. So lhe syslem is asymmelric.
A simiIar discussion aIies for 9's comIemenl, vhere ve sublracl from
999 ralher lhan 1000. This aIIovs us lo reresenl lhe osilive vaIues 001 lo
499, as above, and zero, 000. Ior negalive vaIues, ve vouId reresenl -499
by 999 499 (+)500, -498 by 999 498 (+)501, -321 by 999 321 (+)678,
and -1 by 999 1 (+)998. CIearIy 999 000 999, i.e., zero is aIso
reresenled, redundanlIy, by (+)999. Ior 9's comIemenl, lhe syslem is
symmelric: ve have +1 lo +499, -1 lo
-499, and lvo zeros, 000 and 999. The 999 aears lo be zero vilh a negalive
sign allached.
FIT1001 Computer Systems
36
5ubtracting Numbcrs: AIgebraicaIIy, X Y X + (Y).
A (sIighlIy simIislic) viev of sublraclion: if a comuler aIready has a
mechanism lo add lvo numbers, and anolher lo cnmp!cmcnt (i.e. reresenl
lhe negalive of) a number, lhere is no need for a lhird seciaI mechanism lo
subtract one number from anolher. To sublracl, |usl comIemenl and add.
Tncrc arc spccia| ru|cs lo ensure lhal negalive ansvers are handIed correclIy.
These are easiIy deduced from lhe definilions of 's comIemenl and (-1)'s
comIemenl. The ruIes are iIIuslraled, bul nol fuIIy exIained in lhese
noles. Iurlher reading may be required.
10s Complement Subtraction and 2s Complement Subtraction
To sublracl Y from X, i.e. find X Y:
Add X and lhe 's comIemenl of Y
If lhere is an end carry, discard il.
Recognise lhal lhe resuIl may be negalive.
If so, lake 's comIemenl lo discover lhe magnilude.
Ior humans using 10's comIemenl arilhmelic:
X 33643 33643
Y 04360 has 10's comIemenl 95640
Adding lhese lvo vaIues roduces an end carry: 1 29283 ansver
The end carry (1) is discarded (vhy`)
X 04360 04360
Y 33643 has 10's comIemenl 66357
Add: 70717
There is no end carry, lhe Ieading 7 shovs lhal lhe ansver is negalive.
(We can lake 10's comIemenl lo recognise lhe vaIue 29283 ansver
(magnilude 29283, bul vilh a minus sign)
Ior comulers using 2's comIemenl arilhmelic:
X 0010100 0010100
Y 0000100 has 2's comIemenl 1111100
Add, and discard lhe end carry: 1 0010000 ansver
X 0000100 0000100
Y: 0010100 has 2's comIemenl 1101100
Add: 1110000 2's
comIemenl ansver
Study Guide 2: Data Representation and Computer Arithmetic
37
There is no end carry. The Ieading '1' shovs lhal lhe ansver is negalive.
(We can lake 2's comIemenl lo recognise lhe vaIue 0010000
ansver (magnilude 10000, bul vilh a minus sign)
9s Complement Subtraction and 1s Complement Subtraction
This is quile simiIar lo sublraclion using 10's or 2's comIemenl, excel lhal
an end-around-carry may be required.
To sublracl Y from X, i.e. find X Y:
Add X and lhe 's comIemenl of Y
If lhere is an end carry, add 1 lo lhe righl-mosl digil (end-around-carry),
If lhere is nol an end carry, recognise lhal lhe resuIl is negalive.
Take 's comIemenl and shov sign.
Ior humans using 9's comIemenl arilhmelic:
X 33643 33643
Y 04360 has 9's comIemenl 95639
Add. There is an end carry: 1 29282
Ind-around-carry 1
29283 ansver
X 04360 04360
Y 33643 has 9's comIemenl 66356
Add. 70716
There is no end carry, lhe Ieading 7 shovs lhal lhe ansver is negalive.
Take 9s comIemenl lo gel 29283 ansver
Ior comulers using 1's comIemenl arilhmelic:
X 0010100 0010100
Y 0000100 has 1's comIemenl 1111011
Add. There is an end carry: 1 0001111
Ind-around-carry 1
0010000 ansver
X 0000100 0000100
Y 0010100 has 1's comIemenl 1101011
Add: 1101111 1's
comIemenl ansver
There is no end carry. . The Ieading '1' shovs lhal lhe ansver is negalive.
Take 1's comIemenl 0010000 ansver
FIT1001 Computer Systems
38
Comparison Between 2s Complement and 1s Complement
1's comIemenl is easier lo imIemenl, aII lhal is required is lo
reverse 0's and 1's.
2's comIemenl can be oblained by eilher of lvo ruIes:
add 1 lo lhe 1's comIemenl, or
from righl lo Iefl, Ieave aII lhe 0's and lhe firsl 1 unchanged, lhen
reverse lhe remaining 0's and 1's.
When erforming sublraclion vilh 2's comIemenl, onIy one
arilhmelic addilion is required, any end-carry is discarded.
Wilh 1's comIemenl sublraclion, if an end-carry occurs (say, haIf
lhe lime), a second addilion is needed.
1's comIemenl reresenlalion has lvo zeroes (aII 0s, and aII 1s). So
roughIy haIf lhe lime, lvo lesls are required for vhelher a vaIue is
zero.
RegardIess of vhelher il is osilive or negalive, an even 2's
comIemenl number has bil 0 0.
Ior 1's comIemenl numbers, osilive even vaIues have bil 0 0,
negalive odd vaIues have bil 0 0.
The 1's comIemenl syslem is symmelric. The 2's comIemenl is nol.
2s Complement Signed Integers
2's comIemenl arilhmelic is imIemenled in mosl modern comulers, in
arlicuIar, lhe InleI 80x86 famiIy, incIuding lhe Ienlium range, and lhe
DigilaI Iquimenl Cororalion VAX and AIha machines.
The sels of numbers lhus reresenled are sIighlIy asymmelricaI. There is
one more negalive number lhan lhere are osilive numbers. The number of
numbers musl be even (2
n
), and lhere has lo be a zero.
Using 2's comIemenl reresenlalion:
A Bytc of 8 bils can slore signed inlegers from - 2
7
-128 lo +127 2
7
1.
The bil allern 0000 0000 reresenls 0.
The bil allern 0111 1111 reresenls +127.
The bil allern 1000 0000 reresenls -128.
The bil allern 1111 1111 reresenls -1.
A Wnrd of 16 bils can slore signed inlegers from -2
15
-32768 lo +32767
2
15
1.
The bil allern 0000 0000 0000 0000 reresenls 0.
Study Guide 2: Data Representation and Computer Arithmetic
39
The bil allern 0111 1111 1111 1111 reresenls +32767.
The bil allern 1000 0000 0000 0000 reresenls -32768.
The bil allern 1111 1111 1111 1111 reresenls -1.
A Lnngwnrd of 32 bils can slore signed inlegers from -2
31
-2,147,483,648 lo
+2,147,483,647 2
31
1.
A Quadwnrd of 64 bils can slore signed inlegers from -2
63

-9,223,372,036,854,775,808 lo +9,223,372,036,854,775,807 2
63
1.
Alternative Representations for Signed Integers
1's comIemenl and 2's comIemenl are nol lhe onIy vays in vhich
negalive numbers can be reresenled in a comuler. The design decision, as
lo vhich of lhese lvo aIlernalives lo imIemenl is a fairIy cIose lhing see
lhe comarison, a age or so back. Olher mechanisms have been used. Tvo
simIe ones are Sign/Magnilude reresenlalion and Ixcess N
reresenlalion. Ior simIicily, lhese are discussed in lerms of vhal can be
reresenled in a comuler using four-bil vords (see lhe labIe beIov).
GeneraIisalions lo 8, 16, and 32 bils are obvious. Use lhis labIe lo check
your underslanding of 1's comIemenl and 2's comIemenl (in a 4-bil
conlexl).
Sign/Magnitude Representation
The name is seIf-exIanalory. Use one bil slore lhe + or sign, and lhe
remaining bils lo slore lhe magnilude of lhe number. Ior lhe sign bil,
usuaIIy, 0 means Ius (+) and 1 means minus (-). (This haens
aulomalicaIIy vilh 1's and 2's comIemenl reresenlalions). If ve slore lhe
sign bil on lhe Iefl in our four-bil comuler, for examIe,
0 1 0 1 means + 1 0 1 +5, and 1 0 1 0 means - 0 1 0 -2.
See lhe Iasl coIumn in lhe foIIoving labIe. This reresenlalion is simIe and
sensibIe, bul as vilh 1's comIemenl lhere are lvo zeroes, a +0 and a 0 (a
disadvanlage). AIso, since lhe sign musl be lesled before any addilion or
sublraclion can be carried oul, lhe circuilry lo imIemenl sign/magnilude
arilhmelic is more comIicaled and lhe oeralions are on average sIover.
FIT1001 Computer Systems
40
Hex 4 Bits Unsigned 1s
Complement
2s
Complement
Excess 7 Excess 8 Sign/
Magnitude
0 0 0 0 0 0 0 0 -7 -8 0
1 0 0 0 1 1 1 1 -6 -7 1
2 0 0 1 0 2 2 2 -5 -6 2
3 0 0 1 1 3 3 3 -4 -5 3
4 0 1 0 0 4 4 4 -3 -4 4
5 0 1 0 1 5 5 5 -2 -3 5
6 0 1 1 0 6 6 6 -1 -2 6
7 0 1 1 1 7 7 7 0 -1 7
8 1 0 0 0 8 -7 -8 1 0 (-)0
9 1 0 0 1 9 -6 -7 2 1 -1
A 1 0 1 0 10 -5 -6 3 2 -2
B 1 0 1 1 11 -4 -5 4 3 -3
C 1 1 0 0 12 -3 -4 5 4 -4
D 1 1 0 1 13 -2 -3 6 5 -5
E 1 1 1 0 14 -1 -2 7 6 -6
F 1 1 1 1 15 (-)0 -1 8 7 -7
Six Different Interpretations of 4 Bits
Exccss N Rcprcscntatinn
Here, N is typically 2
n
or 2
n
-1 , e.g. 128 or 127. In the examples for our 4 bit word
computer, we use 8 and 7. The idea with excess representation is to represent all
values as zero or positive, by adding an excess (or a bias) to every number in the
valid range. For example, to represent numbers in the range 7 to +8, add an excess
or a bias of 7 to all values, so that the internal representation will range from 0 to 15.
For example, with excess 7 notation, 5 would be represented as 12 (1100
2
) and 2
would be represented as 5 (0101
2
). Similarly, to represent numbers in the range 8 to
+7, add 8 to all values, so that they will range from 0 to 15.
When two numbers are to be added, there is no need to test their signs. But the excess
(e.g. 7) must be subtracted from the result to maintain the integrity of the
representation.
For example, (true 5) + (true 2) = (5 + 7) + (-2 + 7) - 7 = 10 = (true 3)
Conversely when two numbers are subtracted, the excess must be added to the result.
Study Guide 2: Data Representation and Computer Arithmetic
41
Generally, using excess N representation is perceived as slower and more expensive in
circuitry than 1s or 2s complement representation. However, we shall see shortly
that excess 127 notation in an 8-bit field is part of the scheme for representing single
precision floating point numbers.
Rcad NuII and Lobur, chaler 2, ages 44 (from 2.4) - 55 (lo 2.5)
2.5. Character Data
Binary Coded Decimal (BCD)
CD is a numeric coding syslem used rimariIy in IM mainframes and
midrange syslems. In binary cndcd dccima!, each decimaI digil is
reresenled as a four bil binary number as foIIovs:
Decimal Digit BCD
0
1
2
3
4
5
6
7
8
9
0000
0001
0010
0011
0100
0101
0110
0111
1000
1001
Fig 2.5.1 BCD Basic Tab!c
Examp!c: Reresenlalion of 7926 in CD viII be as foIIovs:
7 9 2 6
0111 1001 0010 0110
Thus lvo decimaI digils occuy one byle of memory.
In a znncd dccima! reresenlalion lhe decimaI digils are reresenled using
8 bils vilh lhe firsl four bils as a seciaI znnc and lhe nexl four bils
conlaining lhe acluaI decimaI digil in CD. The zone nibbIe (lerm for 4 bils)
usuaIIy conlains 1111. Thus, lhe zoned decimaI non-negalive numbers are
FIT1001 Computer Systems
42
same as lhe decimaI numbers reresenled in Extcndcd BCD Intcrchangc
Cndc (EBCDIC) see nexl seclion. To reresenl a signed decimaI number in
zoned form, lhe zone nibbIe of lhe righl-mosl digil is reIaced by a
sequence of bils reresenling lhe sign as foIIovs:
1111 unsigned (I in hex)
1101 negalive (D in hex)
1100 osilive (C in hex)
Examp!c:
(a) Reresenlalion of +135 in zoned form is as beIov:
1111 0001 1111 0011 1100 0101
+ sign of lhe number
The hex reresenlalion of lhe above zoned decimaI is I1 I3 C5
(b) The reresenlalion of 75 in zoned form is as beIov:
1111 0111 1101 0101
sign of lhe number
The hex reresenlalion of lhe above zoned decimaI is I7 D5
In packcd dccima! formal lhe zone nibbIe is discarded and lhe decimaI
number is reresenled in binary. The Iasl nibbIe of lhe number conlains lhe
sign of lhe number vilh lhe same inlerrelalion as in lhe case of zoned
formal. If il is necessary lo reresenl lhe byles in hex nolalion, 0000 may
need lo be added as lhe Iefl-mosl nibbIe, because an even number of nibbIes
are required lo slore lhe number in an 8-bil formal.
EBCDIC (Extended BCD Interchange Code)
efore lhe deveIomenl of lhe IM Syslem/360, IM used a 6-bil varialion
of lhe CD formal. This code vas Iimiled in hov il couId reresenl and
maniuIale dala, Iovercase Ieller vere nol arl of lhis varialion. IM
exanded lhe 6 bils lo 8 bils lhis exlending lhe code. IM sliII uses ICDIC
in lheir mainframes and midrange syslems.
ASCII (American Standard for Information Interchange)
During lhe lime vhen IM vere vorking on lheir Syslem/360 olher
comuler manufaclurers vere Iooking for beller vays of lransmilling dala
belveen lvo syslem. ASCII vas lhe resuIl and is a descendenl of coding
schemes used by leIelye devices.
Study Guide 2: Data Representation and Computer Arithmetic
43
One of lhe earIy slandards adoled vas lhe 7-bil ASCII (American Slandard
Code for Informalion Inlerchange) characler sel, shovn on lhe nexl age.
Here, characlers are reresenled by assigning lhem a numeric vaIue
belveen 0 and 127. Of course lhese are slored in an 8-bil byle, vilh lhe lo
bil (bil 7) 0. There are various exlensions and varialions lo lhis characler
sel, lhe obvious ones using aII 8 bils inslead of 7. The ANSI (American
NalionaI Slandards Inslilule) characler sel, shovn on lhe foIIoving age,
has lhe same characlers maed lo 0...127 as lhe ASCII sel.
Ior examIe, 'A' is decimaI 65, 'z' is decimaI 122, '0' is decimaI 48, and '5' is
decimaI 53. Il is imorlanl lo reaIise lhal lhe reresenlalion of lhe decimaI
number 5, (binary 0101) is quile differenl from, and reresenled differenlIy
from, lhe characler '5'.
Fig 2.5.2 7-bit A5C Tab!c
Nolice lhe firsl lvo coIumns, and characler 127 in lhe ASCII labIe. The same
characlers are aIso resenl in lhe ANSI sel, bul are shovn as vhich
essenliaIIy hides lheir funclion (see figure on nexl age). This indicales lhal
lhese characlers are nol for human consumlion. They are caIIed conlroI
characlers, essenliaIIy used for communicalion belveen eIeclronic devices.
Ior examIe, CR (decimaI 13) is Carriage Relurn (move cursor lo slarl of
Iine), LI (decimaI 10) is Line Ieed (move lexl u one Iine), so lhe CR LI
FIT1001 Computer Systems
44
sequence reresenls vhal a lyisl vouId erform on an oId lyevriler
vhen lhe end of a Iine of lexl vas reached.
Fig 2.5.3 AN5I Tab!c
eIov is lhe lradilionaI IM DOS 8-bil ASCII characler sel.
Fig 2.5.4 IBM DO5 8-bit A5CII Tab!c
Characlers 0 and 25510 disIay as saces (bIanks). The slandard sace
characler is 3210. Characlers (decimaI) 7, 8, 9, 10, 13 and 26 are nol shovn
Study Guide 2: Data Representation and Computer Arithmetic
45
here, lhese vere suressed vhen lhe oulul vas generaled under DOS,
because under normaI circumslances lhey cause aclions ralher lhan disIay:
7 IL causes a bee. Il disIays as a buIIel, simiIar lo 249.
8 S erforms a backsace. Il disIays as an inverse buIIel.
9 HT erforms a horizonlaI lab. Il disIays as a smaII cenlred circIe.
10 LI erforms a Iine feed. Il disIays as lhe inverse of 9.
13 CR erforms a carriage relurn. Il disIays a musicaI crolchel, one-haIf
of 14.
26 SU vas lhe slandard Ind-Of-IiIe characler under DOS.
Il disIays as a righl arrov.
Nolice lhe Iine and box-draving characlers are (decimaI) 179 lo 223.
The ASCII slandard aIso fealures lhe foIIoving:
The digils '0' lo '9' have ordinaI vaIues 4810 ( 3016) more lhan lhe
arilhmelicaI vaIue lhey reresenl. Ior examIe, digil '5' is 5310 3516.
Lover case Iellers have ordinaI vaIues 3210 ( 2016) more lhan lhe
uer case Iellers. Ior examIe, ordinaI 'g' 10310, ordinaI 'G' 7110.
This rovides a convenienl mechanism for converling belveen uer case
and Iover case rogrammalicaIIy, referabIy using AND and OR
oeralions.
Unicode
The exlended version of ASCII couId nol lruIy rovide inlernalionaI
suorl. olh ASCII and ICDIC are conslrucled around lhe Lalin
aIhabel. As a consequence counlries slarled devising lheir ovn codes lo
reresenl lheir nalive Ianguages. None of lhese vere comalibIe vilh each
olher and inlroduced a barrier belveen counlries.
In 1991 a consorlium vas formed and eslabIished a nev inlernalionaI
informalion exchange code caIIed Unicode. Unicode is based on 16 bils and
is dovnvard comalibIe vilh ASCII and lhe Lalin-1 characler sel. 16 bils
rovides lhe caacily lo encode lhe ma|orily of characlers use in Ianguages
across lhe vorId. Hovever lhe consorlium defined exlensions lhal viII
aIIov for lhe coding of an addilionaI miIIion characlers
Rcad NuII and Lobur, chaler 2 ages 55 from 2.6) - 67 (lo 2.7)
FIT1001 Computer Systems
46
2.6 Floating-Point
In malhemalics ve recognise differenl kinds of numbers. There is a
hierarchy, deveIoing from simIe lo more comIex, as foIIovs:
The Natura! Numbcrs 1, 2, 3, 4, ...
The Intcgcrs ....-4, -3, -2, -1, 0, 1, 2, 3, 4, ... lhe naluraI numbers, and zero,
and lhe negalive naluraI numbers.
The Ratinna!s, vhich are defined as aII numbers of lhe form
(inleger_numeralor)/(non-zero inleger_denominalor). The ralionaIs incIude
lhe inlegers. Reealing decimaI fraclions are ralionaI.
The Rca!s form a ccniinuun. The reaIs incIude lhe ralionaIs, and irralionaIs
such as 2 1.414213562..., 3 1.732050807..., and lranscendenlaIs such as
c 2.718281828459045..., 3.1415926535..., 0.577215664...
There is an injiniic nun|cr of each kind. The firsl lhree sels are denumerabIe
(counlabIe), lhe reaIs are nol (lhere are infinileIy many reaIs belveen
every lvo ralionaIs). Remember lhal a comuler is finile and cannol slore
an infinile number of anylhing.
In comuling ve have borroved lhe lerm |ca|, usuaIIy inlerchangeabIe
vilh ||caiing Pcini, lo mean a reresenlalion of a number lhal is (mosl
oflen) an aroximalion, ossibIy lo a very Iarge number or very smaII
number or a fraclion, such as lhose discussed in Number Reresenlalion,
Scienlific Nolalion).
The Inslilule of IIeclricaI and IIeclronic Ingineers (IIII) deveIoed lhe
slandard IIII-754 for lhis reresenlalion, vhich has been fuIIy adoled by
many comuler manufaclurers incIuding InleI, and arliaIIy adoled by
olhers. (When differenl manufaclurers use lhe same slandard, il is easier lo
lransfer dala belveen lhe differenl comulers). The InleI 80x86 famiIy
suorls lhree fIoaling oinl formals, conceluaIIy simiIar bul differing in
recision and size. These are caIIed sncri (32 bils, SingIe), |cng (64 bils,
DoubIe), and icnpcrarq (80 bils, Ixlended). The lerms 'SingIe' and 'DoubIe'
are used in many high-IeveI rogramming Ianguages. When fIoaling oinl
arilhmelic is erformed in lhe InleI chis, singIe and doubIe recision
vaIues are converled lemorariIy lo higher recision 80-bil vaIues, hence
lhe lerminoIogy.
The concel is lhe same as lhal used in Scienlific Nolalion, for reresenling
very Iarge and very smaII decimaI numbers using overs of 10. Of course
in a comuler overs of 2 are used inslead. Wilh lhis lechnique, ve have lo
slore lvo vaIues: for lhe Avogadro conslanl, ve needed 6.02252 and 23, for
Study Guide 2: Data Representation and Computer Arithmetic
47
lhe eIeclron mass, 9.1091 and -31. In Scienlific Nolalion, lhe decimaI oinl is
aIvays immedialeIy afler lhe Ieading digil, and lhe Ieading digil is aIvays
belveen 1 and 9 (incIusive).
The Shorl/SingIe fIoaling-oinl lye slores vaIues in a 32-bil (4-byle) vord.
Three quanlilies have lo be slored: (1) lhe sign, (2) lhe exonenl (over of
2), and (3) lhe fraclion/manlissa/significand.
We demonslrale lhe rocess simuIlaneousIy for four decimaI numbers: 5,
0.1, 254, 0.03125 .
Iirsl, nnrma!isc lhe number by muIliIying/dividing by 2 unliI lhere is a
1 before lhe radix oinl (decimaI or binary oinl, il is lhe same in lhis case),
lhis gives lhe binary equivaIenl of scienlific nolalion, demanding a non-
zero before lhe radix oinl. e.g.
5 1.25 2
2
0.1 1.6 2
-4
254 1.984375 2
7
0.03125 1.0 2
-5
Second, add 127 tn thc cxpnncnt nI 2. This makes il a biased exonenl. Il
avoids having lo slore negalive vaIues of lhe exonenl. Of course, lhis is
excess 127 nolalion, as described earIier as one of lhe ossibIe
mechanisms for reresenling osilive/negalive (signed) inlegers.
Third, discard thc 1 prcccding thc binary pnint! Since ve knov il's lhere,
lhere's no need lo slore il! We are aIIoved lhis riviIege because ve have
gone lo lhe lroubIe of normaIising lhe number.
Our four examIe numbers nov require lhe foIIoving vaIues lo be slored
(nole lhal lhe Ieading 1 has been reIaced by a 0):
5 > 0.25 and 2
129
0.1 > 0.6 and 2
123
254 > 0.984375 and 2
134
0.03125 > 0.0 and 2
122
Ior each, ve have lo slore a fraclion and an exonenl. We converl lhe
above decimaI airs lo binary form:
Iraclion: Ixonenl:
0.25 0.0100 0000 0000 0000 0000 0000 129 10000001
0.6 0.1001 1001 1001 1001 (hex 9 reealing) 123 01111011
FIT1001 Computer Systems
48
0.984375 0.1111 1100 0000 0000 0000 0000 134 10000110
0.0 0.0000 0000 0000 0000 0000 0000 122 01111010
The formal of lhe Shorl/SingIe InleI fIoaling-oinl vord is:
Sign I x o n e n l <------------ I r a c l i o n ----------------->
il Numbers 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
<1> <-- - 8 bils ---- --> <----------------- 23 bils -------------------->
Bit 31 slores lhe sign (0 osilive, 1 negalive).
Bits 23 - 30 slore lhe biased (excess 127) exonenl of 2.
Bits 0 - 22 slore lhe normaIised fraclion (manlissa, significand).
Ior lhe four examIe numbers, ve lherefore gel lhe foIIoving binary
reresenlalions:
il Numbers
31 30 .. 23 22 . 0
5 0 1 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0.1 0 0 1 1 1 1 0 1 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 1
254 0 1 0 0 0 0 1 1 0 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0.03125 0 0 1 1 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
In summary, for a 32-bil Shorl/SingIe fIoaling-oinl dala vaIue:
1. The 32 bil vord is divided inlo lhree arls.
2. The sign of lhe number is in bil 31.
3. The exonenl, i.e., lhe over of 2 lhal lhe manlissa is muIliIied by,
is in bils 23 - 30. Il has had 12710 added lo il (a "bias") so lhal
negalive vaIues do nol have lo be slored.
4. The manlissa (or fraclion or significand) is slored in bils 0 - 22,
vhich is onIy 23 bils. Hovever, lhe number is reaIIy accurale lo 24
bils, because lhere is an imIied 1 before lhe binary oinl, vhich
does nol have lo be slored.
The range of vaIues lhal lhis reresenlalion can slore is aroximaleIy 1.4
10
-45
lo 3.4 10
38
, vilh 7 or 8 significanl decimaI digils.
There are lvo furlher oinls lo nole. iased exonenls vilh vaIues 0 or 255
are regarded as seciaI cases.
5pccia! va!ucs nI thc biascd cxpnncnt:
If lhe biased exonenl is 255, lhen
If lhe sign bil is 0 and lhe manlissa is 0, lhis reresenls +InIinity,
Study Guide 2: Data Representation and Computer Arithmetic
49
If lhe sign bil is 1 and lhe manlissa is 0, lhis reresenls -InIinity,
If lhe manlissa is nol 0, lhis reresenls a NAN, i.e. Nol-a-number.
If lhe biased exonenl is 0, lhen
If lhe manlissa is 0, lhe number is 0.0 (zero),
If lhe manlissa is nol 0, lhe number is a dcnnrma!, and reresenls lhe
vaIue
2
-126
x 0.n , vhere n is lhe lrue manlissa (i.e. no Ieading 1 is imIied before
lhe binary oinl). The sign bil (31) sliII has effecl.
The foIIoving is a denormaI, zero exonenl, binary manlissa 0.0000 11012 ,
hexadecimaI 0.0D16 .
Bit Numbers 31 30 23 22 0
0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
The Long/Double Floating Point Format
This is similar to the 32-bit Short/Single floating-point format:
1. The vord Ienglh is 64 bils 8 byles.
2. The 64 bil vord is divided inlo 3 arls.
3. The sign of lhe number is in bil 63.
4. The 11-bil biased exonenl is slored in bils 52 - 62. A bias of 102310
has been added, so lhal negalive vaIues do nol have lo be slored
(excess 1023 nolalion).
5. The manlissa (or fraclion or significand) is slored in bils 0-51, vhich
is onIy 52 bils. The number is accurale lo 53 bils, because lhere is an
imIied 1 before lhe binary oinl.
The range of vaIues lhal lhis reresenlalion can slore is aroximaleIy 4.9
10
-324
lo 1.8 10
308
, vilh 15 or 16 significanl decimaI digils.
Infinities and NANs (exponent 2047), and denormals are similar to those for
the Short format.
The Temporary / Extended Floating Point Format
This is (mostly) similar to the 32-bit Short/Single floating-point format:
1. The vord Ienglh is 80 bils 10 byles.
2. The 80 bil vord is divided inlo 4 arls.
3. The sign of lhe number is in bil 79.
FIT1001 Computer Systems
50
4. The 15-bil biased exonenl is slored in bils 64 - 78. A bias of 1638310
has been added, so lhal negalive vaIues do nol have lo be slored
(excess 16383 nolalion).
5. A binary 1 is slored in bil 63. (Therefore denormaIs are nol
suorled).
6. The manlissa (or fraclion or significand) is slored in bils 0.62, so
lhal incIuding lhe 1 in bil 63, lhe number is accurale lo 64 bils. This
ensures 19-decimaI-digil recision.
The range of vaIues lhal lhis reresenlalion can slore is aroximaleIy 1.7
10
-4932
lo 1.1 10
4932
, vilh 19 or 20 significanl decimaI digils.
Infinities and NANs (exponent 32767) are similar to those for the Short
format.
Rcad NuII and Lobur, chaler 2, ages 55 (from 2.5) - 62 (lo 2.6)
Web Access
Wcb Acccss Access 5tudy Guidc 2 seclion of lhe unil vebsile and
comIele Iab / luloriaI exercises.
Study
Guide
!
Overview of
Boolean Algebra and
Digital Logic
LEARNING OBJECTIVES
Al lhe comIelion of lhis sludy guide you viII be abIe lo:
read and undersland informalion in a lrulh labIe,
undersland lhe behaviour of Iogic gales (AND, OR, XOR, NOT,
NAND, NOR) and knov lheir Iogic symboIs and lrulh labIes,
undersland lhal Iogic gales may be inlerconnecled in numerous
vays lo creale combinalionaI Iogic circuils,
converl a combinalionaI Iogic circuil inlo ils corresonding
exression in ooIean aIgebra and vice versa,
use a given sel of ooIean aIgebra ruIes lo simIify or olhervise
maniuIale exressions reresenling Iogic circuils inlo nev bul
equivaIenl forms,
undersland severaI combinalionaI Iogic circuils imorlanl in
comuler hardvare (!"# %&''()**+,-. *+/0*+,-. 1&'234'+5+,-. +2/),
undersland lhe use of feedback lo creale sequenliaI Iogic
circuils vilh memory caabiIilies (!"# %'34(%'04-. ,+"3-2+,-. 678-..
+2/),
areciale lhe oeralion of muIlioinl buses and lri-slale
oululs,
use a Iogic simuIalor rogram lo sludy and Iearn aboul various
digilaI Iogic circuils used in comuler hardvare.
FIT1001 Computer Systems
"#
Contents
3.1 Inlroduclion
3.2 Logic Gales and Trulh TabIes
3.3 ooIean AIgebra
3.4 CombinalionaI Logic Circuils
3.5 SequenliaI Logic Circuils
3.6 Tri-Slale Oululs
3.7 SequenliaI Circuil Overviev
Reading
Prescribed readings
NuII and Lobur, !--+923)'- 0% :014&2+, ;,")93<)2309 = 7,/>32+/2&,+#
Chaler 3: ooIean AIgebra and DigilaI Logic
Study Guide 3: Overview Boolean Algebra and Digital Logic
"!
3.1 Introduction
DigilaI comulers maniuIale and rocess informalion reresenled by
sels of numbers. The binary number syslem is used because lhe eIeclronic
circuils needed lo slore, maniuIale, and do arilhmelic on binary digils
are far simIer lhan for any olher number base. These circuils can be buiIl
from sels of simIe svilches, or more arlicuIarIy +'+/2,3/)''? /092,0''+*
-@32/>+-A (ie. an eIeclricaI svilch lhal can be lurned "on" or "off " - bul onIy
by a conlroI signaI.)
Some very earIy comulers used eIeclromagnelic reIays or vacuum lubes
as lheir +'+/2,3/)''? /092,0''+* -@32/>+-A These vere buIky, over hungry and
unreIiabIe. These shorlcomings disaeared in lhe 1950s vilh lhe arrivaI
of semiconduclor or -0'3* -2)2+ lechnoIogies. Semiconduclors are maleriaIs,
such as lhe eIemenl siIicon, vhose Iov eIeclricaI conduclivily in lhe ure
form can be boosled many limes by *0439" lhem vilh minule lraces of
seIecled imurilies. Tvo lyes of doing are ossibIe, giving 9(2?4+ and 4(
2?4+ maleriaI. These bolh conducl eIeclricily veII, bul use differenl
conduclion mechanisms al lhe alomic IeveI.
In 1947 scienlisls discovered lhal a sandvich of n--n semiconduclor
maleriaIs aIIoved lhe IeveI of eIeclric currenl fIoving lhrough il lo be
aIlered by a veak conlroI signaI inserled al lhe mid-oinl. This currenl
amIifier vas named lhe !"#$%&%!'". When used as an eIeclricaIIy
conlroIIed svilch il vas fasl, comacl, Iov-over and reIiabIe - exaclIy
vhal vas needed lo buiId digilaI comulers.
A more recenl lransislor lye is lhe IieId-Iffecl-Transislor. This is formed
using a MelaI-Oxide-Semiconduclor (MOS) sandvich. These 8;BC!D-
use lhe eIeclric fieId of a conlroI voIlage aIied lo lhe melaI Iayer lo
enIarge or reduce a conducling channeI in lhe semiconduclor Iayer. The
oxide Iayer (siIicon dioxide) insuIales lhe melaI Iayer from lhe conducling
channeI. The channeI ilseIf may use eilher n-lye or -lye maleriaI giving
eilher NMOS or IMOS lye lransislors.
ComIemenlary MelaI-Oxide-Semiconduclor (or CMOS) circuils use airs
of NMOS and IMOS lransislors lo roduce digilaI devices vilh exlremeIy
Iov-over consumlion al Iov lo moderale svilching rales. CMOS
lechnoIogy has savned a huge markel in orlabIe ballery oeraled
digilaI Iogic devices.
FIT1001 Computer Systems
"$
3.2 Logic Gates and Truth Tables
The buiIding "brick" of digilaI Iogic circuils is lhe (')&* )#!,. SeveraI
usefuI lyes exisl. Iach lye is formed using an eIeclronic circuil
conlaining from one lo six lransislors. WhiIsl lhe individuaI lransislors
oerale over a range of voIlages, lhe overaII Iogic gale circuil has ils
oeraling voIlages reslricled lo |usl a "Iov-range" and a "high(er)- range".
These lvo ranges aIIov gale inuls and lhe gale oulul lo reresenl eilher
binary vaIues (0 or 1) or Iogic vaIues (faIse and lrue).
To describe lhe behaviour of a Iogic gale, ve need lo accuraleIy slale hov
ils oulul behaves as ils inuls vary. Since a Iogic gale's inuls are binary
ralher lhan conlinuous variabIes, lhere are a Iimiled number of inul
combinalions for vhich ve musl describe lhe gale's oulul. This
informalion can be resenled in a shorl labIe knovn as a !"-!. !#/(,. The
gale's I/O vaIues are commonIy Iisled in lrulh labIes using 1s and 0s, or
somelimes 2,&+ and %)'-+. These labIes assume lhe assignmenls: E>3">+,
F0'2)"+ ,)9"+ G HG 2,&+E )9* E'0@ F0'2)"+ ,)9"+ G I G %)'-+EA
NOT, AND and OR are lhe basic Iogic oeralions. Logic gales lo
imIemenl lhem are readiIy avaiIabIe. The XOR gale is aIso videIy used,
as are lhe NAND, NOR, and XNOR gales vhich have inverled oululs
comared lo lhe gales from vhich lhey vere derived. The symboIs used
lo reresenl lhese gales in Iogic circuils, lhe corresonding lrulh labIes,
and lhe common malhemalicaI nolalions used for lhese Iogic oeralions
are given beIov. The NOT gale has a singIe inul and is lhe simIesl Iogic
oeralion. The olher Iogic oeralions are shovn in lheir 2-inul forms,
aIlhough gales vilh more inuls are aIso commonIy used.
The %&' (or /014'+1+92) oeralion gives an oulul lhal is lhe IogicaI
inverse of lhe singIe inul. The smaII circuIar arl of lhe circuil symboI
acluaIIy signifies lhe inversion. Il is referred lo as an 39F+,-309 or
/014'+1+92 EJ&JJ'+E. Il may aear in olher gale symboIs lo indicale a
Study Guide 3: Overview Boolean Algebra and Digital Logic
""
oinl of IogicaI inversion. This is mosl oflen used on lhe oulul Iine (eg.
NAND, NOR), bul il may aIso be used on inul Iines.
The (%) oeralion belveen lvo or more binary inuls yieIds an oulul
vaIue of 1 onIy vhen aII of lhe inuls are 1, olhervise lhe oulul viII be 0.
The &* oeralion belveen lvo or more binary inuls yieId an oulul
vaIue of 1 vhenever al Ieasl one inul is 1. The oulul viII be 0 onIy if aII
inuls are 0.
The sel of NOT, AND, OR Iogic oeralions is caIIed a &93F+,-)' -+2 because
any olher Iogic gale, or arbilrariIy comIex Iogic oeralion, can be
imIemenled by viring logelher various combinalions of lhese lhree basic
Iogic gales. We nole lhe "slrenglh" of each gale oulul is normaIIy
sufficienl lo drive u lo eighl or so inuls of foIIoving gales. This aIIovs
more comIex circuils lo be designed using severaI "IeveIs" of Iogic gales.
In raclice XOR/XNOR gales are imIemenled as a circuil of olher gales
bul for convenience lhis is given an individuaI gale symboI.
The NAND and NOR gales are of inleresl as searaleIy each of lhem is a
universaI gale and each of lhem can be used lo imIemenl any Iogic
oeralion. (+"A 2>+? /)9 314'+1+92 2>+ K;D 04+,)2309 J? /099+/239" 2>+3, 2@0
394&2 '39+- 20"+2>+, 3920 ) -39"'+ 394&2A D>+ L(,0@ 2,&2> 2)J'+ 2>+9 ,+*&/+- 20 2>+
M(,0@ K;D 2,&2> 2)J'+A)
The NAND gale is of arlicuIar inleresl in severaI siIicon lechnoIogies
vhere il is bolh lhe cheaesl and smaIIesl gale lo roduce as il needs
fever lransislors. Oflen a comIex circuil is converled inlo ils NAND-
onIy equivaIenl. AIlhough aearing lo need more gales, il may acluaIIy
use fever lransislors and a smaIIer area of siIicon lhan a direcl
imIemenlalion of lhe originaI circuil vouId use.
What Can Using Logic Gates Tell Us?
The aIicalions of Iogic gales fIov from a sludy of lheir lrulh labIes.
They can heI us make decisions aboul vhelher arlicuIar reIalionshis
exisl belveen cerlain binary variabIes. Using lhe aroriale gale, ve can
ansver any of lhe queslions:
Is a seIecled binary signaI faIse` |use a NOT galej
Are lvo seIecled binary signaIs differenl` |use an XOR
galej
Are lvo seIecled binary signaIs lhe same` |use an XNOR
FIT1001 Computer Systems
"+
galej
Is al Ieasl one binary signaI in a grou lrue` |use an OR galej
Are aII binary signaIs in a grou simuIlaneousIy
lrue`
|use an AND
galej
Are aII binary signaIs in a grou simuIlaneousIy
faIse`
|use a NOR galej
Is al Ieasl one binary signaI in a seIecled grou faIse` |use a NAND
galej
NK02+# ) 2,&+ 0&24&2 1+)9- ) E?+-E )9-@+, 20 2>+ O&+-2309AP
Some lyes of Iogic robIem aIIov us lo arlilion a verbaI descrilion of
lhe required behaviour of a Iogic circuil inlo smaIIer ieces. Il may lhen be
obvious vhich Iogic gale can be used lo "soIve" each iece of lhe robIem
and aIso vhal gales are needed lo combine aII of lhe arliaI soIulions inlo
a fuII soIulion of lhe originaI design robIem.
Assume lhal in lhe design of some iece of comuler hardvare, lhe
foIIoving secificalion arises in regard lo binary lhe signaIs, v, x, y and z:
B3"9)' E<E 1&-2 J+ H @>+9 -3"9)' E@E 3- H )9* +32>+, -3"9)' E5E 0, -3"9)' E?E 3-
HA B3"9)' E<E 1&-2 )'-0 J+ H @>+9+F+, -3"9)' E@E )9* -3"9)' E?E >)F+ *3%%+,+92
F)'&+-A
We couId soIve lhis design robIem by breaking u bolh of ils senlences
inlo smaIIer arls and seIecling lhe aroriale Iogic gale lo soIve each
arl:
Direcl lransIalion of "vords inlo Iogic gales" is nol aIvays
slraighlforvard, nor does il guaranlee lhe resuIling Iogic circuil is lhe besl
vay lo soIve lhe robIem. A more recise aroach is lo exaclIy secify
lhe circuil behaviour required using a lrulh labIe. A Iogic circuil having K
inuls and 8 oululs, (vilh no feedback of lhe oululs), has a lrulh labIe
Study Guide 3: Overview Boolean Algebra and Digital Logic
",
of 2
K
rovs and KQ8 coIumns. The oululs can aIso be reresenled
malhemalicaIIy as ooIean aIgebra exressions.
3.3 Boolean Algebra
In 1854 George ooIe rovided an aIgebraic framevork for IogicaI
lhinking. He inlroduced lhe IogicaI comIemenl, IogicaI roducl, and
IogicaI sum oeralors. They vere aIied lo variabIes lhal reresenled
cIasses or coIIeclions of ob|ecls. Laler in 1938, CIaude Shannon found lhal
vhen lhis aIgebra vas reslricled lo lvo-vaIued variabIes, lhe IogicaI
oeralors became lhe NOT, AND, and OR as reviousIy defined. He
found lhis form (somelimes caIIed -@32/>39" )'"+J,)), vas heIfuI in lhe
design and simIificalion of his reIay-based Iogic circuils.
DigilaI Iogic circuils can be reresenled by ooIean exressions comosed
of IogicaI oeralors and binary variabIes or conslanls. These may be
lransformed using lhe ruIes of lhe aIgebra inlo nev bul equivaIenl
exressions vhose vaIues vouId be idenlicaI lo lhe originaI for aII inul
combinalions. The Iogic circuils corresonding lo lhe nev exressions
vere eilher simIer, so reducing lhe gale counl, or lhey used one
referred lye of Iogic gale. !"# lhe 5-gale Iogic circuil reviousIy given
for oulul 'z', can be reresenled by lhe ooIean exression:
This can be maniuIaled by lhe ruIes of ooIean aIgebra inlo lhis (3-gale)
form:
To verify lhal lhese exressions roduce lhe same lrue or faIse vaIues for
each and every combinalion of lhe inul variabIes, a lrulh labIe for each
exression can be buiIl and lhe oululs comared. To buiId a lrulh labIe
for a ooIean exression, ve evaIuale each lerm in lhe exression vhiIe
adhering lo lhe recedence ruIes of ooIean aIgebra. The recedence ruIes
are:
1) rackeled lerms are aIvays evaIualed firsl.
2) ComIemenled lerms are evaIualed nexl. (ie. NOT oeralions.)
3) AND oeralions are lhen erformed.
4) OR oeralions are erformed Iasl.
FIT1001 Computer Systems
"-
The labIe over age shovs lhe resuIl of lhis rocess for bolh of lhe
exressions for 'z'. Il shovs bolh exressions have idenlicaI vaIues for aII
inul combinalions.
Transformalion of a ooIean exression inlo a differenl form vilhoul
changing ils vaIue can be achieved using ooIean idenlilies. These are
Iavs lhal describe aIIovabIe lyes of lransformalions. The labIe beIov
shovs lhe equivaIenl lerms lhal may be used in ooIean aIgebra vork lo
maniuIale or simIify any Iogic circuil. The Iellers A, , and C can
reresenl any binary variabIe, or any ooIean aIgebra lerm, or even an
enlire ooIean aIgebra exression.
Nole lhere are lvo sels of equalions, IabeIed lhe AND form and lhe OR
form. This arises from lhe 0-#(&!1 2"&$*&2(, of ooIean aIgebra. This slales
lhal if lvo exressions are equaI, lhen lhe duaIs of lhose exressions viII
aIso be equaI lo each olher. The duaI of any exression is found by
carrying oul lhese lvo sles:
1) ReIace aII originaI AND oeralors vilh lhe OR oeralors and vice
versa.
2) If lhe exression conlains binary conslanls, reIace 0s vilh 1s and vice
versa.
*./0 NuII and Lobur, chaler 3, ages 93-100 (lo 3.2.5)
Study Guide 3: Overview Boolean Algebra and Digital Logic
"1
(2345436 Confirm and enhance your underslanding of ooIean aIgebra by
doing lhe exercises given beIov from ages 124-125 of NuII &
Lobur:
Ixercises: 1, 2, 3, 4, 6, 9, 10a, 11a, 12c, 13c & 14.
Literals, Products, Sums, and Standard Forms
A (&!,"#( in a ooIean exression is a variabIe or lhe comIemenl of a
variabIe. IxamIe: x, y, z'. A IileraI may be lrue or faIse.
A 2"'0-*! !,"3 is a singIe IileraI or a Iogic roducl (AND) of lvo or more
IileraIs. IxamIes: z, xy, xy'z, x'yz'. A roducl lerm viII onIy be lrue if
aII ils member IileraIs are lrue.
A %-3 !,"3 is a singIe IileraI or a IogicaI sum (OR) of lvo or more IileraIs.
IxamIes: z', (x' + z), (x + y + z), (x + y' + z'). A sum lerm is aIvays lrue
unIess aII of ils member IileraIs are faIse.
Using lhe above definilions, il is ossibIe lo converl any lrulh labIe of a
Iogic funclion inlo a ooIean exression lhal conforms vilh eilher of lvo
slandard formals. The firsl is caIIed lhe %-34'542"'0-*!% formal (SOI),
vhiIe lhe second is caIIed lhe 2"'0-*!4'54%-3% formal (IOS). We shaII
deaI onIy vilh lhe firsl formal , as maniuIalions of exressions in lhis
formal are easier as lhe reIevanl ooIean Idenlilies more cIoseIy resembIe
lhe Iavs of ordinary aIgebra.
In generaI, severaI SOI forms of a funclion may exisl, each vilh a
differenl IeveI of simIificalion. Hovever a unique *#$'$&*#( 678 5'"3
exisls vhere aII lhe roducls beIong lo a seciaI cIass caIIed 9&$!,"3%.
These conlain exaclIy one occurrence of each variabIe, eilher
comIemenled or nol comIemenled. The advanlage of lhis slandard form
is lhal il can be vrillen dovn direclIy from a lrulh labIe. Iach labIe rov
vilh a lrue oulul vaIue Ieads lo one Minlerm in lhe exression. Iach
Minlerm roducl is found by examining lhe inul vaIues for lhal rov.
Where an inul is equaI lo 0, lhen lhal variabIe musl aear in lhe
roducl as comIemenled. Where an inul is equaI lo 1, lhen lhal variabIe
musl aear in lhe roducl as nol comIemenled.
IxamIe: I(x,y,z) has lhe lrulh labIe beIov. Whal is ils canonicaI SOI
form`
FIT1001 Computer Systems
+7
The advanlage of lhe canonicaI SOI form (aIso caIIed B&1(;%(8392+,1-
form), is lhal a ooIean exression can be easiIy vrillen dovn for any
lrulh labIe. The corresonding Iogic circuil foIIovs slraighl from lhe
exression. In lhis case 3xNOT, 4xAND, Ius 1 OR gale is needed.
Hovever il is oflen ossibIe lo find a simIer SOI circuil lhal viII yieId
lhe same oulul. Hov can lhis be done`
The key lo simIifying canonicaI SOIs is lo find airs of rovs in lhe lrulh
labIe lhal bolh have a lrue oulul, yel differ onIy in one inul vaIue. The
examIe above, rov numbers 2 & 3 are such a air. The onIy difference in
lhese is lhe vaIue of variabIe "z". We nole bolh rovs have x0 and y1, and
lhal lhese are lhe onIy rovs vhere lhis is lhe case. The simIer roducl
lerm x'y, vhich is lrue onIy under lhese condilions, can reIace lhe air of
roducls reviousIy used lo generale lrue vaIues for rovs 2 & 3. (3+. x'y
can reIace lhe sum: x'yz' + x'yz ).
SimiIarIy, rov numbers 1 & 5 are anolher air. This lime il is onIy lhe
vaIue of variabIe x lhal is differenl. The simIer roducl y'z can reIace
lhe sum of lhe firsl and Iasl Minlerms. (3+. y'z x'y'z + xy'z ). The
simIified Iogic exression is I(x,y,z) x'y + y'z This can be
imIemenled as a circuil using |usl 2xNOT, 2xAND, Ius 1 OR gale. Nol
onIy is lhe number of gales reduced bul lhe number of inuls a gale has,
(R90@9 )- 2>+ ")2+ @3*2>) is Iovered in mosl cases. The cosl and hysicaI
size of lhe circuil have been minimised by using lhis rocess.
The same minimisalion sles can aIso be aIied using lhe ooIean
idenlilies given earIier. In lhe aIgebra melhod, lhe exression is searched
for a air of roducls lhal differ onIy in one IileraI. This air can lhen be
simIified and lhen lhe search conlinued. The sles for lhe given examIe
are:
Study Guide 3: Overview Boolean Algebra and Digital Logic
+8
A difficuIly vilh lhe aIgebra simIificalion melhod occurs vhen a
roducl lerm differs by exaclIy one IileraI from lvo or more olher lerms.
If lhis is nol delecled in lime, lhe lerm mighl be "consumed" in one
airing and so nol be avaiIabIe lo be used in simIifying lhe olher air(s).
The soIulion is lo reeal lhe lerm so il may be used in muIliIe airings.
Reealing a lerm is ermilled by lhe ooIean idenlily: x x + x. Reealing
a sum lerm does nol aIler an exression's vaIue.
*./0 NuII and Lobur, chaler 3, ages 100 (from 3.2.5) 102 (lo 3.3)
(2345436 Confirm and enhance your underslanding of ooIean aIgebra
by doing lhe foIIoving aIgebra exercises from ages 125-127 of
NuII & Lobur:
Ixercises: 18, 19, 22, 25, 26, 27, & 28.
3.4 Combinational Logic Circuits
A combinalionaI Iogic circuil is one lhal has severaI inuls and one or
more oululs, vilh lhe roerly lhal each oulul deends onIy on lhe
currenl vaIue of one or more inuls and can be reresenled by a ooIean
exression. IxamIes incIude buiIding bIocks such as,
lhe haIf-adder, vhich is used lo erform addilion of binary vaIues,
lhe decoder, vhich uses an K-bil binary number aIied al lhe
inuls lo aclivale exaclIy one of 2
K
numbered oululs,
lhe muIliIexer, vhich uses an K-bil seIeclion code lo choose one
of 2
K
numbered dala inuls and lransfers dala from lhe seIecled
inul lo a singIe oulul,
lhe arily generalor , vhich examines an K-bil dala vord and
forms an oulul arily bil so lhe number of "1"s resenl in lhe
combined arily and dala vord is eilher odd or even deending
on ils configuralion,
lhe comaralor, vhich comares lvo binary vaIues and resenls
1 al lhe oulul if lhe vaIues are lhe same,
and many olhers.
One imorlanl combinaloriaI circuil lhal is ilseIf comosed of many of lhe
circuils menlioned above is lhe Arilhmelic Logic Unil (or ALU). This is a
FIT1001 Computer Systems
+#
ma|or comonenl of lhe CenlraI Irocessing Unil (CIU) resenl in every
comuler.
*./0 NuII and Lobur, chaler 3, ages 106 (from 3.5) 113 (lo 3.6)
(2345436 Access lhe 93:06 <:40. ! seclion of lhe unil vebsile and
famiIiarise yourseIf vilh lhe Iogic simuIalor rogram rovided.
Use lhe Iogic simuIalor lo sludy lhe combinalionaI Iogic circuils
as oulIined in lhe documenl "Logic SimuIalion Ixercises 1".
3.5 Sequential Logic Circuits
SequenliaI Iogic circuils are aIso conslrucled from basic Iogic gales and
aIso have one or more inuls and oululs. Hovever unIike combinalionaI
circuils, lheir oululs can deend on revious inul vaIues as veII as lhe
currenl inul vaIues. This occurs because lhese circuils conlain memory
eIemenls. Il is lhe combinalion of lhe currenl inuls, and lhe inlernaIIy
memorised vaIues lhal delermines bolh lhe currenl oululs, and vhal lhe
nexl slale of lhe memory eIemenls viII be.
Memory eIemenls are formed using feedback alhs. These aIIov a gale lo
sense ils ovn oulul. Consider lhe OR gale feedback circuil beIov. Nole
hov lhe lime- Iols of inul signaI "SIT", and lhe oulul signaI "MIM",
shov a memory effecl.
WhiIsl lhis circuil viII remember if ils SIT inul goes lrue, il can never
forgel il! A means of cIearing or reselling lhis basic memory eIemenl is
needed. This can be done by inslaIIing an AND gale "svilch" in lhe
feedback alh as shovn beIov.
WhiIe CLR0, lhe AND gale svilch cIoses lhe feedback Ioo and lhe
circuil viII remember a SIT1 uIse as before. Hovever, vhen CLR1 lhe
Study Guide 3: Overview Boolean Algebra and Digital Logic
+!
AND gale "culs off " lhe feedback signaI. The oulul viII lhen become 0
(roviding lhal SIT0). This gives a circuil lhal can be SIT, or RISIT, on
command. The circuil's currenl slale is heId unliI a nev slale is
commanded. In effecl il lhe circuil can "slore" eilher a binary 0 or a binary
1. Il is a 1-bil "slorage", or "memory" eIemenl.
AIlhough lhe oeralion of lhis circuil is quile slraighl forvard, il is
inefficienl lo imIemenl as il conlains lhree gales, each of a differenl lye.
The simIer circuil beIov uses |usl lvo NOR gales and exhibils essenliaIIy
lhe same memory effecl.
The memory circuil examIes above reacl immedialeIy lo any nev inul
signaIs. A more convenienl arrangemenl is lo inlroduce an overriding
conlroI signaI "C" lhal can diclale exaclIy vhen lhe memory circuil is
ermilled lo "see" ils SIT and RISIT inuls. The circuil beIov shovs a
cosmelic rearrangemenl of lhe NORs inlo a cIassic "cross-couIed"
configuralion. Il aIso shovs hov lvo AND gales can be inlroduced lo
aIIov a conlroI signaI "C" lo govern vhen lhe S(Sel) and R(Resel) inuls
are acled on. The revious "MIM" oulul is renamed as "Q".
SignaI "C" conlroIs exaclIy vhen lhe slale of lhe memory may change. Il is
knovn as a *('*: %&)$#(. OnIy vhen C1 can SIT or RISIT oeralions
occur.
This basic memory eIemenl is lermed a )#!,0 6; <#!*., aIlhough some
aulhors may use lhe name 6; 5(&245('2. TechnicaIIy fIi-fIos are more
comIex designs vhere lhe cIocking aclion is +*"+(2,3""+,+* ralher lhan
'+F+'(2,3""+,+* as in lhe examIe shovn. This means lhe fIi-fIo samIes
ils inuls onIy al lhe inslanl lhe cIock signaI changes ils Iogic IeveI.
S0-323F+ +*"+(2,3""+,+* fIi-fIos are lhe more common. These use a 0 lo 1
change in cIock IeveI lo lrigger lhe accelance of nev vaIues al lhe S and
R inuls. The fIi-fIo ignores lhose inuls al aII olher limes.
ComIex sequenliaI circuils oflen use a dislribuled cIock signaI lo
synchronise lhe accelance of nev inuls lhroughoul lheir various sub-
FIT1001 Computer Systems
+$
circuil comonenls. During lhe lime eriod in belveen lhe aclive cIock
edges, lhe memory eIemenls viII simIy hoId lhe slales lhey allained on
lhe Iasl cIock cycIe, regardIess of any inul varialions lhal may occur
during lhis lime.
In addilion lo lhe shorl feedback alhs needed lo creale lhe memory
eIemenls lhemseIves, sequenliaI circuils aIso fealure Iong feedback alhs
vhere an oulul signaI from a fIi-fIo viII be fed back lhrough a
ossibIy comIex combinalionaI Iogic circuil lo finaIIy emerge as a nev
fIi-fIo inul. Inough lime is needed belveen successive cIocks for a
nev sel of oululs lo roagale aIong lhese feedback alhs and give a
slabIe sel of fIi-fIo inuls. Iach IeveI of gales lhe signaI musl ass
lhrough viII sIighlIy deIay lhal signaI's arrivaI. This Iimils lhe maximum
rale al vhich a sequenliaI circuil can be cIocked and yel sliII accuraleIy
foIIov lhe designed behaviour.
*./0 NuII and Lobur, chaler 3, ages 115 (from 3.6) 117 (lo 3.6.4)
Nole lhal:
1) Iigures 3.19 & 3.20a are mosl robabIy lransosed.
2) The aragrah beIov labIe 3.13 conlains errors:
(S'+)-+ ,+%+, 39-2+)* 20 2>+ ')-2 /3,/&32 "3F+9 )J0F+ )9* /09-3*+, 2>)2 3%
BG6G:GH. 2>+9 TGI )9* TUGIA D>3- 3- 39 %)/2 ) -2)J'+ /09*32309A 7
4,0J'+1 @3'' 0//&, 3% : "0+- '0@A D>+ 2@0 K;6- @3'' 2>+9 E,)/+E +)/>
02>+, 20 J+ 2>+ %3,-2 20 4,0*&/+ ) >3"> 0&24&2A D>+ E@399+,E 3- *+2+,139+*
J? -1)'' 1)9&%)/2&,39" *3%%+,+9/+- )9* 902 J? 2>+ /3,/&32 *+-3"9A D>+
40--3J3'32? 0% BG6GH 3- +'3139)2+* J? 2>+ /3,/&32 10*3%3/)2309- ->0@9 09
4)"+ HHVA D>+-+ "3F+ +32>+, 2>+ EWE. 0, 2>+ EXYE 2?4+ 0% %'34(%'04A)
Registers
Grous of D-lye Ialches, or D-lye fIi-fIos, oeraling in araIIeI and
lriggered by lhe same cIock signaI, form Iarger buiIding bIocks caIIed
",)&%!,"%. A regisler buiIl using K fIi-fIos is abIe lo calure (or =('#0=)
various K-bil binary vords. Common regisler vidlhs are 8, 16, 32 and 64
bils. The binary vord is "heId" or "remembered" by lhe regisler, and may
be used again al some Ialer lime by oululling il from lhe regisler.
The CenlraI Irocessing Unil (CIU) of a comuler syslem has regislers as
one of ils main comonenls. Deending on lhe CIU design lhere may be
Iess lhan 10 regislers or more lhan one hundred. CIU regislers can oflen
be searaled inlo:
Study Guide 3: Overview Boolean Algebra and Digital Logic
+"
SeciaI urose regislers: These hoId numbers lhe CIU needs lo felch
and execule sequences of inslruclions in lhe
rogram.
GeneraI urose regislers
: (or user/rogrammer
regislers)
These hoId numbers needed for lhe dala
rocessing lask lhal vas crealed by lhe
rogrammer.
Large Semiconductor Memories
Very Iarge aggregales of from 2
10
lo 2
30
one-bil slorage eIemenls are
avaiIabIe as singIe-chi semiconduclor memory unils. InlernaIIy lhey are
organised inlo 8, 16, or 32-bil slorage ceIIs caIIed memory "Iocalions".
They have inul/oulul alhs for dala of lhe corresonding number of
bils. efore dala can be vrillen lo or read from a memory unil, lhe largel
Iocalion has lo be seIecled or "#00",%%,0=.
To aIIov memory Iocalions lo be seIecled or addressed on an individuaI
basis, each one is given a unique binary number knovn as lhe Iocalion's
address. The circuil in vhich lhe memory chi is being used musl suIy
lhis number lo lhe )**,+-- 439- on lhe chi. To caler for lhe Iarge number
of memory Iocalions, u lo 20 or more address bils are needed. An
exlensive inlernaI decoding syslem lhen examines lhe address vord and
aclivales onIy lhe addressed Iocalion. A searale conlroI signaI viII
delermine vhelher a read or vrile oeralion is erformed.
Iigure 3.25 (on age 120 of NuII and Lobur) shovs a memory circuil vilh
four 3-bil vords. Iach bil is slored in a D-lye fIi-fIo, arranged inlo
four banks of lhree fIi-fIos each. The 2-bil address vord (S1, S0) is
decoded by lhe vord seIecl Iogic lo enabIe onIy lhe oululs of lhe
addressed bank of fIi-fIos. These oululs are galhered logelher by lhe
OR gales and oulul as a 3-bil dala vord on lhe righl. If lhe Wrile InabIe
Iine is lrue, a cIock signaI viII be direcled lo aII lhree fIi-fIos in lhe
seIecled bank. This viII lhen Ioad a nev vord from lhe dala inuls on lhe
Iefl inlo lhe seIecled 3-bil memory ceII.
Nole lhe diagram reresenls a concel. A beller reresenlalion vouId use
lhe simIer D-Ialches for lhe slorage eIemenls ralher lhan fIi-fIos. Mosl
memory chis are asynchronous devices and have no cIock inul. Nole
aIso lhal exanding lhe 1-D array of slorage ceIIs lo a very Iarge size
needs a Iol of Iogic lo decode Iong address vords and gives comIicaled
viring of lhe numerous ceII enabIe signaIs.
FIT1001 Computer Systems
++
Arranging lhe Iocalions in a 2-D array reduces lhese robIems. The
address vord is lhen divided inlo lvo arls lhal are decoded searaleIy.
This roduces a sel of ,0@ -+'+/2 Iines and a sel of /0'&19 -+'+/2 Iines lhal
run lhrough lhe array. Ivery Iocalion has an AND gale lo enabIe lhal
Iocalion onIy vhen lhe ad|acenl rov and coIumn Iines are bolh lrue. This
reduces lhe amounl of decoding Iogic and viring. !"# 7 -39"'+ H(0%(M
HZ
*+/0*+, 9++*- Z[.\[Z 5 HZ(394&2 7KW ")2+-. @>3'+ J&3'*39" ) 4)3, 0% H(0%(M
]
*+/0*+,- 9++*- 09'? [HM 5 ](394&2 7KW ")2+-A D>+ /0-2 )9* /014'+532? 0% @3,39"
2>+ 9+/+--),? 392+,/099+/2309- 3- )'-0 *,)1)23/)''? ,+*&/+*A
Need More Computer Memory?
Where a comuler syslem needs more memory, a "memory moduIe" may
be conslrucled by viring logelher 2
8
chis of 2
K
vords each. A Iocalion's
address viII lhen be 8QK bils Iong. The uer 8 bils of lhe address viII
be decoded by an exlernaI 1-of-2
8
decoder lo seIecl lhe arlicuIar memory
chi in lhe moduIe lhal acluaIIy conlains lhe Iocalion. The Iover K-bils of
lhe address are lhen decoded inlernaIIy vilhin lhal memory chi lo
address lhe required Iocalion.
Memories of lhe lye discussed so far are somelimes knovn as RWM (for
Read Wrile Memory) bul are more oflen caIIed RAM (for Random Access
Memory). "Random Access" refers lo being abIe lo access Iocalions in any
order vilh lhe same access lime for any Iocalion. Memory lechnoIogies
lhal use mechanicaI scanning of an olicaI or magnelic surface do nol
have lhis roerly and musl access a Iarge and varying number of
Iocalions in sequence before lhe "largel" Iocalion is avaiIabIe for reading
or vriling. These memory lechnoIogies lrade-off shorl and uniform access
limes for a Iarge increase in slorage caacily.
Static RAM (SRAM) and Dynamic RAM (DRAM)
Semiconduclor memories using a bislabIe slorage eIemenl such as a D-
Ialch, are caIIed slalic RAMs because dala is vrillen lo lhem viII remain
lhere unliI over lo lhe memory chi is disconnecled. A slalic memory
slorage ceII requires a considerabIe number of lransislors lo imIemenl.
This Iimils lhe number of bils lhal can be slored in a given area of siIicon.
CommerciaI SRAMs use a very "slreamIined" version of lhe bislabIe Ialch.
This needs onIy six lransislors er ceII and is ralher more Iike a liny
anaIogue eIeclronic circuil lhan a digilaI one.
DRAMs slore more bils/cm
2
by using a very smaII slorage ceII buiIl using
one lransislor and a liny caacilor. The caacilor is given an eIeclric
voIlage as a "1" is vrillen inlo lhe ceII. Imerfecl insuIalion causes lhe
Study Guide 3: Overview Boolean Algebra and Digital Logic
+,
caacilor voIlage lo dro avay. (3+A 32 3- E*?9)13/E). Wilhoul inlervenlion
lhe ceII viII soon relurn lo "0".
To revenl lhe corrulion of a slored 1 bil in a DRAM, il musl be sensed
and ",5",%.,0 aboul one hundred limes each second. WhiIe lhe refresh
rocess can be done on a vhoIe rov of ceIIs al a lime, il sliII comIicales
lhe memory design and increases lhe average access lime. Desile lhis,
mosl desklo comulers use DRAMs for lheir main memory because of
lheir higher bil caacily er doIIar.
Values in CPU Registers and Main Memory
eginners sludying comuler syslems somelimes vonder vhy il is
necessary for a CIU lo read and vrile vaIues lo ils inlernaI regislers as
veII as main memory Iocalions. WouIdn'l il be simIer lo |usl use main
memory lo hoId aII vaIues` There are lvo reasons vhy lhis is nol done.
IirslIy lime required for a CIU lo access ils inlernaI regislers is lyicaIIy
len limes Iess lhan lo access a main memory Iocalion. There are severaI
reasons for lhis. The main memory is hysicaIIy furlher avay and lhe
address and dala signaIs have Ionger lraveI limes. There are aIso deIays in
decoding lhe vide address vords needed lo idenlify a main memory
Iocalion as severaI IeveIs of AND gales are required lo do lhis. There are
aIso severaI IeveIs of gales invoIved in coIIecling lhe dala bils from lhe
seIecled ceII and direcling lhem lo lhe memory oulul ins.
The second reason vhy CIU regislers are needed is lhal lhe CIU musl
suIy a Iong address vord of say 32 bils if il vishes lo access a main
memory Iocalion. Many lyicaI CIU inslruclions do an ALU oeralion on
lvo slored vaIues vilh lhe resuIl vrillen lo a lhird Iocalion. Doing lhis
vilh main memory Iocalions vouId require lhree memory addresses lo be
secified in lhe inslruclion and need CIU inslruclions lhal vere more
lhan 100 bils Iong. This vouId bolh bIoal lhe size of lhe execulabIe
rograms and sIov dovn lhe seed of lheir execulion. Shorler
inslruclions can be reaIised if CIU regislers are used as lhe source, and or
lhe deslinalion, of oerand vaIues since fever bils are needed lo idenlify a
regisler.
Laler in lhe unil you viII sludy *#*., 3,3'"1 vhich is Iaced belveen
lhe CIU and main memory lo imrove a comuler's erformance. Il has
medium seed and medium caacily characlerislics, and is used lo slore
many frequenlIy accessed bul unreIaled "chunks" of a rogram's
inslruclions or ils dala.
FIT1001 Computer Systems
+-
=4.> NuII & Lobur, figure 6.1 "The Memory Hierarchy" on age 236.
Nole lhal lhe uer four Iayers of lhe yramid are aII cIassed
as semiconduclor slorage. Nole aIso lhe CIU regislers are al
lhe lo of lhe yramid, bolh in lerms of seed and cosl er bil.
(2345436 Access lhe 93:06 <:40. ! seclion of lhe unil vebsile and use
lhe Iogic simuIalor lo sludy sequenliaI circuils as delaiIed in
lhe documenl "Logic SimuIalion Ixercises 2".
3.6 Buses
Inside lhe CIU binary vaIues are moved belveen regislers and olher
comonenls using buses. IhysicaIIy a bus is a grou of conduclors lhal
aIIovs aII lhe bils in a binary vord lo be coied from a -0&,/+ comonenl
lo a *+-239)2309 comonenl. Oulside lhe CIU, buses are aIso used lo coy
vaIues belveen lhe CIU regislers and main memory, and belveen lhe
CIU regislers and lhe I/O sub-syslem.
Various bus slyIes are used for differenl aIicalions. A *+*3/)2+* or 40392(
20(40392 bus is used lo lransfer dala from a singIe source lo a singIe
deslinalion. This lye needs onIy a deslinalion cIock lo conlroI lhe dala
lransfer. A bus vilh muIliIe dala sources and a singIe deslinalion may be
imIemenled using muIliIexers lo roule each bil from lhe seIecled source
lo lhe singIe deslinalion. In lhis case a source seIecl code as veII as a
deslinalion cIock is needed lo conlroI lhe lransfer. A 3-(!&2'&$! /-% may
have many sources and muIliIe deslinalions. Il aIIovs many devices lo
use a common alhvay lo communicale vilh one anolher, bul onIy one
source/deslinalion air is abIe lo use lhe bus al any one lime.
This lye of bus is lermed /&0&",*!&'$#( because al some oinls on lhe bus,
dala may fIov in eilher direclion (bul al differenl limes). Some of lhe
allached devices may aIso be bidireclionaI in lhal lhey use lhe same
conneclions lo eilher oulul dala lo lhe bus or inul dala from il. A
muIlioinl bus is simIe lo imIemenl if each dala source device has ils
oululs connecled lo lhe shared bus Iines onIy lhrough buffer gales
equied vilh oululs knovn as a !"&4%!#!, oululs.
Study Guide 3: Overview Boolean Algebra and Digital Logic
+1
Tri-State Outputs
A slandard Iogic gale oulul may be modeIIed as having lvo lransislor
svilches lhal can eilher uII lhe oulul u lo Iogic 1 if one svilch is
cIosed, or uII il dovn lo Iogic 0 if lhe olher svilch is cIosed. This gives
bi-IeveI oeralion. To avoid a shorl circuil, lhe svilches are inlerIocked so
lhe "bolh cIosed" case never occurs.
A !"&4%!#!, '-!2-! is one vhere in addilion lo lhe normaI bi-IeveI mode, a
lhird slale is aIIoved in vhich neilher svilch is cIosed. In lhis slale lhe
oulul Iine is effecliveIy disconnecled from lhe main body of lhe Iogic
gale. This aIIovs lhe corresonding oulul bils of muIliIe sources lo be
connecled logelher lo form a shared bus Iine. OnIy one dala source al a
lime can have ils oulul buffers in lhe bi-IeveI mode and so driving lhe
bus. AII olher sources connecled lo lhe bus musl have lheir oulul buffers
in lhe lri-slale or "disconnecled" condilion al lhis lime.
(2345436 Access lhe 93:06 <:40. ! seclion of lhe unil vebsile and use
lhe Iogic simuIalor lo sludy regisler and bus circuils as delaiIed
in lhe documenl "Logic SimuIalion Ixercises 3".
3.7 Sequential Circuit Overview
The generaIised bIock diagram of a cIocked sequenliaI Iogic circuil is
shovn beIov. Il is comosed of a combinalionaI Iogic bIock and a
memory eIemenl bIock, vilh each bIock feeding signaIs inlo lhe olher.
The key fealure of a sequenliaI circuil is lhal differences in lhe bil allerns
slored in lhe fIi-fIos give il lhe allribule of &$!,"$#( %!#!,. Thal is, even
for a given sel of exlernaI inuls, lhe circuil can exisl in severaI
dislinguishabIe condilions and so lhese may roduce differenl oululs. If
a sequenliaI circuil has K fIi-fIos, lhen lhere is a maximum of 2
K
inlernaI slales.
To describe lhe behaviour of a sequenliaI circuil requires a labIe lhal Iisls
aII ossibIe combinalions of resenl slale feedback signaIs and lhe
exlernaI inul signaIs. (3+A ) /3,/&32 @32> $ %'34(%'04- )9* & +52+,9)' 394&2-.
FIT1001 Computer Systems
,7
9++*- ) 2)J'+ 0% M
N9Q3P
,0@- '3-239" )'' /01J39)2309- 0% $ )9* &A) AddilionaI
coIumns are added for each combinalionaI oulul funclion (if any). The
finaI coIumns Iisl lhe nexl slale each fIi-fIo viII allain on lhe nexl cIock
uIse. Nole lhese Iasl coIumns are oulul vaIues lhal don'l yel exisl so il
is vrong lo caII lhe labIe a "lrulh labIe" (as lhe lexl book does). The correcl
name is "slale labIe" or "slale lransilion labIe".
(2345436 Confirm your underslanding of sequenliaI circuils by comIeling
exercise 39 from age 129 of NuII & Lobur. IIease nole lhal,
1) Since lhis circuil does nol have a combinalionaI oulul, |usl for
raclice, inserl an oulul named Z, such lhal: Z A + A'X'
2) IroerIy IabeI lhe signaIs in your slale labIe. Use A(l+1) slyIe
nolalions lo dislinguish nexl slale vaIues from resenl slale ones.
A common sequenliaI circuil is a binary counler. Here lhe resenl slale
oululs reresenl a number lhal counls u on each cIock uIse. To buiId a
counler lhe combinalionaI Iogic nelvork is designed lo samIe lhe currenl
counl vaIue and comule vhal fIi-fIo excilalion signaIs are needed so
lhe fIi-fIos viII change lo lhe nexl counl in lhe sequence al lhe nexl
cIock uIse.
TyicaI exlernaI inuls for a counler mighl be ones lhal change lhe
excilalion funclions so lhe counler counls dovnvards, or erhas
"freezes" lhe counling aclion even lhough lhe cIock uIse conlinues. A
lyicaI combinalionaI oulul mighl signaI vhen lhe counler reaches a
cerlain uer Iimil. There are many design ossibiIilies. Counlers of
various sorls are common Iogic buiIding bIocks.
State Machines
In lhis imorlanl cIass of circuil, lhe resenl slale oululs are significanl
onIy in lhal lhey reresenl "some circuil slale" and lheir vaIues rovide a
vay of decoding vhen lhe circuil is, or is nol, in a arlicuIar slale. Of
more imorlance are lhe combinalionaI oululs lhal are generaled as lhe
circuil is cIocked lhrough ils various slales in resonse lo lhe aIied
inul sequence. These machines can make simIe decisions by choosing
lo make a lransilion lo one slale ralher lhan anolher. WhiIsl in a arlicuIar
slale lheir combinalionaI oululs can be used lo aclivale a arlicuIar
rocess in some exlernaI equimenl or anolher Iogic circuil.
Study Guide 3: Overview Boolean Algebra and Digital Logic
,8
The diagram on lhe righl is a
slale diagram of a slale
machine vilh lhree fIi-fIos.
The circIes reresenl lhe eighl
ossibIe slales. Iach slale is
given a name lhal reresenls ils
urose. The fIi-fIo bil
combinalion reresenling each
slale is nol given, and is nol of
rimary imorlance. The Iines
and arcs shov ermilled
lransilions belveen slales
deending on an inul vaIue.
The slale diagram shovs
asecls of an aIgorilhm, a
sequence of sles, a choice of
lvo aIlernalive sequences,
Ioos lhal reeal unliI a
condilion salisfied, elc.
Slale machines can execule many simIe rocessing aIgorilhms and can
do so al a very high seed comared lo a soflvare aIgorilhm. This is
because lhe decisions and sles are buiIl inlo a circuil's design and so do
nol have lo be "Iooked u" in memory as a comuler vouId have lo do.
ComIex slale machines are used lo conlroI lhe inlernaI oeralions of a
CIU so lhal il is abIe lo felch and execule each of ils ovn machine
inslruclions. A lyicaI CIU machine inslruclion may invoIve severaI
inlernaI bus lransfers, ossibIy a memory access, and erhas an ALU
oeralion.
These aclivilies can be broken dovn inlo sequences of 3&*"''2,"#!&'$%
such as a singIe bus lransfer of a vaIue belveen lvo CIU regislers. Iach
of lhe lhousands of ossibIe microoeralions lhal a CIU's hardvare is
caabIe of doing can be aclivaled by one slale of ils conlroI unil. This unil
is a Iarge slale machine abIe lo generale erhas a hundred or more
differenl microoeralion sequences lo cover lhe fuII sel of inslruclions lhe
CIU can erform. The combinalionaI Iogic seclion of such a slale machine
has lhousands of gales and is difficuIl lo design. This vay of buiIding a
CIU conlroI unil is knovn as .#"04>&",0 *'$!"'( (')&*.
Anolher aroach lo lhis comIex design robIem imIemenls lhe
combinalionaI Iogic nelvork of lhe slale machine by simIy using a ROM
FIT1001 Computer Systems
,#
lo memorise aII lhe lhousands of rovs of informalion in lhe slale labIe. A
ROM used in lhis vay is caIIed a *'$!"'( %!'", ;79. This is buiIl righl
inlo lhe CIU conlroI unil and musl nol be confused vilh lhe exlernaI
syslem ROM used lo hoId a comuler's slarl-u inslruclions. The conlroI
slore ROM hoIds lhe binary vaIues of aII lhe conlroI signaIs needed lo
oerale lhe CIU hardvare. The number of signaIs lhe ROM musl
remember may run from a fev dozen lo a hundred or more deending on
lhe CIU design. A conlroI slore ROM is made for very vide binary
vords.
A slale machine imIemenled in lhis vay uses lhe combinalion of exlernaI
inuls and slale feedback signaIs lo address one Iocalion in lhe conlroI
slore ROM. This causes lhe ROM lo oulul aII lhe conlroI signaI bils for
one microoeralion, as veII as lhe nexl slale excilalion signaIs for lhe fIi-
fIos. When lhe circuil is cIocked, lhe combinalion of exlernaI inuls and
fIi-fIo vaIues viII address a nev conlroI slore Iocalion lhal hoIds
informalion for lhe nexl microoeralion.
This melhod of CIU conlroI is caIIed 3&*"'*'0,0 or 3&*"'2"')"#33,0
conlroI. The binary vords in lhe conlroI slore ROM are oflen lermed
3&*"'&$%!"-*!&'$%. The melhod bolh simIifies lhe design of lhe slale
machine and makes il easier lo ugrade a design lo suorl nev CIU
inslruclions. Hovever, as vilh any syslem lhal invoIves accessing a
memory unil, lhere is a lime enaIly. Il lakes more lime lo oblain lhe nexl
sel of conlroI signaI vaIues lhan if lhey vere comuled direclIy by Iogic
gales as in lhe hard-vired melhod. A microrogrammed conlroI unil
cannol be cIocked as fasl as a hard-vired design so CIU erformance
suffers.
(2345436 Access lhe 93:06 <:40. ! seclion of lhe unil vebsile and use
lhe Iogic simuIalor lo sludy lhe slale machine circuils as
delaiIed in lhe documenl "Logic SimuIalion Ixercises 4".
Web Access
?.@ (22.AA Access 93:06 <:40. ! seclion of lhe unil vebsile and
comIele Iab / luloriaI exercises.
Study
Guide
4
CPU Internal Bus
Organisation
LEARNING OBJECTIVES
Al lhe comIelion of lhis sludy guide you viII be abIe lo:
idenlify lhal regislers, ALU, conlroI unil and buses are
comonenls of a simIe cenlraI rocessing unil,
describe hov lhe comonenls are |oined by buses lo form a
dalaalh,
undersland lhal cIock uIses are used lo reguIale lhe
oeralionaI liming of buses and lhe comonenls in lhe
dalaalh,
describe lhe felchdecodeexecule cycIe and exIain hov lhis is
used lo erform inslruclions in a simIe digilaI comuler
rogram, and
demonslrale lhe oeralion of a simIe comuler using a
simuIalor.
FIT1001 Computer Systems
74
Contents
4.1 CIU Organisalion
4.2 A comuler SimuIalor: MARII
4.3 Ielch-Decode-Ixecule cycIe
4.4 A SimIe Irogram
4.5 Inside lhe CIU ConlroI Unil
Reading
Prescribed readings
NuII and Lobur, !""#$%&'(" *+ ,*-./%#0 102'$&3'%&*$ 4 5067&%#6%/0#8
Chaler 4: MARII: An Inlroduclion lo a SimIe Comuler
Study Guide 4: CPU Internal Bus Organisation
75
4.1 CPU Organisation
In lhis sludy guide, you viII exIore lhe conslruclion of a simIe CenlraI
Irocessing Unil. In an inlroduclory course Iike lhis, il is nol ossibIe lo
resenl aII you need lo knov in order lo conslrucl a CIU simiIar lo vhal
can be urchased loday, bul vilh lhese basic concels you shouId be abIe
lo undersland lhe vorkings of a modern rocessor.
IarIier sludy guides discussed lhal a lyicaI comuler consisls of a CIU,
Memory slorage and Inul/Oulul devices. The CenlraI Irocessing Unil is
resonsibIe for felching inslruclions and dala from memory, decoding lhe
delaiIs of each inslruclion and lhen carrying oul lhe inslruclion using lhe
correcl dala. The CIU consisls of a 9'%'.'%7 and a 6*$%0*( /$&%.
The dalaalh is a nelvork of regislers and dala maniuIalion devices
connecled by various buses. The regislers slore inslruclions, dala
oerands, and machine slalus informalion used during lhe CIU
oeralions. The dala maniuIalion devices are used lo erform arilhmelic
and Iogic oeralions and are caIIed Arilhmelic Logic Unils (ALUs). A
simIe ALU is abIe lo raidIy erform arilhmelic oeralion such as add,
sublracl, comIemenl and bil-shifl (Iefl or righl). Using combinalions of
lhese simIe oeralions il is ossibIe lo erform aII olher lyes of
arilhmelic (eg muIliIy and divide) bul mosl reaI comulers have ALUs
vhich can aIso muIliIy and divide, and vhich can handIe fixed-Ienglh
signed inleger, characler (CD) and fIoaling-oinl numbers.
The conlroI unil manages lhe liming and sequencing of aII oeralions
vilhin lhe CIU. Il generales lhe Iogic slales lhal enabIe lhe arls of lhe
dalaalh al lhe righl limes so lhal syslem cIock uIses synchronise lhe
correcl dala lransfers via buses belveen lhe various comonenls of lhe
CIU. The resuIl is lhal lhe CIU oerales in a conlinuous and reealing
cycIe of inslruclion execulion.
The overaII erformance of lhe machine is direclIy affecled by lhe design
of lhe dalaalh and lhe conlroI unil.
In revious sludy guides lhe comuler bus has been menlioned. uses
consisl of muIliIe Iines or circuils lhal convey signaIs reresenling Iogic
slales. uses make il ossibIe lo connecl lvo or more devices or
subsyslems of digilaI Iogic logelher, bul al any lime lhere can be onIy one
device vhich rovides lhe Iogic signaIs. If lvo or more devices lry lo
rovide lhe source signaI lhey viII inlerfere and lhe resuIl viII be
uncerlain (see race condilion). One soIulion for lhis is lo conslrucl lhe
devices so lhal one device is a :/" -'"%#0 devices vhich may iniliale
lransfers of dala across a bus, vhiIe lhe olhers devices connecled lo lhe
FIT1001 Computer Systems
76
bus are "(';# devices vhich assiveIy resond lo requesls issued by lhe
masler. AIso lhe devices musl share a common sel of ruIe lhal are used
govern hov dala is lransferred belveen devices lhal share lhe bus.
uses may be eilher "<$670*$*/" or '"<$670*$*/". Devices allached lo
synchronous buses musl aII oerale al exaclIy lhe same seed as lhey aII
share a common bus cIock lo vhich lhey are synchronised. Asynchronous
buses aIIov inlerconneclion of devices lhal may oerale al differenl
seeds, and synchronise lheir oeralion lhrough lhe use of Iogic slales
rovided on conlroI Iines, vhich for arl of lhe bus. ='$9"7'>&$2 .0*%*6*("
are lhen used lo coordinale bus aclivily and conlroI limings.
If lhere is more lhan one masler device, lhen lhere aIso needs lo be some
kind of arbilralion lhal fairIy aIIocales conlroI of lhe bus belveen lhe
comeling masler devices.
Modern comuler syslems oflen use buses for many differenl funclions.
These incIude:
The dalaalh inlerconneclions vilhin lhe CIU
Irocessor-Memory buses used lo connecl lhe CIU lo rimary
memory
I/O buses vhich connecl exlernaI I/O device conlroIIers lo each
olher and lo lhe CIU and/or memory
Olher buses for seciaI uroses, such as backIane, IocaI and
eriheraI buses
us archileclures and I/O devices inlerconneclions viII be revisiled in
sludy guide 8.
Rcad NuII and Lobur, chaler 4, ages 145 153 (lo 4.1.4)
4.2 A Computer Simulator: MARIE
MARII is a comuler simuIalor rogram vhich is rovided vilh lhe lexl
book for lhis unil. AIlhough lhe comuler lhal MARII reresenls is onIy
hyolhelicaI, il has aII lhe comonenls of a reaI comuler. MARII has:
inary, 2's comIemenl oeralions
A slored rogram vilh fixed-Ienglh 16-bil vords
4K vords of main memory
Study Guide 4: CPU Internal Bus Organisation
77
16-bil (1 vord) inslruclions vilh 4-bil ocode and 12-bil oerand
An ALU lhal conlains an AccumuIalor and resuIl Slalus regisler
Inslruclion Regisler and Irogram Counler (or Inslruclion Ioinler)
Memory address and memory buffer regislers
Inul and oulul regislers
MARII is has a very simIe archileclure vilh regislers lhal hoId dala used
for secific uroses during ils oeralion. Iigure 4.2.1 shovs lhe
regislers, ALU and conlroI unil rovided by MARII.
Fig 4.2.1 MARIE's Architccturc (Figurc 4.8 - Nu!! and Lnbur, pagc 158)
The comonenls of lhe MARII
syslem are inlerconnecled by a
singIe 16-bil syslem bus, and mosl
regislers can deIiver a vaIue lo or
from lhis bus. The AccumuIalor is
ralher seciaI in lhal il can deIiver
resuIls lo or from lhe ALU or lhe
Memory uffer Regisler (MR)
direclIy, lhis aIIovs some
overIaing dala lransfers and
MARII a IillIe fasler.
Memory is Iocaled oulside lhe CIU,
on a searale bus vilh ils ovn cIock
Fig 4.2.2 MARIE's Data Path (Figurc
4.9 - Nu!! and Lnbur, pagc 160)
FIT1001 Computer Systems
78
lhal runs al a differenl seed. The Memory Address Regisler (MAR) and
MR form an inlerface vilh lhe main memory. The MAR is effecliveIy
connecled lo lhe address Iines on lhe rocessor-memory bus and so lhe
conlenls of lhe MAR delermines vhich memory Iocalion is used. The
MR is connecled lo lhe dala Iines on lhe memory bus and deIivers ils
conlenls lo memory during a vrile cycIe, or receives a vaIue from memory
during a read cycIe.
MARII can execule a
smaII sel of inslruclions.
Since lhe inslruclion
formal is fixed and lhe
ocode is onIy 4-bils
Iong, lhere can onIy be a
maximum of 16 ocode
vaIues (0-15)
reresenling 16
differenl inslruclions.
Load and Slore
inslruclions are used lo
lransfer 16-bil dala
ilems belveen lhe
memory Iocalion vhose
address is in lhe
oerand and lhe
accumuIalor. SimiIarIy
Add and Sublracl
inslruclions add or
sublracl lhe number in
lhe memory Iocalion
vhose address is given
as lhe oerand lo lhe
number currenlIy in lhe
accumuIalor and Ieave a
resuIl in lhe
accumuIalor.
I/O inslruclions
incIuded vilh MARII
Fig 4.2.3 MARIE 5uppnrtcd Instructinns
Opcndc Instructinn Rcgistcr TransIcr Nntatinn
0000 }nS ? MR IC
MAR ?
M|MARj MR
MR ?
AC 1
AC AC + MR
IC AC
0001 Load ? MAR ?
MR M|MARj, AC MR
0010 Slore ? MAR ?, MR AC
M|MARj MR
0011 Add ? MAR ?
MR M|MARj
AC AC + MR
0100 Subl ? MAR ?
MR M|MARj
AC AC - MR
0101 Inul AC InRIG
0110 Oulul OulRIG AC
0111 HaIl
1000 Skicond If IR|11-10j 00 lhen
If AC < 0 lhen IC IC + 1
IIse If IR|11-10j 01 lhen
If AC 0 lhen IC IC + 1
IIse If IR|11-10j 10 lhen
If AC > 0 lhen IC IC + 1
1001 }um ? IC IR|11-0j
1010 CIear AC 0
1011 AddI ? MAR ?
MR M|MARj
MAR MR
MR M|MARj
AC AC + MR
1100 }umI ? MAR ?
MR M|MARj
IC MR
Study Guide 4: CPU Internal Bus Organisation
79
assume lhal dala is handIed as 16-bil binary numbers. In reaIily, lhis is
rareIy lrue, because mosl I/O devices accel and deIiver dala as ASCII
characlers.
The Skicond inslruclion may be used vilh a foIIoving }um inslruclion
lo creale condilionaI changes in execulion sequence lhal may be used lo
erform Ioos of inslruclions, vhere lhe Ioo conlinues unliI some
condilion is lrue (or vhiIe some condilion is nol faIse!). The condilion is
vhelher lhe accumuIalor conlains a arlicuIar vaIue, vhich ilseIf is lhe
resuIl of a revious Ioad or arilhmelic inslruclions.
The labIe above shovs lhe comIele inslruclion sel for MARII. The righl-
hand coIumn reresenls lhe sequence of dala lransfer aclions required lo
imIemenl lhe inslruclion. This formal is knovn as @#2&"%#0 A0'$"+#0
B*%'%&*$. The arrov shovs lhe direclion of dala movemenl. ! is lhe
vaIue of lhe oerand in lhe inslruclion. M|!{ is lhe vaIue in lhe memory
Iocalion vhose address is given by lhe inslruclion oerand. Nole lhal in
some cases, lhe dalaalh of lhe machine aIIov more lhan one aclion lo
occur simuIlaneousIy, and lhis is shovn as lvo or more aclions on lhe
same Iine.
Rcad NuII and Lobur, chaler 4, ages 157 (from 4.2) 166 (lo 4.3)
4.3 Fetch-Decode-Execute Cycle
A simIe comuler execules inslruclions
using a reealing sequence of regisler
lransfer oeralions. The cycIe consisls of
lhree slages and is based on lhe idea lhal a
rogram ilseIf is |usl a sequence of binary
inslruclion dala lhal can be slored in
memory i.e. lhe "%*0#9 .0*20'- 6*$6#.%. The
memory makes no dislinclion belveen
inslruclions and numeric dala vaIues ils aII
|usl bils!
The firsl slage is vhere lhe comuler felches
lhe nexl rogram inslruclion from memory.
Fig 4.3.1 Fctch-Dccndc-Exccutc Cyc!c
(Figurc 4.11 - Nu!! and Lnbur, pagc 167)
FIT1001 Computer Systems
80
This requires lhal lhe address of lhe nexl inslruclion be slored somevhere,
and lhe Irogram Counler regisler (somelimes aIso knovn as lhe
Inslruclion Ioinler regisler) is used lo do lhis. Once felched, lhe binary
inslruclion needs lo be anaIysed. This is lhe decode slage, and requires
lhal lhe inslruclion be housed in lhe Inslruclion regisler, vhere ils bil
allerns can be cIoseIy examined by seciaIised Iogic in lhe conlroI unil.
The allern found in lhe firsl 4 (Ieflmosl) bils of lhe inslruclion regisler
viII resuIl in lhe dalaalh being aclivaled so lhal lhe Ixeculion slage,
vhich occurs nexl, acluaIIy lransfers dala in a vay lhal resuIls in lhe
required oeralion being erformed. Once lhe execulion slage is
comIeled, lhe cycIe slarls aII over again vilh anolher Ielch slage.
Nolice lhal lhe vaIue in lhe IC regisler delermines vhere lhe nexl
inslruclion is felched from.. NormaIIy lhe IC is simIy incremenled
during each cycIe, so inslruclions slored in neighbouring Iocalions are
execuled in address sequence. ul lhis sequence may be changed by lhe
execulion of an inslruclion, if lhe resuIl of lhal inslruclion slores a nev
vaIue in lhe IC regisler (eg. Skicond, }um or }nS).
AIso, nole lhal lhe execulion of an inslruclion may ilseIf require lhal a
dala ilem be felched or slored. This means lhal anolher memory cycIe
musl be erformed.
In Ialer sludy guides ve viII focus on Inlerruls. An inlerrul is lhe resuIl
of some exlernaI condilion or evenl lhal musl be rocessed by
inlerruling lhe normaI Ielch-Decode-Ixecule cycIe. The simIesl vay lo
do lhis is lo modify lhe cycIe so lhal lhe comuler checks lo see if lhere
has been a requesl for an inlerrul before reealing lhe cycIe again.
Rcad NuII and Lobur, chaler 4, age 166 (from 4.3) 166 (lo 4.3.2)
4.4 A Simple Program
Here is a smaII MARII rogram lhal viII gel lvo numbers from memory,
add lhem logelher and slore lhe resuIl back inlo memory.
Hcx
Addrcss
Instructinn Binary Cnntcnts nI
Mcmnry
Hcx
Cnntcnts nI
Mcmnry
100 Load 104 0001 0001 0000 0100 1104
101 Add 105 0011 0001 0000 0101 3105
102 Slore 106 0010 0001 0000 0110 2106
Study Guide 4: CPU Internal Bus Organisation
81
103 HaIl 0111 0000 0000 0000 7000
104 0023 0000 0000 0010 0011 0023
105 III9 1111 1111 1110 1001 III9
106 0000 0000 0000 0000 0000 0000
This rogram Ioads lhe hexadecimaI vaIue 0023 (decimaI 35) from Iocalion
10416 inlo lhe accumuIalor using a Lnad inslruclion. The Add inslruclion
lhen felches lhe hex vaIue III9 (vhich is 2's comIemenl binary for -23
decimaI) from Iocalion 10516 and adds lhis lo lhe vaIue in lhe accumuIalor,
Ieaving lhe resuIl in lhe accumuIalor. Al lhis oinl, lhe accumuIalor
conlains hex 000C ie. 35 + (-23) 12 decimaI. The nexl inslruclion (5tnrc)
lransfers lhe conlenls of lhe accumuIalor lo memory Iocalion 10616 and
lhal's lhe end of lhe rogram.
The diagram beIov and on lhe nexl age is from Iigure 4.13 of NuII and
Lobur, age 171, and shovs a lrace of lhe execulion of lhese lhree
inslruclions. The highIighled ceIIs under lhe regisler headings indicale
finaI vaIue in each case. You can cIearIy see lhe Ielch, Decode and Ixecule
slages in each case.
The inslruclions of a rogram musl be resenl in memory so lhal lhey can
be execuled, and as such are |usl bils slored in conseculive Iocalions.
WhiIe il is ossibIe lo vrile rograms in lhis form, il is more convenienl
lo use a lexl reresenlalion of lhe inslruclions, and lhen converl lhe lexl
formal inlo binary numbers. In facl, il is ossibIe lo vrile a rogram lo do
lhis conversion for you! Such rograms are caIIed 5""#-:(#0" and lhe lexl
lhey read is usuaIIy slored in a "*/06# fiIe and lhe machine code oulul lo
an *:C#6% fiIe or direclIy inlo memory. ReIacing inslruclion ocodes vilh
aIhanumeric names and using IabeIs inslead of machine addresses makes
machine-IeveI rogramming much easier lo undersland and Iess error
rone. AssembIers viII be discussed in more delaiI Ialer in lhe unil.
FIT1001 Computer Systems
82
Fig 4.4.1 Prngram Tracc (Figurc 4.13 - Nu!! and Lnbur, pagc 171)
The samIe MARII assembIer rogram, shovn on lhe nexl age,
iIIuslrales lhe use of a Ioo, vhere lhe conlroI variabIe is decremenled
from an iniliaI vaIue each lime around lhe Ioo. When lhe conlroI variabIe
is decremenled beIov zero (ie become negalive!) lhe Skicond inslruclion
viII exil from lhe Ioo and haIl. The summalion uses an add inslruclion
vilh an &$9&0#6% '990#"" oerand. The oerand in lhis kind of inslruclion is
lhe address of a Iocalion vhich conlains lhe address of anolher Iocalion
vhere lhe acluaI vaIue is lo be found. This kind of doubIe felch oerand
is very usefuI because il aIIovs lhe oerand address lo be lhe resuIl of an
arilhmelic oeralion. In lhis examIe, an incremenl oeralion (XX+1) is
used lo sle lhe largel of lhe add inslruclion lhrough a Iisl of vaIues,
forming lhe sum as lhe rogram successiveIy adds each subsequenl
number. Addressing modes are discussed in more delaiI Ialer in lhe unil.
Study Guide 4: CPU Internal Bus Organisation
83
/ A SamIe MARII AssembIer rogram
/ based on IxamIe 4.1 from NuII&Lobur
/ Iorm lhe sum of 5 numbers lhan slo
/ Uses indirecl addressing lo add each number in a Ioo
Org 100 /Direclive lo sel address of firsl inslruclion
Load Addr /Load address of firsl number lo be added
Slore Nexl /Slore lhis address as our Nexl oinler.
Load Num /Load lhe number of ilems lo be added
Subl One /Decremenl
Slore Clr /lhen slore lhis vaIue in Clr lo conlroI Iooing.
CIear /CIear AC.
Loo, Load Sum /Load lhe Sum inlo AC.
AddI Nexl /Add lhe vaIue oinled lo by Iocalion Nexl
Slore Sum /Slore lhis nev Sum.
Load Nexl /Load Nexl oinler
Add One /Incremenl by one - Nov oinls lo nexl number
Slore Nexl /...and save il.
Load Clr /Gel lhe Ioo conlroI variabIe
Subl One /and decremenl il
Slore Clr /lhen save nev vaIue.
Skicond 000 /If conlroI variabIe < 0 lhen ski nexl inslruclion
}um Loo /eIse go back lo slarl of Loo.... again!
HaIl /Terminale rogram
Addr, Hex 0118 /address of slarl of Iisl of numbers lo be added
Nexl, Hex 0 /oinler lo nexl number in Iisl
Num, Hex 5 /Ienglh of Lisl of numbers lo be added
Sum, Dec 0 /The sum of numbers in lhe Iisl
Clr, Hex 0 /The Ioo conlroI variabIe - counls dovn lo zero
One, Dec 1 /a conslanl used for incremenling and decremenling
Lisl, Dec 10 /The Iisl of vaIues lo be added logelher
Dec 15
Dec 20
Dec 25
Dec 30
Ind /Direclive for Ind of rogram code
Rcad NuII and Lobur, chaler 4, age 169 (from 4.4) 179 (lo 4.7)
4.5 Inside the CPU Control Unit
The comonenls of a CIU have been described in some delaiI bul lhe
delaiIs of hov lhe ocode is decoded and used lo generale conlroI signaIs
has nol been examined in delaiI. In lhe revious sludy guide il vas
menlioned lhal combinaloriaI and sequenliaI Iogic circuils can be used lo
buiId slale machines, and lhal slale machines can be used lo a conslrucl
7'09DE&0#9 CIU ConlroI Unil. Such as device vouId lake inuls from lhe
FIT1001 Computer Systems
84
Ocode bils of lhe inslruclion regisler, slalus bils from lhe ALU as veII as
bus and cIock signaIs, and use lhese lo delermine an iniliaI slale and
resuIling conlroI signaIs as lhe slale machine rogresses. Iigure 14.4 from
NuII and Lobur shovs such a hard-vired conlroI unil.
Fig 4.5.1 (Figurc 4.14 - Nu!! and Lnbur, pagc 180)
Anolher aroach is lhe -&60*.0*20'--#9 conlroI unil as shovn in Iigure
4.15 from NuII and Lobur overage. This is nol unIike having a comuler
vilh a seciaI rogram of il ovn, inside lhe CIU conlroI unil, aIlhough
lhe archileclure of lhe microconlroIIer is quile differenl lo lhe comuler
described earIier. The rogram execuled by lhe microconlroIIer is
rimariIy designed lo decode lhe macrocomuler inslruclion and lhen
felch a very shorl sequence of microinslruclions. The microinslruclions
have many seciaIised oerand fieIds lhal direclIy generale lhe conlroI
signaIs used lo govern lhe dalaalh of lhe macromachine, and so are
usuaIIy much Ionger lhan macromachine inslruclions.
Study Guide 4: CPU Internal Bus Organisation
85
Fig 4.5.2 (Figurc 4.15 - Nu!! and Lnbur, pagc 181)
WhiIe lhe seed of hard-vired conlroI unils is Iimiled onIy by lhe
lechnoIogy used lo imIemenl lhe Iogic gales used lo conslrucl il, lhe
comIexily of such circuils lends lo make lhem difficuIl lo design and
modify. Irocessors lend lo be designed as members of a famiIy, and lhere
are oflen requiremenls lhal Ialer members of lhe famiIy be comalibIe
vilh earIier members, and lhis is difficuIl vhen lhe conlroI unil is hard-
vired lo lhe dalaalh and inslruclion sel. Hovever, vilh a
microrogrammed conlroI unil il is easy lo add nev inslruclions lo an
aIready comIicaled inslruclion sel, bul lhe cosl of lhis fIexibiIily is
reduced seed.
The differenl kinds of CIU conlroI unils viII aIso occur in sludy guide 6.
Rcad NuII and Lobur, chaler 4, age 179 (from 4.7) 182 (lo 4.8)
FIT1001 Computer Systems
86
Web Access
Wcb Acccss Access 5tudy Guidc 4 seclion of lhe unil vebsile and
comIele Iab / luloriaI exercises.
Study
Guide
!
Introduction to
Instruction Set
Architectures
LEARNING OBJECTIVES
Al lhe comIelion of lhis sludy guide you viII be abIe lo:
define inslruclion lyes and formals,
idenlify inslruclion oerands and lhe addressing modes used,
vrile machine and assembIer rograms for a simIe comuler
simuIalor,
exIain lhe use of basic inslruclion lyes such as arilhmelic,
Iogic, branch and subrouline caII,
idenlify lhe fealures of severaI machine inslruclion sels.
FIT1001 Computer Systems
""
Contents
5.1 Inlroduclion
5.2 Inslruclion Iormals
5.3 Inslruclion Tyes
5.4 Addressing
5.5 Inslruclion-IeveI IieIines
5.6 Overviev of Machine Inslruclion Sel Archileclures
Reading
Prescribed readings
NuII and Lobur, !""#$%&'(" *+ ,*-./%#0 102'$&3'%&*$ 4 5067&%#6%/0#8
Chaler 5: A CIoser Look al Inslruclion Sel Archileclure
Study Guide 5: Instruction Set Architectures
"#
5.1 Introduction
The revious sludy guide inlroduced lhe idea of machine Ianguage
oeralions and machine Ianguage rograms. ul vhy is il necessary lo
Iearn aboul Iov-IeveI rogram inslruclions, vhen mosl of lhe
rogramming of comulers is done in high-IeveI Ianguages such as $
%%
or
&'(' and using inleraclive deveIomenl environmenls such as )*+, or
+$-./0+` One arl of lhe ansver lo lhal queslion is lhal a delaiIed
underslanding of lhe Iov-IeveI oeralion of a comuler aIIovs
rogrammers and syslem deveIoers lo design and vrile more efficienl
and more effeclive syslems.
This sludy guide viII Iook al lhe loic of machine inslruclion sels and
exand on lhe concels of inslruclion lyes, oerand lyes and
addressing modes used lo access dala in memory. The idea lhal differenl
comulers use differenl inslruclion sels is an imorlanl arl of
underslanding comuler archileclure, so lhis sludy guide ends vilh an
overviev of some differenl lyes of inslruclion sels.
5.2 Instruction Formats
In lhe revious sludy guide, lhe MARII simuIalor vas used lo iIIuslrale
oeralion of a comuler. The machine simuIaled by MARII had a fixed
inslruclion size of 16 bils vilh onIy one oerand. A sludy of machine
archileclure shovs lhal inslruclions come in many differenl lyes vhich
have lhe foIIoving fealures:
Oerand dala can be slored in lhe CIU, lyicaIIy in a regisler or
slack slruclure
There can be a number of oerands er inslruclion, usuaIIy zero,
one, lvo and lhree oerands
Differenl combinalions of oerand Iocalions in each inslruclion,
mosl common are regisler-lo-regisler, regisler-lo-memory (and
vice-versa) and memory lo memory
Differenl lyes of oeralion, incIuding lyes lhal have oerands
lhal address memory and lhose lhal do nol
Inslruclions vilh differenl lye and size of oerand, lhal is,
oerands lhal are addresses or IileraI numbers or characlers or Iisls
Secifying lhe delaiIs of lhe inslruclion sel is a fundamenlaI slage in lhe
design of a comuler. Limiling lhe fealures (as menlioned above) of lhe
inslruclions viII have Iong lerm imIicalions for lhe use of lhe machine
FIT1001 Computer Systems
#1
and lhe sorl of lasks il can easiIy erform. The fealures of lhe inslruclions
viII delermine:
The sace required by a rogram
The comIexily of lhe conlroI unil in lhe CIU lhal is required in
order lo decode and execule lhe inslruclions
The comIexily of lhe arilhmelic Iogic unil, dala lransfer and bus
inlerface hardvare required lo mosl efficienlIy execule lhe
inslruclions
The Ienglh of lhe inslruclions
The lolaI number of inslruclions
Things lo consider in lhe secificalion of an inslruclion sel incIude:
Shorl inslruclions are beller lhan Iong ones, because lhey can be
handIed quickIy, more inslruclions er unil of dala lransfer
lo/from memory means lhal each inslruclion can be felched fasler
and is more IikeIy lo be in cache
Inslruclions vilh fixed Ienglh are easier (cheaer and fasler) lo
decode
There are many differenl vays lo refer lo oerands, knovn as
addressing modes, lhese aIIov dala lo be accessed in a variely of
convenienl vays
Memory organisalion has an effecl on lhe inslruclion formal. This
is vhy mosl modern machines have byle-addressabIe memory
oerands, even vhen lhe memory bus lransfers dala in vords of
much Iarger sizes
One imorlanl asecl of inslruclion formal is deendenl on lhe byle
slorage sequence used in lhe memory sub-syslem of lhe machine. If
severaI byles can be lransferred lo/from memory in a singIe memory
access cycIe (or vord) and lhese byles are arl of a Iarger slruclure, such
as a Iong inleger or a lexl slring, lhe Ieasl-significanl byle may be slored al
lhe Iovesl byle address or al lhe highesl. Iigure 5.1 on age 202 of NuII
and Lobur shovs lhe slorage of a 32-bil binary number in hexadecimaI
reresenlalion, vilh lvo hex digils er byle.
2.3 !)5)6 7.3 '*8 9.,,-+ :*8.'* 2;<=',0
Study Guide 5: Instruction Set Architectures
#6
A big-Indian machine is one vhere lhe mosl significanl (Iefl-hand) arl
of lhe 32-bil number is slored al lhe Iovesl byle address. The IillIe-
Indian archileclure is one vhere lhe mosl significanl arl is slored al lhe
highesl byle address. There are many advanlages and disadvanlages for
each formal and moslIy il is |usl a maller of convenlion and convenience
lhal decides vhich one lo use.
>+'8 NuII and Lobur, chaler 5, ages 201 (from 5.2.2) - 203 (lo
5.2.3)
Aarl from lhe byle ordering of dala, anolher vay lo cIassify inslruclion
sels is lo Iook al lhe vay oerand refers lo dala in lhe CIU. NuII & Lobur
idenlify lhree lyes of CIU slorage archileclure:
Slack machines
AccumuIalor based machines
GeneraI urose regisler machines
Slack machines have inslruclions vhose oerands imIicilIy refer lo
vaIues currenlIy on lo of a slack. WhiIe lhis formal is a comacl and
efficienl vay lo execule arilhmelic and can make lransIalion (see:
6*-.&('%&*$) of exressions easier in high IeveI Ianguages (see: 0#9#0"# .*(&"7
$*%'%&*$ and .*"%+&: $*%'%&*$), il reslricls lhe sequence of oerand
rocessing because dala on slacks can onIy be accessed one ilem al a lime,
from lhe lo, vhich is effecliveIy a seriaI sequence. Hardvare Iimilalions
on lhe amounl and lye of slorage vilhin lhe CIU, means lhal lhe slack is
acluaIIy Iocaled in memory anyvay. AccumuIalor machine designs have
inslruclions lhal imIicilIy refer lo a singIe cenlraI lemorary slore, bul
lhis requires Ioad and slore inslruclions lo lransfer dala from memory
lo/from lhe accumuIalor, and Ieads lo exlra memory accesses. The generaI
urose regisler formal is lhe one mosl commonIy found in modern
comulers, as lhis can minimise lhe memory lransfers required and can be
accommodaled by modern olimising comiIers (see: 6*-.&('%&*$).
The number of oerands lhal an inslruclion can have and lhe lolaI number
of inslruclions a machine has, is delermined by lhe size of lhe inslruclion.
Inslruclions are usuaIIy eilher fixed in Ienglh or may vary in Ienglh. Iixed
Ienglh inslruclions are fasler lo felch and decode, vhereas, variabIe Ienglh
inslruclions are more comIex lo decode, bul use memory sace more
efficienlIy. Mosl reaI comulers have a range of fixed Ienglh inslruclions.
Common inslruclion formals incIude:
OICODI onIy (zero addresses)
FIT1001 Computer Systems
#5
OICODI + 1 address (usuaIIy a memory reference)
OICODI + 2 addresses (usuaIIy regislers, or one regisler and a memory
reference)
OICODI + 3 addresses (usuaIIy regislers, or combinalions of regislers and
memory)
>+'8 NuII and Lobur, chaler 5, ages 204 (from 5.2.4) - 208 (lo 5.2.5)
In IxamIe 5.1 (Iage 206 of NuII & Lobur) a series of hyolhelicaI
comuler inslruclions are shovn vhere lhe same robIem is being
comuled using 3, 2, 1 and zero oerand inslruclion formals. Nole lhal
lhere is an inverse reIalionshi belveen lhe number of oerands and lhe
number of inslruclions lhal need lo be execuled lo do lhe caIcuIalion. The
rogram vrillen in 3-oerand inslruclions is shorlesl and lhe slack
inslruclion rogram (vilh zero-oerand inslruclions) is Iongesl. Hovever,
comensaling for lhis is lhe facl lhal lhe 3-oerand inslruclions robabIy
occuies aImosl as much memory sace and lakes Ionger lo execule lhan
lhe slack inslruclion rogram. Ior examIe, assuming 16-bil memory
oerands, 4-bil regisler oerands and 4-bil fixed Ienglh ocode, lhe 3-
oerand rogram occuies 13 byles of memory, vhiIe lhe slack rogram
occuies 14 byles of rogram memory.
The concIusion lo be dravn from lhis is lhal lhe ocode Ienglh and lhe
number of oerands conlroI lhe formal of comuler inslruclions. ul lhis
assumes lhal lhe ocodes and oerands are fixed in size. Some inslruclion
sels have variabIe Ienglh ocodes, vhere differenl inslruclions have
ocodes of differenl Ienglh. WhiIe lhis makes decoding lhe inslruclions
Study Guide 5: Instruction Set Architectures
#?
more comIicaled il can make more efficienl use of RAM and aIIov lhe
inslruclion sel of a nev machine lo incIude lhe inslruclions from an oIder
modeI vilh differenl archileclure. This idea has been used lo aIIov
famiIies of CIUs lo be backvard comalibIe, vhere lhe never and more
advanced modeIs can sliII execule rograms vrillen in lhe machine code
of lhe oIder modeIs.
>+'8 NuII and Lobur, chaler 5, ages 208 (from 5.2.5) - 209
5.3 Instruction Types
Comuler inslruclion sels conlain many lyes of oeralions designed lo
maniuIale a vide variely of lyes of dala using various melhods of
addressing. These lyicaIIy incIude:
Dala movemenl - used lo lransfer dala belveen regislers and
memory
Arilhmelic erform lhe slandard arilhmelic oeralions on many
lyes of dala
ooIean AND, OR, and comIemenl (NOT)
il maniuIalion - shifl and rolale
Inul/Oulul simiIar lo a dala move oeralion bul lransferring
belveen I/O and regislers or memory
Transfer of ConlroI change lhe sequence of execulion somelimes
deending on some condilion
SeciaI urose slring and array maniuIalion and olher CIU
suorl funclions
>+'8 NuII and Lobur, chaler 5, ages 210 211 (lo 5.4)
5.4 Addressing
Inslruclions idenlify lheir oerands in a number of vays lhal deend on
vhal lye of dala lhey conlain and lhe melhod of secifying lhe address.
AIlogelher, lhis is knovn as address modes. There are severaI address
modes incIuding:
FIT1001 Computer Systems
#@
Immediale vhere lhe oerand is a IileraI vaIue lhal lhe
inslruclion oerales on
Direcl vhere lhe oerand is a memory address lhal is lo be
felched
Regisler lhe oerand secifies a regisler conlaining lhe vaIue lo
be oerales on
Indirecl a highIy fIexibIe melhod vhere lhe oerand secifies lhe
address in memory vhere lhe address of lhe acluaI oerand may
be found. This requires lvo or more felch sequences, bul makes il
ossibIe lo erform address caIcuIalions searaleIy from lhe
inslruclion.
Indexed lhe address of lhe dala ilem is caIcuIaled by adding lhe
conlenls of an index regisler lo lhe oerand, lhis can aIso be used
lo do variabIe address caIcuIalions
Slack is vhere lhe oerands are assumed lo be Iocaled on a slack.
There may be more lhan one slack, in vhich case lhe oerand
idenlifies vhich slack lo use.
SeciaIised addressing modes, such as base-offsel, aulo-incremenl
and reIalive addressing.
>+'8 NuII and Lobur, chaler 5, ages 211 (from 5.4) 214 (lo 5.5)
5.5 Instruction-level Pipelines
A CIU execules inslruclions using lhe Ielch-Decode-Ixecule cycIe
described reviousIy. Some CIUs have been designed so lhal lhe circuilry
lhal erforms each slage can oerale in araIIeI, so lhal severaI sequenliaI
inslruclions are being execuled al lhe same lime, bul al differenl slages.
This is caIIed a ieIine and in ideaI condilions such designs can seed
u lhe execulion of inslruclions by a faclor equaI lo lhe number of slages
in lhe ieIine. Iigure 5.4 on age 216 of NuII & Lobur shovs 4
inslruclions going lhrough a 6-slage ieIine, and afler 6 cIock cycIes lhe
comuler begins sloring lhe resuIls of successive inslruclions during each
cycIe, vhich is 6 limes fasler lhal a design vilhoul a ieIine.
Hovever, lhis ideaI silualion is nol aIvays achieved, as changes in lhe
sequence of execulion lhal somelime occur vilh branch or subrouline caII
inslruclions Iead lo a silualion vhere lhe inslruclions lhe foIIov in lhe
ieIine are nol lhe righl ones and have lo be discarded so lhal lhe nev
sequence of inslruclions may be cIocked inlo lhe ieIine in lheir Iace.
AIso, robIems such as concurrenl use of memory buses by differenl
Study Guide 5: Instruction Set Architectures
#!
slages or use of common dala by sequenliaI inslruclions can revenl
ieIines from achieving lheir ideaI seed.
>+'8 NuII and Lobur, chaler 5, ages 214 (from 5.5) 219 (lo 5.6)
5.6 Overview of Machine Instruction Set
Architecture
In summary, il is ossibIe lo comare CIU inslruclion sels by Iooking al:
Inslruclion formals
Inslruclion lyes
Number of oerands
Addressing modes
IieIining
In lhe reading beIov, lhese characlerislics are comared for lvo
hisloricaIIy imorlanl CIU famiIies by InleI and MIIS as veII as lhe }ava
virluaI machine archileclure.
>+'8 NuII and Lobur, chaler 5, ages 219 (from 5.6) 225.
Web Access
A+B C$$+00 Access D,E8F GE.8+ ! seclion of lhe unil vebsile and
comIele Iab / luloriaI exercises.
FIT1001 Computer Systems
#H
Study
Guide
!
Computer Program
Execution Concepts
LEARNING OBJECTIVES
Al lhe comIelion of lhis sludy guide you viII be abIe lo:
undersland lhe concels of rogram execulion and conlroI
lhe fIov of a rogram,
undersland lhe basic concels of lhe slack as dala slorage
slruclures in rogramming,
undersland lhe basic concels of bolh hardvare and soflvare
inlerruls,
describe hov inlerruls aIler lhe normaI fIov of rogram
execulion in a comuler syslem,
define inlerrul veclors and deveIo inlerrul handIers, and
comare lhe characlerislics of RISC machines versus CISC
machines,
FIT1001 Computer Systems
"#
Contents
6.1 Irogram Ixeculion Concels
6.2 Irogram ConlroI Inslruclions
6.3 Slacks
6.4 Inlerruls
6.5 Case Sludies of ReaI Archileclures
Reading
Prescribed readings
NuII and Lobur, !""#$%&'(" *+ ,*-./%#0 102'$&3'%&*$ 4 5067&%#6%/0#8
Chaler 4: MARII: An Inlroduclion lo a SamIe Comuler
Chaler 9: AIlernalive Archileclures
Reader: SlaIIings, ,*-./%#0 102'$&3'%&*$ 4 5067&%#6%/0#8 9#"&2$&$2 +*0
:#0+*0-'$6#:
Chaler 10: Inslruclion Sels: Characlerislics and Iunclions,
354-359 / 377-381
Reader: IngIander, ;7# 5067&%#6%/0#8*+ ,*-./%#0 <'0=>'0# '$= ?@"%#-"
?*+%>'0#:
Chaler 9: Inul/Oulul, 238-251
Study Guide 6: Computer Program Execution Concepts
""
6.1 Program Execution Concepts
We have sludied in Sludy Guide 4 lhal aII comulers foIIov a basic
machine cycIe: lhe felch-decode-execule cycIe.
$%&'%( NuII and Lobur, chaler 4, age 166 (4.3.1 onIy)
6.2 Program Control Instructions
Irogram conlroI inslruclions conlroI lhe fIov of a rogram. We have
sludied in lhe revious sludy guide lhal %0'$"+#0 *+ 6*$%0*( inslruclion
lyes change lhe sequence of rogram execulion. Mosl common lransfer-
of-conlroI oeralions found in inslruclion sels are A0'$67 and .0*6#=/0#
6'((.
Branch Instructions
A branch inslruclion, aIso caIIed a B/-. inslruclion, has one of ils
oerands lhe address of lhe nexl inslruclion lo be execuled. Mosl oflen,
lhe inslruclion is a )*+,'-'*+./ 12.+)3 inslruclion. Thal is, lhe branch is
made (udale rogram counler lo equaI address secified in oerand)
onIy if a cerlain condilion is mel. Olhervise lhe nexl inslruclion in
sequence is execuled (incremenl lhe rogram counler as usuaI). A branch
inslruclion in vhich lhe branch is aIvays laken is an 4+)*+,'-'*+./
12.+)35
Mosl machines rovide a muIliIe bil condilion code lhal is sel as lhe
resuIl of some oeralions. As an examIe, an arilhmelic oeralion couId
sel a 2-bil condilion code vilh one of lhe four vaIues: 0, osilive, negalive,
overfIov. On such a machine, lhere are 4 differenl branch inslruclions:
RI X ranch lo Iocalion X if resuIl is osilive.
RN X ranch lo Iocalion X if resuIl is negalive.
RZ X ranch lo Iocalion X if resuIl is zero.
RO X ranch lo Iocalion X if overfIov occurs.
In aII lhese cases, lhe resuIl referred lo is lhe resuIl of lhe mosl recenl
oeralion lhal sel lhe condilion code.
Anolher aroach is deicled by lhe foIIoving examIe:
FIT1001 Computer Systems
677
RI R1, R2, X ranch lo X if conlenls of R1 conlenls of
R2.
Iigure 6.2.1 shovs examIes of lhese branch oeralions.
8'942% !5:56 ;2.+)3 <+=-24)-'*+=
Procedure Call Instructions
A !"#$%&'"% ) *'+"#',-.% is a seIf-conlained rogram lhal is incororaled
inlo a Iarger rogram. Al any oinl in lhe rogram lhe rocedure maybe
invoked or $/00%&. The rocessor is inslrucled lo go and execule lhe enlire
rocedure and lhen relurn lo lhe oinl from vhich lhe caII look Iace.
A rocedure aIIovs lhe same iece of code lo be used many limes,
resuIling in efficienl use of slorage sace in lhe syslem. Large
rogramming lasks can be subdivided inlo smaIIer moduIar unils, easing
lhe rogramming lask.
The rocedure mechanism invoIves lvo basic inslruclions:
A ).// inslruclion lhal branches from lhe resenl Iocalion lo lhe
rocedure
A 2%-42+ inslruclion lhal relurns from lhe rocedure lo lhe Iace
from vhich il vas caIIed.
Imorlanl oinls aboul a rocedure lo nole are:
Study Guide 6: Computer Program Execution Concepts
676
1. A rocedure can be caIIed from more lhan one Iocalion.
2. A rocedure can aear in a rocedure, Ieading lo $#"%&$2
of rocedures lo an arbilrary delh.
3. Iach rocedure caII is malched by a relurn in lhe in lhe
subrouline.
Iigure 6.2.2 (a) iIIuslrales lhe use of rocedures lo conslrucl a rogram.
Iigure 6.2.2 (b) deicls lhe execulion sequence.
8'942% !5:5: >%=-%, ?2*)%,42%=
The rocessor needs lo save lhe relurn address so lhal lhe relurn from lhe
subrouline can lake Iace arorialeIy. Differenl comulers use differenl
melhods lo save lhe relurn address. One common melhod is lo slore lhe
relurn address on a memory slack, lhe 2%-42+ inslruclion oerales by
removing lhe address from lhe slack and moving il lo lhe rogram
counler.
8'942% !5:5@ A=% *B C-.)D -* <EF/%E%+- >%=-%, C412*4-'+%= *B 8'942%
!5:5:
FIT1001 Computer Systems
67:
In addilion, il is oflen necessary lo !/** !/"/1%,%"* vilh a rocedure caII.
Hence, vhen lhe rocessor execules a caII, il slacks lhe relurn address and
lhe aramelers lo be assed lo lhe caIIed rocedure.
$%., Reader SlaIIings, Chaler 10, ages 354-359
6.3 Stacks
A "%'6C is an ordered sel of eIemenls, onIy one al lhe %*. can be accessed al
a lime. The number of eIemenls (vhich is variabIe) in lhe slack is lhe
(#$2%7 and lhe Iasl eIemenl is lhe A'"# of lhe slack. Ilems may be added lo
or deIeled from lhe lo of lhe slack. Hence a slack is knovn as a ./"7=*>$
(&"% or a ('"%D&$D+&0"%D*/% EFGH1I (&"%J
A F4=3 inslruclion aends one nev ilem lo lhe lo of lhe slack, vhiIe a
F*F inslruclion removes lhe lo ilem from lhe slack. inary oeralions,
vhich require lvo oerands (e.g. muIliIy, divide, add, sublracl), use lhe
lo lvo ilems of lhe slack as oerands.
A conliguous bIock of Iocalions is reserved in main memory (or virluaI
memory) for lhe slack. Il is arliaIIy fiIIed vilh slack eIemenls and lhe
remainder is avaiIabIe for slack grovlh. Three addresses are needed for
roer oeralion, and lhese are slored in rocessor regislers:
C-.)D F*'+-%2 conlains lhe address of lhe lo of lhe slack.
C-.)D 1.=% conlains lhe address of lhe bollom Iocalion in lhe
reserved bIock.
C-.)D /'E'- conlains lhe address of lhe olher end of lhe reserved
bIock.
$%., Reader SlaIIings, Chaler 10, ages 377-381
6.4 Interrupts
Inlerruls are signaIs lhal cause lhe comuler's CIU lo susend vhal il is
doing and lransfer lo a seciaI rogram caIIed an &$%#00/.% 7'$=(#0 or
&$%#00/.% "#0K&6# 0*/%&$#. The lransfer is forced by seciaI hardvare
Study Guide 6: Computer Program Execution Concepts
67@
mechanisms lhal are engineered for maximum seed. The inlerrul
handIer is resonsibIe for delermining lhe cause of lhe inlerrul, laking
lhe aroriale aclion, and lhen relurning conlroI lo lhe originaI rocess
lhal vas susended.
Inlerruls are lyicaIIy caused by evenls exlernaI lo lhe CIU and require
immediale allenlion, such as:
ComIelion of an I/O rocess
Deleclion of a hardvare faiIure
Irror handIing
Calaslrohes over faiIure, elc.
The melhod mosl comulers use lo rocess an inlerrul is lo check lo see
if an inlerrul is ending al lhe beginning of each felch-decode-execule
cycIe. If so, lhe inlerrul is rocessed, afler vhich lhe machine execulion
cycIe conlinues. If no inlerrul is resenl, rocessing conlinues as normaI.
The alh of execulion is shovn in Iigure 6.4.1.
8'942% !5G56 H*,'B'%, <+=-24)-'*+ IJ)/% -* I3%)D B*2 <+-%224F-
FIT1001 Computer Systems
67G
To service inlerruls efficienlIy, modern CIUs suorl muIliIe inlerrul
lyes or IeveIs. Ior each lye, lhere is a reserved Iocalion in memory,
caIIed an &$%#00/.% K#6%*0 lhal secifies vhere lhe inlerrul handIer
rogram for lhal inlerrul lye is Iocaled. (Here, K#6%*0 is an unnecessariIy
lechnicaI lerm meaning air of numbers.) This seeds inlerrul
rocessing, since conlroI is lransferred direclIy lo lhe aroriale rouline,
no lime is vasled by a cenlraI rouline lhal has lo delermine lhe cause of
lhe inlerrul. The concel of inlerrul lyes aIso aIIovs inlerruls lo be
riorilised, so lhal if severaI inlerruls occur simuIlaneousIy, lhe mosl
imorlanl one can be rocessed firsl.
CIUs lhal suorl inlerruls musl aIso be abIe lo bIock inlerruls vhiIsl
execuling crilicaI seclions of code. Somelimes lhe inlerrul IeveIs can be
bIocked seIecliveIy, bul more oflen lhe effecl is gIobaI. WhiIe an inlerrul
is being serviced, aII inlerruls of lhe same or Iover riorily are masked
unliI lhe aclive handIer has comIeled ils execulion, and lhe execulion of
a handIer can be re-emled if anolher inlerrul vilh higher riorily
requires service. Some CIUs can dislinguish belveen seIecliveIy masking
inlerruls (recognise, bul defer handIing), and simIy disabIing lhem
(lhrov lhe inlerrul avay).
6.4.1 Interrupt Types
In generaI inlerruls can be groued inlo lhree calegories:
Irocessor Inlerruls, (aIso knovn as InlernaI Hardvare Inlerruls)
Hardvare Inlerruls, (aIso knovn as IxlernaI Hardvare
Inlerruls)
Soflvare Inlerruls
Processor Interrupts
These are generaled by lhe rocessor ilseIf, vhen cerlain evenls moslIy,
error condilions occur during rogram execulion, such as an arilhmelic
division error (lhis can be caused by an alleml lo divide by zero), slack
overfIov, or roleclion vioIalions. In lhe InleI 80x86 famiIy of rocessors,
lhese inlerrul lyes are numbered 0 lo 12H. The numbers assigned lo
such evenls are vired inlo lhe CIU and are nol modifiabIe. A lye 1
inlerrul, SingIe-Sle, occurs al lhe comIelion of each inslruclion bul
onIy if lhe %0'. +('2 TI has been sel.
Study Guide 6: Computer Program Execution Concepts
67K
Hardware Interrupts
These are requesls inilialed by exlernaI hardvare. The 80x86 rocessors
have lvo ins (exlernaI circuil conlacls) reserved for lhese inlerruls. One
is caIIed lhe Non-MaskabIe Inlerrul (NMI) in, and lhe olher is lhe
MaskabIe Inlerrul (INTR) in. The NMI Iine is usuaIIy reserved for
inlerruls caused by calaslrohic evenls such as memory arily errors or
over faiIure.
Inslead of being vired direclIy lo lhe CIU, lhe inlerruls from exlernaI
devices are usuaIIy channeIIed lhrough a device caIIed lhe InleI 8259A
IrogrammabIe Inlerrul ConlroIIer (IIC). This is conlroIIed by lhe CIU
lhrough a sel of I/O orls, and converseIy, signaIs lhe CIU via lhe INTR
in. The IIC can accommodale 8 hardvare devices. When il receives a
hardvare inul, il signaIs using INTR, vails for a CIU acknovIedgmenl,
and Iaces lhe lye number (idenlifying lhe hardvare device) on lhe dala
bus.
Software Interrupts
Soflvare inlerruls are seciaI inslruclions lhal lrigger an inlerrul
resonse from lhe rocessor, simIy by execuling an inslruclion in lhe
rogram (such as one lhal requires a rogram lo svilch from running al
one IeveI, such as user IeveI, lo anolher IeveI, such as kerneI IeveI) . Ior
examIe execuling lhe INT inslruclion for 80x86 CIU:
INT InlrNumber
Inlerruls 20H lo 3IH are used by MS-DOS lo communicale vilh ils
moduIes and aIicalion rograms, e.g., 21H suIies a Iarge range of
funclions. There are lveIve ROM IOS inlerruls (5H, and 10H lo 1AH)
lhal rovide hardvare communicalions al a Iover IeveI lhan DOS. These
inlerrul numbers are simIy convenlionaI, and are nol vired inlo lhe
hardvare in any vay.
Nole aIso lhal nol aII of lhe rocessor inlerruls are due lo an error
condilion. Inlerrul lyes 3 and 4 are soflvare inlerruls. INT 3 is a
seciaI one-byle inslruclion usefuI for debugging, because il can be
inserled easiIy inlo a rogram vhich lhen runs unliI lhe inslruclion is
encounlered. This is knovn as a breakoinl. INTO is lye 4 (lhe
inslruclion is |usl INTO, vilh no InlrNumber, O slanding for OverfIov),
vhich inlerruls a rogram vhen an overfIov condilion occurs.
FIT1001 Computer Systems
67!
6.4.2 Interrupt Processing
The occurrence of an inlerrul lriggers a number of evenls, bolh in lhe
rocessor hardvare and in soflvare. To handIe an inlerrul, a rocessor
lakes lhe foIIoving sles:
Save lhe currenl execulion slale
Delermine vhich device inlerruled
CaII lhe rocedure lhal handIes lhe device
CIear lhe inlerrul signaI on lhe bus
Reslore lhe currenl execulion slale
Iigure 6.4.2 shovs a lyicaI sequence. Saving lhe currenl slale occurs
usuaIIy in memory, and a seciaI 0#%/0$ +0*- &$%#00/.% inslruclion reIoads
lhe saved slale, vhich corresond lo lhe foIIoving hardvare slales:
VaIues in regislers
Irogram counler
Condilion code
8'942% !5G5: C'EF/% <+-%224F- ?2*)%=='+9
Study Guide 6: Computer Program Execution Concepts
67L
6.4.3 How Interrupts Work on the 80x86
An ISR (inlerrul service rouline) is a iece of soflvare residenl
somevhere in memory. When an inlerrul is delecled, lhe rocessor musl
delermine lhe Iocalion of lhe ISR and lhen |um lo il, execule il, and
relurn lo vhal il vas doing before lhe inlerrul occurred. Ivery inlerrul
suIies a %@.# $/-A#0, vhich is used by lhe rocessor as a oinler inlo
lhe &$%#00/.% K#6%*0 %'A(# (IVT). The IVT is slored in lhe Iovesl 1024 byles of
memory. Il can be envisaged as an array of 256 number airs (veclors
for lhe inleIIigenlsia), each number 2 byles (16 bils), so each air is 4 byles
Iong. The airs are numbered 0 lo 255, corresonding lo lhe inlerrul
numbers. Iach air in lhe labIe slores lvo 16-bil vaIues, II and CS, lhe
air is caIIed an inlerrul veclor. II is slored in lhe firsl 2 byles, CS in lhe
second lvo. Loading lhe IVT vilh lhe roer subrogram addresses is
one of lhe firsl lasks erformed by lhe rocessor vhen booling, or, under
lhe Windovs XI OS, in crealing lhe DOS box.
The INT inslruclion is lvo byles Iong. The firsl byle is lhe o-code, CD,
and lhe second is lhe inlerrul lye number 00 lo II. (Hovever INT 3 is
seciaIIy coded as a singIe byle inslruclion, o-code CC. This means Iess
disrulion vhen il is inserled as a breakoinl).
When lhe CIU senses an inlerrul, il:
1. Iushes lhe rogram slalus vord (conlaining lhe fIags) onlo lhe slack
(IUSHI inslruclion)
2. CIears lhe TI (singIe sle fIag) and lhe II (inlerrul-enabIe fIag)
3. Iushes CS onlo lhe slack
4. Ielches lhe nev vaIue of CS from lhe inlerrul veclor
5. Iushes II onlo lhe slack
6. Ielches lhe nev vaIue of II from lhe inlerrul veclor
7. }ums lo lhe nev Iocalion addressed by CS:II.
The rocess is simiIar lo lhe far CALL inslruclion, excel lhal lhe fIags are
aIso ushed onlo lhe slack.
UsuaIIy, lhe ISR handIer immedialeIy re-enabIes lhe inlerrul syslem (by
cIearing II) lo aIIov high-riorily inlerruls lo occur, il aIso saves on lhe
slack any regislers lhal il is going lo use, and lhen rocesses lhe inlerrul
as quickIy as ossibIe. Some exlernaI (hardvare) inlerruls aIso require an
acknovIedgmenl so lhal lhey viII knov lhal lhe inlerrul has been
recognised.
FIT1001 Computer Systems
67#
IinaIIy, lhe handIer execules lhe seciaI IRIT (Inlerrul RITurn)
inslruclion lhal reslores lhe originaI slale of lhe CIU fIags, lhe code
segmenl regisler CS and lhe inslruclion oinler II.
$%., Reader IngIander, Chaler 9, ages 238 - 351
6.5 Case Studies of Real Architectures
MARII shares many fealures vilh modern archileclures bul il is nol an
accurale deiclion of lhem. We shaII examine lvo machine archileclures.
We viII Iook al an InleI archileclure, vhich is a CISC machine and MIIS,
vhich is a RISC machine. CISC is an acronym for comIex inslruclion sel
comuler. RISC slands for reduced inslruclion sel comuler.
Intel Architectures
The cIassic InleI archileclure, lhe 8086, vas born in 1979. Il is a CISC
archileclure. Il vas adoled by IM for ils famed IC, vhich vas reIeased
in 1981. The 8086 oeraled on 16-bil dala vords and suorled 20-bil
memory addresses. Laler, lo Iover cosls, lhe 8-bil 8088 vas inlroduced.
Like lhe 8086, il used 20-bil memory addresses. The 8086 had
four 16-bil generaI-urose regislers lhal couId be accessed by lhe
haIf-vord.
a fIags regisler, an inslruclion regisler, and a slack accessed
lhrough lhe vaIues in lvo olher regislers, lhe base oinler and lhe
slack oinler
no buiIl in fIoaling-oinl rocessing, bul in 1980, InleI reIeased lhe
8087 numeric corocessor
In 1985, InleI inlroduced lhe 32-bil 80386. Il aIso had no buiIl-in fIoaling-
oinl unil. The 80486, inlroduced in 1989, vas an 80386 lhal had buiIl-in
fIoaling-oinl rocessing and cache memory. The 80386 and 80486 offered
dovnvard comalibiIily vilh lhe 8086 and 8088. Soflvare vrillen for lhe
smaIIer vord syslems vas direcled lo use lhe Iover 16 bils of lhe 32-bil
regislers. CurrenlIy, InleI's mosl advanced 32-bil microrocessor is lhe
Ienlium 4. Il can run as fasl as 3.06 GHz. This cIock rale is over 350 limes
fasler lhan lhal of lhe 8086. Seed enhancing fealures incIude muIliIeveI
cache and inslruclion ieIining. InleI, aIong vilh many olhers, is
marrying many of lhe ideas of RISC archileclures vilh microrocessors
lhal are IargeIy CISC.
Study Guide 6: Computer Program Execution Concepts
67"
MIPS Architectures
The MIIS famiIy of CIUs has been one of lhe mosl successfuI in ils cIass.
In 1986 lhe firsl MIIS CIU vas announced. Il had a 32-bil vord size and
couId address 4G of memory. Over lhe years, MIIS rocessors have been
used in generaI urose comulers as veII as in games. The MIIS
archileclure nov offers 32- and 64-bil versions. MIIS vas one of lhe firsl
RISC microrocessors. The originaI MIIS archileclure had onIy 55
differenl inslruclions, as comared vilh lhe 8086 vhich had over 100.
MIIS vas designed vilh erformance in mind: Il is a (*'=L"%*0#
archileclure, meaning lhal onIy lhe Ioad and slore inslruclions can access
memory. The Iarge number of regislers in lhe MIIS archileclure kees bus
lraffic lo a minimum.
RISC Vs CISC
The underIying hiIosohy of RISC machines is lhal a syslem is beller
abIe lo manage rogram execulion vhen lhe rogram consisls of onIy a
fev differenl inslruclions lhal are lhe same Ienglh and require lhe same
number of cIock cycIes lo decode and execule. RISC syslems access
memory onIy vilh exIicil Ioad and slore inslruclions.
In CISC syslems, many differenl kinds of inslruclions access memory,
making inslruclion Ienglh variabIe and felch-decode-execule lime
unrediclabIe.
The difference belveen CISC and RISC becomes evidenl lhrough lhe basic
comuler erformance equalion:
RISC syslems shorlen execulion lime by reducing lhe cIock cycIes er
inslruclion. CISC syslems imrove erformance by reducing lhe number
of inslruclions er rogram. The simIe inslruclion sel of RISC machines
enabIes conlroI unils lo be hardvired for maximum seed. The more
comIex-- and variabIe-- inslruclion sel of CISC machines requires
microcode-based conlroI unils lhal inlerrel inslruclions as lhey are
felched from memory. This lransIalion lakes lime. Wilh fixed-Ienglh
inslruclions, RISC Iends ilseIf lo ieIining and secuIalive execulion.
ecause of lheir Ioad-slore ISAs, RISC archileclures require a Iarge
number of CIU regislers. These regisler rovide fasl access lo dala during
sequenliaI rogram execulion. They can aIso be emIoyed lo reduce lhe
overhead lyicaIIy caused by assing aramelers lo subrograms. Inslead
of uIIing aramelers off of a slack, lhe subrogram is direcled lo use a
FIT1001 Computer Systems
667
subsel of regislers. The TabIe 6.5.1 on lhe nexl age summarises lhe
characlerislics of RISC machines versus CISC machines.
M.1/% !5K56 M3% I3.2.)-%2'=-')= *B $<CI H.)3'+%= &%2=4= I<CI H.)3'+%=
$%., NuII and Lobur, chaler 4, ages 182 (from 4.8) - 189
NuII and Lobur, chaler 9, ages 412 - 417 (lo 9.3)
Web Access
N%1 O))%== Access C-4,J P4',% ! seclion of lhe unil vebsile and
comIele Iab / luloriaI exercises.
Study
Guide
!
Computer Memory
Components and
Organisation
LEARNING OBJECTIVES
On comIelion of lhis session you viII be abIe lo:
be abIe lo describe differenl lyes of rimary memory,
undersland lhe concels of hierarchicaI memory organizalion,
undersland hov each IeveI of memory conlribules lo syslem
erformance, and hov lhe erformance is measured,
exIain lhe concels of cache memory, virluaI memory, aging,
address lransIalion and memory segmenlalion.
FIT1001 Computer Systems
""#
Contents
7.1 Inlroduclion
7.2 Tyes of Memory
7.3 The Memory Hierarchy
7.4 Cache Memory
7.5 VirluaI Memory
Reading
Prescribed readings
NuII and Lobur, !""#$%&'(" *+ ,*-./%#0 102'$&3'%&*$ 4 5067&%#6%/0#8
Chaler 3: ooIean AIgebra and DigilaI Logic
Chaler 4: MARII: An Inlroduclion lo a SimIe Comuler
Chaler 6: Memory
Study Guide 7: Computer Memory Components and Organisation
""$
7.1 Introduction
Mosl comulers are buiIl using lhe slored-rogram concel of lhe von
Neumann modeI using memory. The funclion of lhe memory is lo hoId
lhe inslruclions of rograms lhal are being execuled and lhe dala being
rocessed. The memory needs lo be abIe lo
Read lhe inslruclions of rograms being execuled
Read and vrile dala in memory
Mainlain informalion ermanenlIy
We have examined a simIe 4 X 3 bil memory and sludied hov lo address
memory Iocalions earIier.
The lvo key asecls of memory are
TechnoIogy, vhich refers lo lhe underIying hardvare
Organizalion, vhich refers lo hov lhe underIying hardvare is used
lo buiId lhe memory syslem
Some of lhe imorlanl characlerislics of memory are
VoIaliIe (conlenls disaear vhen over is removed) or non-
voIaliIe
Random (lyicaI) or sequenliaI access (eg. IIIO, 9&0"%:;$:9&0"%:1/%)
Read-vrile or read onIy
Irimary (high seed, lyicaIIy soIid slale) or secondary (sIover,
Iarger caacily, lyicaIIy magnelic media and eIeclro-mechanicaI
drive mechanism)
Speed
Memory seed is measured by ils access lime. Access lime is lhe lime
eriod from lhe aearance of a vaIid address on lhe address Iines lo lhe
vaIid dala aearing al lhe dala Iines. Access lime is measured in
%&%'()*'%+( (%(). One nanosecond refers lo one biIIionlh of a second (10
-
9
sec) a very smaII fraclion of lime!
To a Iarge exlenl a comuler's erformance deends on lhe seed of ils
memory. High erformance memory syslems are exensive. Hence
designers choose memory syslems lo salisfy bolh erformance and cosl
conslrainls
FIT1001 Computer Systems
"",
-)&+ NuII and Lobur, chaler 3, ages 117 (from 3.6.4) - 120 (lo 3.7)
-)&+ NuII and Lobur, chaler 4, ages 153 (from 4.1.5) - 156 (lo 4.1.6)
7.2 Types of Memory
Comulers slore lheir informalion in bolh rimary slorage and secondary
slorage devices. Secondary slorage devices incIude magnelic disks, laes
and olicaI disks. These are discussed in lhe Sludy Guide 08 and viII nol
be covered here. Irimary memory, aIso caIIed main memory, makes use
of siIicon chis lo slore lhe inslruclions of rograms and dala. Though
lhere are a Iarge number of semiconduclor memory lechnoIogies, lhere are
onIy lvo basic lyes of memory:
RAM (!'$<*- "66#"" ##-*0=) vhich is lhe voIaliIe, read-vrile
memory.
ROM (!#'< $$(= ##-*0=) vhich is a lye of memory lhal can
ermanenlIy or semi ermanenlIy slore dala. ROM is knovn as non-
voIaliIe memory because any dala slored in ROM remain lhere even
vhen lhe over is disconnecled. ROM slores crilicaI informalion
necessary lo oerale lhe syslem, such as lhe informalion required lo
iniliaIize lhe comuler.
RAM Technologies
The lechnoIogies used lo imIemenl RAMs can be divided inlo lvo
broad calegories:
Slalic RAM (.-/0)
Dynamic RAM (1-/0)
SRAM mainIy consisls of circuils simiIar lo lhe fIi-fIo digilaI circuil.
asicaIIy lhe circuil has lvo inuls and one oulul as foIIovs:
!2#2" .-/0 456*758 9'6 & (5%:;) <58
inul
Wrile enabIed
oulul
Circuil for 1
bil
Study Guide 7: Computer Memory Components and Organisation
""=
To slore / vrile a vaIue lhe vaIue (eilher a 0 or 1) is Iaced on lhe inul
Iine, lhe vrile enabIed Iine is sel lo on (a osilive voIlage) and lhen lurned
off again. Wilh lhe vrile enabIed Iine lurned off lhe circuil hoIds lhe
charge.
SRAM erforms al high seeds and has a Iover densily rale (vhen
comared vilh DRAM. Iover consumlion and heal is a ma|or robIem
as lhe many lransislors inside lhe circuil oerale conlinuousIy. AIso due
lo ils design SRAM is more exensive lo roduce lhan DRAM.
DRAM uses a circuil lhal acls Iike a caacilor lo slore informalion. When
a vaIue is vrillen lhe hardvare charges or discharges lhe caacilor lo
refIecl a digilaI vaIue. Ior a read lhe hardvare examines lhe charge on lhe
caacilor and generales lhe reIevanl digilaI vaIue. Due lo ils design
DRAM is an imerfecl memory device as caacilors viII graduaIIy Iose
lheir charge. If Iefl Iong enough lhe vaIue slored viII evenluaIIy Ieak from
lhe caacilor. In lerms of DRAM lhis can be as IillIe as under once second.
An addilionaI circuil is added lo DRAM lo aIIov refreshing of lhe
caacilor. This can be seen as foIIovs:
!2#2# 1-/0 456*758 9'6 & (5%:;) <58
Refresh hardvare is more comIex lhan indicaled above. Inslead of
adding one circuil lo each bil a refresh mechanism is designed lo cycIe
lhrough lhe enlire memory. The refresh circuil musl coordinale lhe refresh
rocess vilh normaI memory oeralions. AIso lhe hardvare musl ensure
lhal lhe vaIue of a bil does nol change belveen lhe lime lhe refresh circuil
reads a bil and lhe lime lhe circuil vriles lhe same vaIue back. Hovever,
even vilh lhese issues, lhe cosl and over consumlion advanlages of
DRAM are more advanlageous lhan using SRAM. You viII generaIIy find
SRAM used for fasl memory aIicalions such as cache.
RAM Examples
During lhe evoIulion of comulers lhere have been a number of RAM
lechnoIogies used for main memory rimariIy lo imrove lhe
erformance of lhe memory syslem and aIso reduce cosl. Synchronized
inul
Wrile enabIed
oulul
Circuil for 1
bil
Refresh
FIT1001 Computer Systems
"">
memory lechnoIogies use cIocks synchronised vilh lhe CIU cIock lo
avoid unnecessary deIays, and are aIicabIe lo bolh SRAMs and
DRAMs. MuIliIe dala rale memory lechnoIogies imrove memory
erformance by using cIocks lhal run al a muIliIe of lhe bus cIock. Some
of lhe commerciaIIy avaiIabIe RAM lyes are Iisled beIov:
IIM RAM (9'"% >'2# ?*<# @5?)
IDO RAM (!A%#$<#< B'%' 1/% @5?)
SDRAM (C=$670*$*/" B@5?)
DDR SDRAM (B*/D(# B'%' @'%# CB@5?)
DDR2 SDRAM 9'"%#0 E#0"&*$ *+ BB@ CB@5?
RDRAM (@'-D/" B@5?)
Higher densily memory generaIIy resuIls in Iover cosls bul may have lhe
disadvanlage of increased over consumlion.
ROM Technologies
We have seen earIier ROM is lhe ideaI Iace lo slore slarl u informalion
for a comuler, being non-voIaliIe. OriginaIIy ROMs vere manufaclured
vilh lhe dala aIready buiIl in.
The lechnoIogies used lo imIemenl ROMs can be divided inlo lhe
foIIoving calegories:
ROM (!#'< $$(= ##-*0=) vhere lhe informalion cannol be changed
and is usefuI for firmvare
IROM (%0*20'--'D(# !#'< $$(= ##-*0=) iniliaIIy emly/bIank and
can be vrillen once.
IIROM (&0'"'D(# %0*20'--'D(# !#'< $$(= ##-*0=) vhose conlenls
can be aIlered, bul doing so is lime-consuming and may invoIve
removaI from a circuil and exosure lo uIlravioIel Iighl
IIIROM (&(#6%0&6'((= &0'"'D(# %0*20'--'D(# !#'< $$(= ##-*0=)
vhose conlenls couId be erased / be vrillen lo muIliIe limes (uses
eIeclricaI charge for rocess), aIso knovn as +('"7 @1? vhen
vrillen or erased in bIocks.
Many comulers loday use an IIIROM for lheir IOS informalion as
lhese can be easiIy udaled via soflvare udales.
-)&+ NuII and Lobur, chaler 6, ages 233 235 (lo 6.3)
Study Guide 7: Computer Memory Components and Organisation
""!
7.3 The Memory Hierarchy
Nol aII memory is crealed equaI and some lyes are fasler and lhus more
exensive lhan olhers. To deaI vilh lhis disarily, loday's comuler
syslems use a combinalion of memory lyes lo reduce overaII cosl vhiIsl
mainlaining an accelabIe IeveI of erformance. This aroach is caIIed
7&#0'067&6'( -#-*0=F
-)&+ NuII and Lobur, chaler 6, ages 235 (from 6.3) - 247 (lo 6.4)
7.4 Cache Memory
A cache memory is a smaII, lemorary, fasl memory lhal lhe rocessor
uses for sloring frequenlIy used informalion. The comuler uses lhe
IocaIily rinciIe lo lransfer an enlire bIock from main memory inlo cache
memory vhenever il has lo make a main memory access. If lhe robabiIily
of using somelhing eIse in lhal bIock is high, lhen lransferring lhe enlire
bIock saves on access lime.
So hov does il vork` When lhe CIU needs lo read dala, il firsl checks lo
see vhelher lhe dala is in lhe cache. If il is (caIIed a ?58), lhe dala is read
direclIy from lhe cache. If il is nol (caIIed a @5((), lhe dala is read from
lhe usuaI RAM and is aIso vrillen inlo lhe cache, aIong vilh
neighbouring dala, in lhe hoe lhal lhis dala viII be used again soon.
Ior examIe: main memory seed 200 ns, cache memory seed 50 ns,
assuming 90% hil rale lhen lhe average memory access seed is:
0.9 50 + 0.1 200 45 + 20 65 ns
This is a very significanl imrovemenl.
There are lhree IeveIs of cache, L1, L2 and L3.
L1 cache is aIso knovn as inlernaI cache as il is has aIvays been buiIl inlo
lhe rocessor. ecause of lhis lhe L1 cache runs al lhe same seed as lhe
rocessor core and is lhe faslesl cache.
L2 cache vas originaIIy caIIed exlernaI cache because il vas exlernaI lo lhe
rocessor. This meanl lhal lhe L2 cache vas inslaIIed on lhe molherboard
and oeraled al lhe molherboard and CIU bus seeds. In many
rocessors from 1999 onvards, L2 vas incororaled inlo lhe rocessor
FIT1001 Computer Systems
""A
chi, lhough exlernaI lo lhe CIU. This inlernaI L2 cache oerales al
seeds higher lhan lhe bus and is Iarger lhan L1 cache.
L3 cache is found in some high-end rocessors and rovides an addilionaI
IeveI of cache. L3 cache is aIso buiIl inlo lhe rocessor chi and is Iarger
lhen L2 cache.
UnIike main memory, vhich is accessed by address, cache is lyicaIIy
accessed by conlenl, hence, il is oflen caIIed 6*$%#$% '<<0#""'D(# -#-*0= or
CAM.
-)&+ NuII and Lobur, chaler 3, ages 237 (from 6.4) - 239 (lo 6.4.1)
Cache Mapping Schemes
The simIesl cache maing scheme is <&0#6% -'..#< 6'67#. Ior examIe, in
a direcl maed cache consisling of G bIocks of cache, bIock H of main
memory mas lo cache bIock I H mod GF Thus, if ve have 10 bIocks of
cache, bIock 7 of cache may hoId bIocks 7, 17, 27, 37, . . . of main memory.
Once a bIock of memory is coied inlo ils sIol in cache, a E'(&< bil is sel for
lhe cache bIock lo Iel lhe syslem knov lhal lhe bIock conlains vaIid dala
and lhe lag fieId uniqueIy idenlifies a vord from a secific bIock in main
memory. Direcl maed cache evicls a bIock vhenever anolher memory
reference needs lhal bIock's sace.
Wilh +/((= '""*6&'%&E# 6'67#, ve have no such maing, lhus ve musl
devise an aIgorilhm lo delermine vhich bIock lo evicl from lhe cache. The
bIock lhal is evicled is lhe E&6%&- D(*6JF C#% '""*6&'%&E# 6'67# combines lhe
ideas of direcl maed cache and fuIIy associalive cache. Wilh fuIIy
associalive and sel associalive cache, a 0#.('6#-#$% .*(&6= is invoked vhen
il becomes necessary lo evicl a bIock from cache. A (#'"% 0#6#$%(= /"#<
(LRU) aIgorilhm kees lrack of lhe Iasl lime lhal a bIock vas assessed and
evicls lhe bIock lhal has been unused for lhe Iongesl eriod of lime.
9&0"%:&$K +&0"%:*/% (IIIO) is a ouIar cache reIacemenl oIicy. Cache
reIacemenl oIicies musl aIso lake inlo accounl <&0%= D(*6J", lhose bIocks
lhal have been udaled vhiIe lhey vere in lhe cache bul have nol been
vrillen back lo main memory. There are lvo lyes of vrile oIicies, L0&%#
%70*/27 and L0&%# D'6J
-)&+ NuII and Lobur, chaler 6, ages 239 (from 6.4.1) -250 (lo 6.5)
Study Guide 7: Computer Memory Components and Organisation
""B
7.5 Virtual Memory
VirluaI memory enhances erformance by roviding grealer memory
caacily, vilhoul lhe exense of adding main memory. Inslead, a orlion
of a disk drive serves as an exlension of main memory. A .7="&6'( '<<0#""
is lhe acluaI memory address of hysicaI memory. Irograms creale E&0%/'(
'<<0#""#" lhal are -'..#< lo hysicaI addresses by lhe memory
managemenl unil (MMU).
In .'2&$2 main memory and virluaI memory are divided inlo equaI sized
ages. Informalion concerning lhe Iocalion of each age, vhelher on disk
or in memory, is mainlained in a dala slruclure caIIed a .'2# %'D(#F The
IogicaI age number is lransIaled inlo a hysicaI age frame lhrough a
Iooku in lhe age labIe. ecause age labIes are read conslanlIy, il makes
sense lo kee lhem in a seciaI cache caIIed a %0'$"('%&*$ (**J:'"&<# D/++#0
(TL). TLs are a seciaI associalive cache lhal slores lhe maing of
virluaI ages lo hysicaI ages.
Anolher aroach lo virluaI memory is lhe use of "#2-#$%'%&*$. Inslead of
arlilioning memory inlo equaI-sized ages, lhe virluaI address sace is
divided inlo variabIe-Ienglh segmenls, oflen under lhe conlroI of lhe
rogrammer. A segmenl is Iocaled lhrough ils enlry in a segmenl labIe,
vhich conlains lhe segmenl's slarl address, a bounds Iimil lhal indicales
ils size and access reslriclions.
-)&+ NuII and Lobur, chaler 6, ages 250 (from 6.5) - 263 (lo 6.6)
Web Access
C)< /**)(( Access .87+D E75+) ! seclion of lhe unil vebsile and
comIele Iab / luloriaI exercises.
FIT1001 Computer Systems
"#F
Study
Guide
!
Input/Output
Organisation and
Standards
LEARNING OBJECTIVES
Al lhe comIelion of lhis sludy guide you viII be abIe lo:
exIain common melhods used lo slore dala in comuler
syslems,
describe lhe slruclure and funclion of each comonenl of a
comuler syslem, and Inul-Oulul devices in delaiI,
undersland oeralionaI rinciIes of common eriheraI
devices such as lae, disk, cdrom drives, video disIays,
rinlers and olher inul devices such as mice, keyboards and
scanners,
exIain hov comulers erform inul and oulul as arl of a
comuler rogram,
idenlify lhe faclors lhal conlribule lo comuler syslem
erformance in lhe organisalion of eriheraI devices.
FIT1001 Computer Systems
"##
Contents
8.1 Inlroduclion
8.2 I/O Archileclures
8.3 I/O us Slandards
8.4 Magnelic Disk TechnoIogy
8.5 OlicaI Disks
8.6 Magnelic Tae
8.7 Irinler and DisIay Devices
8.8 Inul Devices
Reading
Prescribed readings
NuII and Lobur, !""#$%&'(" *+ ,*-./%#0 102'$&3'%&*$ 4 5067&%#6%/0#8
Chaler 7: Inul / Oulul and Slorage Devices
Reader: urd, 9:"%#-" 5067&%#6%/0#8
Chaler 7: Inul / Oulul TechnoIogy, 260-289
Study Guide 8: I/O Organisation and Standards
"#$
8.1 Introduction
In earIier sludy, you viII have Iearnl aboul lhe rocessing and memory
comonenls of a comuler syslem. This seclion is aboul lhe inul and
oulul devices exlernaI lo lhe comuler, some of vhich are used for dala
slorage. In lhis seclion, you viII sludy lhe organisalion of
inlerconneclions belveen olher comuler comonenls and I/O devices,
rogramming and conlroI melhods, as veII as lhe lechnoIogy used in
magnelic and olicaI slorage devices, rinlers, video disIays and olher
inul eriheraIs, incIuding keyboards, mice and audiovisuaI devices.
8.2 I/O Architectures
The Inul/Oulul subsyslem of a comuler is used lo move dala belveen
exlernaI devices and lhe hosl syslem, and incIudes:
Iocks of main memory (buffers) lhal are assigned lo I/O funclions
uses lhal convey lhe dala inlo or oul of lhe syslem
ConlroI Iogic moduIes in lhe hosl and in lhe devices
Command and dala inlerfaces lo devices such as keyboards and
disks
CabIes and communicalion Iinks belveen lhe hosl syslem and
eriheraIs
Iigure 7.1 from on age 276 of NuII and Lobur shovs a lyicaI I/O
subsyslem configuralion vhere dala fIovs lhrough high seed buses from
memory or CIU lo I/O device inlerfaces, vhich connecl via cabIes lo
exlernaI devices. Nole lhal lhese devices may be exlernaI lo lhe comuler
circuilry, bul sliII be mounled vilhin a singIe cabinel or case vilh lhe resl
of lhe comuler machinery.
SeveraI melhods of conlroIIing lhis fIov of I/O are avaiIabIe, incIuding:
Irogrammed (or IoIIed) I/O
Inlerrul-driven I/O
Direcl Memory Access (DMA)
ChanneI-allached (or Dala-channeI) I/O
Programmed I/O
In lhe rogrammed I/O melhod CIU inslruclions are used lo exchange
dala belveen lhe exlernaI device and a CIU slorage regisler. WhiIe lhis is
robabIy lhe simIesl and cheaesl melhod, is il aIso lhe Ieasl efficienl, in
lhal il requires lhe CIU lo conlinuous execule sequences of inslruclions
FIT1001 Computer Systems
"#%
lhal erform lhe I/O oeralion, and each lransfer is generaIIy Iimiled lo
one regisler vord of dala for each CIU cycIe. This is aIso knovn as
oIIed I/O because of lhe need for lhe CIU lo inlerrogale or oII lhe
device conlinuousIy, as arl of a busy-vail rogramming Ioo. The
rogram Ioo conlains I/O inslruclions lhal sense lhe slale of lhe device
inlerface, and onIy roceed lo lransfer lhe regisler conlenls vhen lhe
device is ready lo handIe il. This melhod is CIU inlensive and nol
suilabIe for muIli-user or muIli-rogramming environmenls.
Interrupt-Driven I/O
Inlerrul-driven I/O makes use of inlerrul hardvare lo aIIov lhe I/O
devices lo lrigger lhe execulion of corresonding I/O inslruclions uon
requesl. In lhis vay, il frees lhe CIU from lhe need lo conlinuousIy oII
lhe device slalus, and aIIovs lhe execulion of olher unreIaled inslruclions
vhiIe lhe I/O device is busy. The Iarge difference in lhe lime il lakes for a
device lo comIele an oeralion and lhe lime lhal lhe CIU lakes lo
execule inslruclions, means lhal lhe CIU can usuaIIy execule many
inslruclions (ossibIy from anolher user's rogram) vhiIe vailing for an
I/O oeralion lo comIele. ConlroI Iogic vilhin lhe inlerrul syslem is
used lo accel inlerrul requesls from devices and direcl lhe CIU lo a sel
of inslruclions caIIed an Inlerrul Service Rouline, vhich is designed lo
handIe lhe I/O requesled by lhe device. WhiIe inlerrul-driven I/O
reduces lhe need for lhe CIU lo execule regisler lransfer I/O inslruclions,
il is sliII necessary for lhe rogram running in lhe CIU lo be inlerruled,
and lemorariIy reIaced by lhe inslruclion sequence from an inlerrul
service rouline, even if onIy briefIy.
Direct Memory Access
Many Iarge scaIe I/O oeralions such as lhose invoIving magnelic disk or
lae drives, lransfer bIocks of dala lo or from lhe comulers main
memory. Reading or vriling lhese bIocks of dala using rogrammed or
inlerrul-driven melhods vouId invoIve lransferring one regisler vord of
dala al a lime, and require CIU inslruclions and inlerruls vilh each
vord lransferred. Wilh Direcl Memory Access, once lhe lransfer of lhe
bIock of dala has been slarled, il can be comIeled vilhoul furlher CIU
invoIvemenl. Once lhe DMA conlroI Iogic has been rogrammed (by
inslruclions from lhe CIU) al lhe slarl of a bIock I/O lransfer, il can be
used by lhe device inlerfaces lo lransfer vords of dala direclIy lo or from
lhe comuler's main memory. Iigure 7.2 on age 278 of NuII and Lobur
shovs an examIe DMA configuralion. In smaII comulers, a DMA
lransfer lakes Iace using lhe same buses lhal lhe CIU uses lo felch
inslruclions and oerands. This form of I/O aIIovs lhe comuler lo
lransfer dala lo or from devices al very high rales bul may Iead lo
Study Guide 8: I/O Organisation and Standards
"#&
conlenlion on lhe dala bus, belveen lhe felching of CIU inslruclions and
lhe lransfer of bIocks of dala.
Channel I/O
Many I/O oeralions require lhe movemenl of voIumes of dala belveen
fiIes on disk or belveen fiIes and devices. Ior examIe, rinling a fiIe, or
lransferring a fiIe belveen machines allached lo a nelvork. Using
rogrammed or inlerrul-driven I/O vouId require lhal lhe dala be
lransferred a vord al a lime vilh CIU inslruclions and inlerruls for each
vord lransferred. Using a DMA lransfer vouId invoIve lhe CIU onIy al
lhe slarl and end of each bIock of dala, bul sliII require lhal each bIock be
lemorariIy coied inlo main memory, and ossibIe bus conlenlion. Wilh
ChanneI-allached or Dala ChanneI I/O even lhis may nol be necessary, as
searale I/O Irocessors vilh lheir ovn bus alhvays can be used lo
lransfer lhe dala vilhoul main memory invoIvemenl. Iigure 7.3 on age
280 of NuII and Lobur shovs a ossibIe configuralion of channeI-allached
I/O Irocessors.
I/O Buses and Device operation
As has been sludied reviousIy, a bus is a shared dala alhvay vilh
searale circuils for each bil of dala and conlroI signaIs used lo rovide
Iogic gale aclivalion. Olher signaIs are used lo arbilrale belveen
comeling users. Iigure 7.4 on age 281 of NuII and Lobur, shovs a high-
IeveI viev of a syslem bus lhal conlains searale dala, address and conlroI
Iines. Comuler syslems conlain many differenl buses. Indeed, a good
design fealure is lo incIude searale buses for comonenls of a comuler
syslem. Some arls, such as main memory are caabIe of conlinuous and
reguIar cycIic oeralion vhere aII arls oerale in a fixed and conslanl
sequence. These are besl served by a synchronous bus vhere lhe liming of
lhe bus access cycIes is lhe same as (or al Ieasl a muIliIe of) lhal of lhe
main memory. Hovever, eriheraI devices rareIy oerale in a fixed
cycIic manner, lhey need lo have slarl-u and sIov-dovn slages and may
deend on exlernaI evenls, such as a key being ressed or lhe resence of
some recording media. Ior lhis reason, I/O buses generaIIy oerale
asynchronousIy. Iigure 7.6 on age 282 of NuII and Lobur shovs a disk
conlroIIer inlerface vilh conneclions lo an I/O bus. Wilh reference lo lhe
us Timing diagram in Iigure 7.7 (on age 283) you can see lhal lhe bus
CIock signaI can be used lo conlroI Iogic gales lhal samIe lhe olher
signaIs on lhe various bus Iines. The Requesl signaI indicales lhal a device
address is resenl as a araIIeI bil allern on lhe Address Iines and lhe
IeveI of lhe Read/Wrile signaI indicales lhal lhe bus masler device in lhis
case lhe DMA conlroIIer) is issuing a Wrile command lo lhe addressed
device. The Ready signaI indicales lhal lhe device vhose address is on lhe
FIT1001 Computer Systems
"#'
Address Iines (in lhis case lhe Disk conlroIIer) is nov avaiIabIe and lhe
dala lransfer begins in lhe foIIoving cycIes. This vhoIe sequence is
knovn as a bus rolocoI. In comIex asynchronous bus rolocoIs is il
ossibIe lo use some signaI Iines for differenl uroses al differenl slages
during lhe rolocoI.
Bus Interrupts
The bus sequence described above is vhere a bus masler device issues lhe
inslruclions and lhe sIave devices are conlroIIed accordingIy. Hovever,
lhere are silualions vhere a device vhich is nol in conlroI of lhe bus may
require allenlion, such as vhen an inul device has some dala lo be
lransferred inlo lhe comuler syslem. SmaII comuler syslems oflen use
Inlerrul-driven I/O lo do lhis. Iigure 7.8 on age 286 of NuII and Lobur
shovs an I/O subsyslem using inlerruls. One of lhe conlroI signaIs on
lhe I/O bus is sel aside for use by eriheraI conlroIIers lo signaI a requesl
for inlerrul, and is usuaIIy allached lo lhe CIU inlerrul inul Iine
(INT). Afler lhe CIU has finished execuling lhe currenl inslruclion lhe
CIU signaIs Inlerrul AcknovIedge (INTA)
()*+ NuII and Lobur, chaler 7, ages 275 (from 7.3) - 286 (lo 7.4)
8.3 I/O Bus Standards
In lhis seclion ve viII read aboul some lyicaI I/O subsyslems used for
secondary slorage and I/O device inlerconneclions. Slarling vilh delaiIs
of slandards for device inlerconneclion cabIes, lhe SCSI, IIII 1394 (or
firevire) ATA, ICI and US slandards viII be briefIy described.
IeriheraI devices need lo be connecled lo lhe conlroIIer Iogic in lhe
comuler using an inlerface cabIe. Inlerface cabIes may use eilher araIIeI
or seriaI dala lransfer. IaraIIeI conneclions are simiIar lo an inlernaI
comuler bus, vhere each bil vaIue in a vord or byle is lransmilled over
araIIeI individuaI circuils simuIlaneousIy. SeriaI dala lransmission is
vhere lhe dala bils are lransmilled over a singIe circuil in sequence.
UsuaIIy olher circuils vilhin lhe same cabIe are rovided for conlroI and
liming uIses. The overaII Ienglh of lhese inlerface cabIes is usuaIIy
Iimiled by lhe maximum dala signaIing rale, quaIily and noise re|ecling
fealures of lhe cabIe, as veII as lhe sensilivily of lhe receiver Iogic in each
inlerface.
Study Guide 8: I/O Organisation and Standards
"#,
Various slandards for lhese inlerconneclion cabIes exisl. These slandards
define lhe lye of cabIe lo be used, lhe lye and viring of lhe Iugs and
sockels. The mosl common araIIeI rinler inlerface (oflen referred lo as
lhe araIIeI orl) uses 25-in D shaed conneclors, vhiIe seriaI
conneclors use 9-in D Iugs.
The SmaII Comuler Syslem Inlerface (SCSI), aIlhough il vas deveIoed
by a commerciaI consorlium, became a nalionaI slandard in lhe earIy
1980's. SCSI devices are connecled in series (as a daisy-chain) and are
nov avaiIabIe in a variely of formals. See labIe 7A.1 and figure 7A.2 on
age 339 of NuII and Lobur for a descrilion of a SCSI configuralion and
summary of caabiIilies. One of lhe faclors Ieading lo lhe conlinued
success of lhe SCSI archileclure is ils abiIily lo inlerconnecl severaI lyes
of slorage devices. SCSI buses vere used lo connecl disk, lae and olicaI
drives lo a singIe SCSI conlroIIer inlerface vilhin lhe comuler. The
design of lhe bus uses a command sequence and slale cycIe so lhal devices
may inleracl vilh each olher of vilh lhe masler conlroIIer and lake lurns
using lhe bus lo lransfer dala. The SCSI bus vas an economicaI and
efficienl vay lo connecl many devices in Iarger syslem, such as a fiIe
server. The lhird version of lhe SCIS bus archileclure incororales a
number of differenl cabIe, Iug and dala lransfer lyes, as shovn in
Iigure 7A.4 on age 343 of NuII and Lobur.
UnIike lhe SCSI inlerface, lhe firevire IIII 1394 inlerface slandard uses
high seed seriaI dala lransfers and so requires a much lhinner cabIe.
AIso, lhe bus managemenl rolocoI used in IIII 1394 is seIf-configuring
and aIIovs devices lo be added and removed from lhe bus vilhoul lhe
need lo lurn off lhe over. This is a concel knovn as Iug and Iay or
hol-sva.
Comuler syslems vilh a need for Iarge scaIe secondary slorage or lhe
abiIily lo share a sel of slorage devices belveen severaI hosl comulers
oflen use SeriaI Slorage or Iibre ChanneI archileclures. These slorage
melhods use bus conlroI and managemenl melhods simiIar lo lhe SCSI
bus, vilh much fasler dala lransfer channeIs, oflen based on duIicaled
olicaI fibre inlerconneclions. Iigure 7A.7 and 7A.8 (Ig 346-7) of NuII and
Lobur shov some lyicaI configuralions of lhese lyes.
The deveIomenl of high seed olicaI fibre based slorage made il
ossibIe lo exlend lhe dislance belveen hosl comulers and lhe secondary
slorage devices and lhis Iead lo lhe deveIomenl of Slorage Area
Nelvorks., vhich can be used lo rovide remole access lo a shared
coIIeclion of secondary slorage devices, oflen lhrough one or more
nelvork servers. Iigure 7A-11 and 7A-12 (Iage 251-252 of NuII and Lobur)
comare Nelvork Allached Slorage ad Slorage Area Nelvork lechnoIogy.
FIT1001 Computer Systems
"#!
The high seed and Iarge caacily slorage slruclure menlioned in
revious aragrahs are oflen loo exensive for use in lyicaI IC
equimenl, vhere olher I/O bus slandards have become more common.
The originaI IM IC vas rovided vilh an 8-bil I/O bus lhal oeraled al
aboul 2Mbs and lhis and lhis became lhe basis of lhe IIII Induslry
Slandard Archileclure (ISA) bus. As IC equimenl deveIoed severaI
enhanced versions of lhis bus vere deveIoed, Ieading lo lhe AT Allached
or ATA buses and lhe IDI bus used nov for mosl IC disk drives.
IvenluaIIy, lhe ATA buses reached a Iimil of erformance, and lhe
IeriheraI Comonenl Inlerconnecl (ICI) bus vas deveIoed by a
consorlium of smaII comuler equimenl manufaclurers. RecenlIy higher
erformance versions of lhe ICI bus have been deveIoed.
()*+ NuII and Lobur, chaler 7, ages 335 (from 7A.1) - 354 (lo
Ixercises)
8.4 Magnetic Disk Technology
Magnelic recording and Iayback for digilaI dala has been a lechnoIogy
commonIy associaled vilh comuler slorage devices since comulers
vere firsl invenled. Hovever, mosl slorage devices in earIy generalion
syslems used seriaI (or sequenliaI) slorage, vhere dala vas vrillen
sequenliaIIy onlo lhe recording medium. This mean lhal an ilem lhal had
been vrillen al a cerlain osilion on lhe recording medium couId onIy be
relrieved afler firsl reading and rocessing aII lhe recorded dala lhal
receded il. So il vas a very Ienglhy and inefficienl lask if lhe order of
rocessing of lhe dala vas in a differenl sequence lo lhe order in vhich il
vas recorded. So lhe commerciaI deveIomenl of magnelic disk slorage
Iead lo a ma|or change in lhe vay informalion couId be rocessed because
lhe disk Iayback mechanism vas caabIe of Iocaling and reading bIocks
of dala vilhoul firsl having lo read lhe revious bIocks. Knovn as
random (or direcl) access, lhis made il ossibIe lo efficienlIy rocess
informalion in any sequence.
This abiIily lo read slorage bIocks al random is due lo lhe vay lhe dala is
recorded. Iigure 7.9 (Iage 287) of NuII and Lobur shovs a hyolhelicaI
viev of a disk surface, vhere lhe dala is recorded seriaIIy as a Iinear series
of bils in a slream lhal forms a concenlric recording lrack. Reresenled as
lransilion in lhe hase of a magnelic fIux recorded in a magnelic Iayer on
lhe surface of lhe disk, each lrack is divided inlo a fixed number of
recording bIocks knovn as seclors. The bil allern can be read, vrillen
or erased using one or more recording heads osilioned near bul nol
Study Guide 8: I/O Organisation and Standards
"#-
acluaIIy louching lhe surface of lhe disk. As lhe disk sins al high seed
every arl of lhe bil slream on lhe lrack becomes avaiIabIe each
revoIulion. Mosl modern disk drives have many lracks er surface and
severaI surfaces. Iigure 7.10 (Iage 288) of NuII and Lobur shovs a simIe
magnelic disk vilh a read/vrile head assembIy lhal can reciseIy
osilioned over a seIecled lrack on each surface. When an I/O oeralion
requires a arlicuIar iece of dala, lhe Iocalion can be secified as a head
number, a lrack number and a seclor number. y aclivaling onIy lhe
secified head number and moving lhe head assembIy lo lhe require
lrack, lhe reading rocess lhen onIy need lo vail for lhe required seclor lo
rolale and ass under lhe read head before lransferring lhe bil slream lo
lhe comulers main memory using DMA or ChanneI allached I/O buses.
In lhis vay, il is ossibIe lo randomIy access any arl of lhe disk slorage
very quickIy.
()*+ NuII and Lobur, chaler 7, ages 286 (from 7.4) - 293 (lo 7.5)
8.5 Optical Disks
WhiIe disk lechnoIogy makes il ossibIe lo access informalion in random
sequence, lhe exense and Iong lerm reIiabiIily of lhese devices means
lhal lhis may nol be lhe besl vay lo slore Iarge voIumes of archivaI
maleriaI. Magnelic lae vas used for lhis urose unliI recenlIy, vhen
olicaI disk slorage became a raclicaI vay lo slore Iarge voIumes of
rareIy-accessed dala for Iong limes. OlicaI disks come in a number of
formals incIuding lhe common Comacl Disk Read OnIy Memory (CD-
ROM) suilabIe for soflvare and dala dislribulion, and Comacl Disk
RevrilabIe (CD-R) vhich can be used for Wrile Once Read Many lyes
of aIicalions. OriginaIIy designed for slorage of muIli-lrack audio (and
Ialer video) recording using a singIe siraI lrack conlaining fixed Ienglh
bIocks of binary encoded dala, as shovn in Iigure 7.14 (Iage 295) of NuII
and Lobur. ils are reresenled by regions vilhin a lrack caIIed ils,
lhal aear lo be darker lhan lhe resl of lhe lrack area, resuIling in uIses
in lhe Iighl refIecled off lhe surface. CDROM usuaIIy have a lrack
conlaining lhese ils embossed inlo lhe disk surface using a ressing and
Iaminalion rocess. WrilabIe CDs reIy on lhe effecl of a high overed
Iaser lo ermanenlIy deform lhe surface in some vay and for lhe ils
vilhin a lrack. In revrilabIe disks, lhe deformalion is onIy semi-
ermanenl, so lhal a revious lrack can be erase and overvrillen by a nev
one.
FIT1001 Computer Systems
"$.
()*+ NuII and Lobur, chaler 7, ages 293 (from 7.5) - 299 (lo 7.6)
8.6 Magnetic Tapes
One of lhe earIiesl secondary slorage devices is Magnelic Tae. A reeI of
lae lyicaIIy conlained severaI lhousand feel of haIf-inch vide lhin
Iaslic fiIm, vilh a coaling of magnelic recording medium on one side, aII
roIIed onlo a sooI (and Ialer a casselle), vhich couId lhen be Iaced in a
lae drive. Dala is vrillen as a series of one or more sels of dala bIock
searaled by a recorded bil allern knovn as a fiIe mark. Iach dala
bIock or record conlained muIliIe frames vrillen across lhe vidlh of lhe
lae. Iach frame usuaIIy reresenled one characler and incIuded a arily
bil vhich vas used for error deleclion.
Much deveIomenl by lae drive manufaclurers over lhe years has Iead lo
significanl increases in lhe amounl of dala lhal can be slored on a singIe
lae medium, and aIso lo a Iarge number of lae slorage devices and
formals. DigilaI Linear Tae (DLT) and Quarler Inch Carlridge (QIC)
syslems use serenline recording melhods, vhere recording densily is
increased by moving lhe lae al very high seed asl lhe recording heads
in aIlernaling direclions. DigilaI Audio Tae (DAT) uses much narrover
(8mm) lae and a rolaling lae head lo creale a heIicaI lrack arrangemenl.
Due lo lhe removabIe nalure of lhe lae slorage medium, magnelic lae
rovides virluaIIy infinile slorage al Iov cosl and conlinues lo be used as
lhe rimary medium for fiIe and syslem backu in Iarge comuler
inslaIIalions.
()*+ NuII and Lobur, chaler 7, ages 299 (from 7.6) - 301 (lo 7.7)
8.7 Printer and Display Devices
Irinl lechnoIogy based on ink and lyeface,
has been avaiIabIe for hundreds of years, and
vhiIe earIy comuler rinlers used somelhing
simiIar, lhis aroach vas nol raclicaI for
disIay devices. The images lhal aear on
disIay devices (and Ialer rinlers) are
conslrucled using eilher a dol malrix image
Study Guide 8: I/O Organisation and Standards
"$"
(bil ma or rasler grahics) or a sequence of slroke allerns (veclor
grahics).
Dol malrix grahic oulul is conslrucled from rovs and coIumns of dols,
simiIar lo a Iarge labIe or malrix. In many lyes of disIay devices lhis
malrix is conslrucled by a dol generalion device, such as an eIeclron gun
or an ink |el. Slarling al lhe lo Iefl-hand corner of lhe disIay area, lhe
device is moved across aII lhe coIumns in lhe firsl rov from Iefl lo righl,
foIIoved by lhe nexl rov, one rov al a lime unliI lhe end of lhe disIay
area is reached. Then lhe scanning mechanism is relurned lo lhe lo-Iefl
corner and lhe vhoIe rocess is reealed. The zig-zag reealing allern
vhich is generaled in lhis vay is caIIed a rasler, and lhe rale al vhich
lhe disIay area is reealedIy scanned is caIIed lhe frame rale.
Iach dol is referred lo as a iclure eIemenl or ixeI and reresenls lhe
smaIIesl visibIe iece of lhe image. The resoIulion of an image is a
measure of lhe number of ixeIs lhal are regislered vilhin a redefined
Ienglh or area. Ig 300di is 300 dols er inch, so a square inch vouId
conlain 300 x 300 90000 dols (assuming lhe resoIulion is lhe same in aII
direclions)! Anolher measure of resoIulion is lhe dol ilch, vhich is lhe
dislance belveen dol cenlers in lhe image. GeneraIIy, lhe higher lhe
resoIulion (or lhe smaIIer dol ilch), lhe beller is lhe quaIily of lhe image.
The osilion of each ixeI is defined by lhe malrix lhal conlains il, lhis is
usuaIIy reresenled as a rov and coIumn number. The image lhen is
conslrucled by defining lhe nalure of lhe ixeI, usuaIIy ils coIour or
shade. Ior examIe, in a simIe bIack and vhile rinler, each ixeI may
conlain ink or nol, lo creale bIack or vhile ixeI on lhe
aer.
One robIem vilh malrix reresenlalion of images is lhe
slaircase effecl, vhich is vhal haens vhen lhe
image conlains an edge vhich is al an angIe lo lhe rovs
and coIumns of lhe malrix and lhe individuaI ixeIs are
visibIe as sles. This robIem becomes Iess obvious as
lhe resoIulion of lhe image increases.
Veclor grahics uses a quile differenl melhod of reresenling an image.
The image is crealed by roducing (ie draving) a sequence of iclure
comonenls. In some syslems lhere is onIy one comonenl (eg a Iine
segmenl or slroke), in olher syslems lhere may be a sel of differenl
comonenls made from slandard geomelric shaes and allerns (Iines,
eIIises, lriangIes and bilmas). The image is defined in lerms of lhe
sequence of comonenls lo be dravn and lheir osilion, orienlalion, size
and coIour or shade. Ior examIe, in a slroke draving veclor grahic
FIT1001 Computer Systems
"$#
disIay, lhe image vouId be conslrucled by crealing a sequence of Iine
segmenls, vhere each segmenl is secified by:
an X:Y coordinale, lo define lhe slarling osilion of lhe slroke
reIalive lo lhe origin of lhe draving area (usuaIIy lhe lo Iefl
corner),
a Ienglh, lo shov hov Iong lhe slroke shouId be
an angIe (in degrees from verlicaI), lo shov lhe direclion of lhe
slroke
a coIour or shade or lhickness for lhe Iine segmenl.
Many advanced disIay devices, such as rinlers caabIe of roducing
grahics, are acluaIIy veclor grahic oulul devices. They can accel dala
vrillen in an image descrilion Ianguage (eg ICL, Ioslscril, IDI) and
lhen inlerreled lhis lo roduce lhe required image.
The buIk of rinled or disIayed oulul is usuaIIy lexl. In lhe memory of
lhe comuler, lhis is reresenled using binary numbers for ASCII or
Unicode characlers, bul on lhe disIay il is a characler using a fonl. The
idea of fonls is as oId as vriling and is somelhing ve aII lake for granled.
Characler fonls are usuaIIy crealed using dol malrix grahic
reresenlalions. Mosl disIay devices have a buiIl-in sel of fonls, vhiIe
lhe fonls for some devices may be uIoaded as a kind of dala labIe, vhich
defines lhe allern of ixeIs for each characler in lhe dala sel. In order lo
roduce fonls of differenl sizes, lhere usuaIIy needs lo be a searale labIe
for each fonl (or oinl) size. One imorlanl varialion on lhis idea is lhal of
scaIabIe fonls. These are bil ma allerns for lhe characlers lhal can be
exanded or conlracled using a malhemalicaI lransformalion, so lhal a
singIe fonl labIe can roduce Iellers of virluaIIy any size.
The idea lhal arls of lhe image (eg. lhe ixeIs or lhe slroke eIemenls)
have allribules, such as coIor or osilion or size, requires lhal lhese
allribules be reresenled in numeric formal. The mosl common allribule is
lhal of coIour or shade. CoIour can be reroduced by combining lhe lhree
rimary coIours in varying amounls. Shades can be crealed by varying lhe
amounl of one coIour (usuaIIy bIack). These amounls are reresenled
using a binary number. The mosl common melhod of crealing coIour in a
disIay device is lhe RG syslem, vhere lhree 8-bil numbers are used lo
reresenl lhe amounl (or brighlness) of Red, Green and Iue. A vaIue of
zero means none and a vaIue of 255 mean fuII- slrenglh. Combining lhese
logelher requires a 24-bil sequence. Ior examIe, 0:0:0 reresenls Iack
and 255:255:255 is While.
Il is imorlanl lo consider hov much memory is required lo slore lhis
ixeI allribule informalion. Images can easiIy consume Iarge amounls of
memory. Ior examIe a lyicaI disIay screen has a resoIulion of 800x600
Study Guide 8: I/O Organisation and Standards
"$$
ixeIs and each ixeI requires 24 bils (3 byles) of memory lo slore ils
coIour delaiIs. So a singIe image of lhis lye required more lhan 1Myle!
To reduce lhe cosl and imrove erformance, many devices use a smaII
subsel of lhe avaiIabIe coIours, caIIed a aIelle. The number of lhe
.*"&%&*$ &$ %7# .'(#%%# is lhen used lo reresenl lhe coIour of a ixeI inslead
of lhe 24-bil RG code. Ior examIe, using a redefined 16 coIour aIelle
means lhal lhe coIour of a ixeI onIy needs 4 bils of slorage, so lhe same
800x600 ixeI image referred lo above vouId onIy use 234Kyles of
memory.
The aarenl quaIily of an image can aIso be imroved by inlermixing
differenl coIour ixeIs in various inlerIocking allerns. This idea is knovn
as dilhering of haIf-lone imaging. Il has been used in lhe rinl
induslry for some lime lo roduce shades and lexlures, bul lends lo
reduce lhe lrue resoIulion of an image.
()*+ Reader - urd, chaler 7, ages 260 (from asic Irinl and
DisIay Concels) 270 (lo Video DisIays)
Video Displays
Comulers have aIvays had oulul
devices, bul video disIays onIy became
common in lhe 1970's, as lhey reIaced
leIelyes and olher rinled oulul
devices. IarIy VisuaI DisIay TerminaIs
used Calhode Ray Tubes simiIar lo lhose
used in leIevision sels and acceled dala
as slrings of ASCII characlers using RS232
seriaI dala communicalions lransfers. They
vere reaIIy onIy caabIe of disIaying
characlers.
The diagram oosile shovs lhe oeralion
of a characler-based VDT. VDTs combine
severaI kinds of I/O devices inlo a singIe
unil. A Keyboard conlaining funclion keys
and a numeric key ad is used for
characler inul. Iressing a key generales
an ASCII characler code vhich is lhen
lransmilled over lhe seriaI I/O circuil.
SimuIlaneousIy, ASCII characler received from lhe seriaI I/O inul are
FIT1001 Computer Systems
"$%
converled inlo a bilma allern and slored al a Iocalion in lhe video RAM
vhich is delermined by a currenl cursor. The video RAM has lvo access
alhs, so vhiIe lhe seriaI I/O is laking Iace, a rasler scan generalor can
conlinuousIy read lhe enlire video RAM and use lhe bils on each rov lo
creale corresonding dols on lhe screen. This resuIls in lhe aearance of
characlers on lhe disIay surface. As characlers arrive from lhe seriaI I/O
circuil, lhe corresonding bilma allerns aear on lhe screen during
lhe nexl rasler scan.
More advanced VDTs used sequences of conlroI characlers (usuaIIy
slarling vilh an escae code) lo drav shaes. These escae sequences
vere arl of lhe ASCII dala slream and vere used lo disIay boxes and
forms or bilma images on lhe screen. The firsl video disIays caabIe of
advanced grahics vere aIso deveIoed al aboul lhis lime, bul became
more common as devices allached lo ersonaI comulers.
The seriaI I/O inlerface used in VDT Iimils lhe rale al vhich dala can be
lransferred lo lhe disIay screen. TruIy generaI urose grahic disIay
requires lhal dala be deIivered direclIy lo lhe video RAM. To achieve lhe
high dala rales required, lhe video RAM is oflen arl of lhe comuler's
ovn memory syslem or accessibIe direclIy via lhe comuler's I/O buses.
This is caIIed memory-maed I/O. The rasler scan signaIs necessary lo
disIay iclures on a monilor are lhen generaled in lhe video conlroIIer
and connecled lo a disIay in a searale video monilor device using a
video signaI cabIe. Iigure 7.9 (Iage 272) of urd shovs lhe conceluaI
delaiI of a modern comuler video adaler.
Modern video conlroIIers oflen conlain seciaIised rocessors caabIe of
direclIy maniuIaling lhe bil allerns in lhe video RAM lo erform
comIex lransformalions and rendering oeralions. Some video
conlroIIers are aIso knovn as Grahics AcceIeralors, vhich can lake over
many oeralions lhal vouId have reviousIy been done using soflvare.
This has Iead lo lhe deveIomenl of image disIay Ianguages such as
OenGL and DivX.
Many video disIay lechnoIogies are avaiIabIe lo be used lo conslrucl
video monilors. The mosl common form of video monilor uses a Calhode
Ray Tube vhich is lhe same lechnoIogy as used in mosl leIevision sels. A
CRT consisls of a screen vilh a Iayer of hoshors arranged so lhal lhese
gIov vhen iIIuminaled by an eIeclron beam. Differenl mixlures of
hoshors can be used lo creale differenl coIours. An array of coiIs
carrying a varying eIeclric currenl is used lo svee lhe eIeclron beam
across lhe hoshor coaled screen in a rasler allern, and lhe slrenglh of
lhe beam is conlroIIed (ie svilch on and off) so lhal lhe desired ixeI
malrix allern aears on lhe screen. This lechnoIogy is very oId and
Study Guide 8: I/O Organisation and Standards
"$&
veII eslabIished bul uses gIass and melaI lubes conlaining a vacuum vilh
high voIlage over suIies vhich are exensive and consume a Iol of
over.
Anolher lechnoIogy is lhe Liquid CryslaI DisIay, vhich reIies on lhe
change in oIarisalion of Iighl as il asses lhrough some kinds of
oIymers. Liquid cryslaI oIymers have lhe seciaI roerly lhal lhey
normaIIy rolale lhe direclion of oIarisalion of Iighl beams lhal ass
lhrough lhem, bul vhen slressed by an eIeclric fieId, lhe Iiquid cryslaI
oIymers aIign and lhe rolalion in oIarisalion is reduced. Iigure 7-10
(age 275) in lhe reading from urd shovs hov Iighl assing lhrough a
air of cross-oIarised fiIlers is bIocked vhen an eIeclric fieId is resenl,
anl nol bIocked vhen lhe fieId is absenl. LCD screens consisl of arrays of
Iiquid cryslaI ceIIs vhich can be individuaIIy exosed lo an eIeclric fieId,
effecliveIy lurned on or off al high seed, vilh rear ro|eclion Iighling
and red, bIue and green coIour fiIlers lo achieve fuII coIour disIay. LCDs
have lhe advanlage lhal lhey can be a Iol more comacl lhan CRTs and
oerale al much Iover voIlages, and so use Iess over. ul lhe CRT
disIay is usuaIIy brighler, visibIe from aII angIes and can oerale al
much higher frame rales.
IIasma disIays can aIso be as brighl as CRTs and be vieved from any
angIe bul require higher voIlages and more over lhan LCDs. IIasma
disIays use lhe uIlra-vioIel radialion generaled by lhe discharge from a
gas. When a high voIlage uIse asses lhrough lhe gas, il forms a Iasma
vhich radiales UV Iighl, simiIar lo a fIuorescenl Iighl lube. The UV Iighl
lhen iIIuminales a hoshor vhich gIovs vilh visibIe Iighl in a coIour
vhich deends on lhe lye of hoshor. y conslrucling a malrix of
microscoic hoshor ixeIs behind lhe vieving screen, and generaling
carefuIIy limed uIses of high voIlage lhal Iighl u seIecled hoshor
dols, il is ossibIe lo disIay a dol malrix image. y osilioning lhe ixeIs
so lhal lhey aear in grous of red, bIue and green and varying lhe
duralion and frequency of lhe eIeclric uIses lo roduce differenl IeveIs of
brighlness, il is ossibIe lo disIay brighl cris fuII coIour images.
()*+ Reader - urd, chaler 7, ages 270 (from Video DisIays)
277 (lo Irinlers)
Printers
Irinlers can be groued according lo lhe lye of lechnoIogy lhey use.
There are al Ieasl 3 common rinling melhods, imacl, Iaser and ink-|el.
FIT1001 Computer Systems
"$'
The oIdesl and mosl veII eslabIished of lhese is imacl rinling, vhich
reIies on hysicaI conlacl of lhe raised image of a characler vilh a rinl
medium, such as aer. When lhe raised image is coaled vilh ink, some
of lhe ink is Iefl behind on lhe aer in lhe shae of lhe image. IarIy
rinlers vere |usl modified eIeclric lyevrilers lhal acceled inul from a
keyboard or dala communicalions orl. Laler examIes incIuded Iine-
rinler, daisy-vheeI, and dol-malrix rinlers. The mechanicaI nalure of
lhese devices Iimiled lhe seed of oeralion and sub|ecl lo raid vear, bul
lhe big advanlage of imacl lechnoIogy is lhe abiIily lo roduce muIli-
arl forms.
Ink-|el rinlers, Iike lhe dol malrix rinler, generale lhe rinled image
using a scanned malrix of dols, excel lhal lhe dols are formed from a
slream ink droIels. The dros of ink are formed inslanlaneousIy by
eIeclromechanicaI or eIeclrolhermaI shock vaves and forced from a nozzIe
lhal direcls lhem onlo lhe aer lo form lhe malrix allern. CoIour
rinling is ossibIe by mixing inks of differenl coIours and by dilhering
lhe droIel allerns on lhe aer.
Using a malrix of dols lo conslrucl fonl images aIso aIIov lhe
conslruclion of any lye of grahic, incIuding Iines and iclures, bul
vhere an ASCII or Unicode characler couId be used lo direcl a rinler lo
generale lhe image of a fonl, a ixeI malrix grahic requires much more
dala and conlroI informalion lo be lransferred lo lhe rinler. Grahic
rinlers usuaIIy conlain rocessors lhal imIemenl an image definilion
Ianguage such as Ioslscril or ICL, and have more sohislicaled rinling
caabiIilies lhan simIe fonl rinlers. They aIso have inul conneclions
vilh high dala rales, such as a araIIeI, US or nelvork inlerfaces.
Laser rinlers offer erhas lhe besl quaIily and seed of oeralion of aII
lhe rinling lechnoIogies, bul al much higher cosl due lo lhe comIexily
and recision required. These reIy on a Iarge cyIinder coaled vilh a
maleriaI lhal relains an eIeclric charge on ils surface, caIIed a holoslalic
drum. The eIeclric change is lhen removed from seIecled arls of lhe
drum by scanning a Iaser beam across lhe surface as lhe drum rolales.
This Ieaves a slalic malrix allern lhal reresenls lhe image lo be rinled.
A seciaIIy formuIaled ovder, caIIed loner vhich consisls of
microscoic gIass or Iaslic sheres coaled vilh ink, is allracled lo lhe
charged areas on lhe drum. As lhe drum rolales, lhe loner image is
lransferred lo eIeclricaIIy charged aer. The aer lhen asses lhrough a
sel of ressure roIIers al high lemeralure, vhich fuses lhe ovdered
loner and gIues il onlo lhe surface of lhe aer. MeanvhiIe lhe drum
conlinues lo rolale and is cIeaned and recharged ready for anolher cycIe.
This is a conlinuous rocess lhal aIIovs high resoIulion images lo be
roduced on an enlire age. In coIour rinling, lhe aer moves over one
Study Guide 8: I/O Organisation and Standards
"$,
or more holoslalic drums, vilh differenl coIour loners used on each
ass.
Mosl modern rinlers are designed lo handIe A4 or Leller sized sheels of
aer, aIlhough some are equied vilh a mechanism lhal can feed
conlinuous roIIs or fan-foId aer. Devices knovn as Iollers can be
used lo rinl on Iarger formal cul-sheels or conlinuous roII and are oflen
used lo rinl engineering dravings or bIuerinls. These use one or more
ens lo drav Iines and arcs or ink-|el lechnoIogy, and use an image
definilion Ianguage such as HIGL.
()*+ Reader - urd, chaler 7, ages 277 (from Irinlers) 281 (lo
ManuaI Inul Devices)
8.8 Input Technologies
Inlering dala inlo a comuler syslem invoIves reading some kind of
medium vhere lhe dala has been reviousIy recorded. In mosl cases, lhe
dala has lo be lyed inlo a keyboard in lhe firsl Iace. This manuaI dala
enlry and doubIe-handIing of lhe source dala (once for lying and once
for reading) is a ma|or Iimilalion on lhe erformance of comuler
syslems. Il is onIy recenlIy lhal severaI lyes of direcl dala enlry
lechnoIogies such as seech recognilion, olicaI scanning and characler
recognilion have become avaiIabIe.
Keyboards based on oIder slyIe lyevriler and leIex inul devices are sliII
imorlanl forms of manuaI inul. ecause lhe keyboard used on lhe IM
IS/2 ersonaI comuler is inexensive and sliII videIy avaiIabIe, lhis has
become lhe basic keyboard inlerface used on mosl comulers, aIlhough
lhere may be rorielary and nalionaI varialions. Mosl keyboards use lhe
ancienl QWIRTY formal and have shifl, conlroI and escae keys as veII
as rovs of funclion keys and a numeric keyad. When a key is ressed or
reIeased, a scan code number corresonding lo lhe key osilion is
emilled, vhich is lhen lransIaled inlo ASCII by lhe keyboard conlroIIer
and slored in regislers in lhe keyboard inlerface. The keyboard is
connecled lo lhe inlerface using seriaI communicalions over a IS/2, US
or Iueloolh vireIess conneclion.
Mosl modern generaI urose comulers have a grahic user inlerface
vhich aIso uses some kind of oinling device, usuaIIy a mouse, vhich
aIso uses a seriaI, US or vireIess inlerface. Olher kinds of oinling
devices incIude lhe lrackbaII, louch screen, en or slyIus and digilizing
labIel. These devices conlinuousIy monilor lhe osilion of an indicalor
FIT1001 Computer Systems
"$!
and make lhis avaiIabIe via coordinale regislers in lhe conlroIIer or as a
slream of direclionaI sles. In lhe firsl case, lhe currenl osilion is
avaiIabIe as a air of binary numbers, reresenling lhe X and Y
coordinales vilhin a re-eslabIished grid. In lhe second case, movemenl
of lhe oinling device roduces a slream of ASCII characlers lhal
reresenls lhe dislance covered or lhe rale of movemenl on X and Y axes
(u-dovn and Iefl-righl). Oeraling syslem driver rograms can lhen be
used lo lransIale lhese indicaled osilions inlo movemenl of a cursor on
lhe disIay screen.
WhiIe manuaI dala enlry is sliII imorlanl, mosl effeclive aulomalion of
rocessing lasks can besl be achieved by removing lhe lranscrilion of
dala enlry. OlicaI inul devices rovide a simIe vay lo do lhis, and
incIude mark or allern sensors and image calure devices.
OlicaI mark sensors have been used on aer and cards for many years,
vhiIe bar codes are nov commonIy used. These aII reIy on using
holosensors lo delecl lhe edges in a allern of Iines rinled on aer,
and many slandards for secific uroses have been defined. Ior
examIe, mosl ackaged goods nov have UniversaI Iroducl Code bar-
codes rinled on lhem, lo aIIov lhe delaiIs of lhe ackage lo be scanned
inlo a comuler syslem. Mosl mark and barcode scanners generale ASCII
characler dala, simiIar lo a keyboard, and may require seciaI rograms lo
inlerrel lhe coded dala slream.
OlicaI scanners are used lo calure and creale a digilaI image of a
surface, vhich is effecliveIy a binary bil-ma image of lhe scanned area.
This may invoIve scanning a Iaser beam across lhe surface in a rasler
allern, and measuring lhe slrenglh of lhe refIecled Iighl, ossibIy in
severaI coIours, and buiIding a ixeI malrix image of lhe scanned area.
ecause of lhe Iarge amounl of dala generaled, olicaI scanners usuaIIy
require a high seed inlerface, such as a US, SCSI or firevire conneclion,
and aroriale image rocessing soflvare.
Images or iclures, vhiIe recognizabIe lo humans are of Iimiled use lo
currenl generalions of comuler syslems. OlicaI Characler Recognilion
soflvare is oflen used lo lransform lhe digilized image oblained from an
olicaI scanner inlo ASCII characlers or some olher form of comuler
readabIe documenl. The robIems encounlered vhiIe doing lhis are
considerabIe, and invoIve differences in Iighling, conlrasl, scaIe and
orienlalion of lhe characlers vilhin lhe scanned image. If lhe lexl is
handvrillen, conlains mixed fonls or slyIes in various coIours or has
varying orienlalion on lhe age, lhen accurale recognilion is difficuIl,
Ieading lo error rales of 10% or higher.
Study Guide 8: I/O Organisation and Standards
"$-
()*+ Reader - urd, chaler 7, ages 281 (from ManuaI Inul Devices)
289 (lo Audio I/O Devices)
Web Access
/)0 233)44 Access 567+8 97:+) ! seclion of lhe unil vebsile and
comIele Iab / luloriaI exercises.
FIT1001 Computer Systems
"%.
Study
Guide
!
Introduction to
Operating Systems
LEARNING OBJECTIVES
On comIelion of lhis sludy guide you viII be abIe lo:
exIain lhe evoIulion of modern oeraling syslems from earIy
seriaI and balch syslems lo resenl day - incIude basic
oeralions of each calegory and imorlanl deveIomenls,
discuss lhe imorlanl design faclors and consideralions
invoIved vilh oeraling syslem design,
define lhe lerms rocess and lhread,
discuss lhe four main services rovided by lhe oeraling
syslem, rocess managemenl, resource managemenl (CIU,
memory and I/O), GUI and securily / roleclion,
exIain hov rocesses and lhreads are slruclured and rocessed
by lhe CIU incIudes rocess / lhread slales and scheduIing
melhods,
exIain lhe key issues reIaled lo concurrency incIudes
deadIock, muluaI excIusion, race condilion, slarvalion and
crilicaI seclion.
FIT1001 Computer Systems
"#$
Contents
9.1 Inlroduclion
9.2 IvoIulion of Oeraling Syslems
9.3 Oeraling Syslem Design
9.4 Oeraling Syslem Services
9.5 Concurrency
Reading
Prescribed readings
NuII and Lobur, !""#$%&'(" *+ ,*-./%#0 102'$&3'%&*$ 4 5067&%#6%/0#8
Chaler 8: Syslem Soflvare
Reader: urd, 9:"%#-" 5067&%#6%/0#8
Chaler 11: Oeraling Syslems, 439-452
Reader: SlaIIings, 1.#0'%&$2 9:"%#-" ;$%#0$'(" '$< =#"&2$ >0&$6&.(#"8
Chaler 2: Oeraling Syslems Overviev, 66-81
Chaler 5: Concurrency, 203-212
Study Guide 9: Introduction to Operating Systems
"#%
9.1 Introduction
?; %7&$@ %7#0# &" ' A*0(< -'0@#% +*0 -':B# +&C# 6*-./%#0"DE
Thomas }. Walson, Chairman of IM 1949-1956
Hislory uIlimaleIy roved Thomas }. Walson vrong. As ve have
vilnessed over lhe years numerous lyes of comulers have come and
gone, eseciaIIy since 1956. TechnoIogicaI advancemenls have increased
lhe seed and comIexily of comulers vhiIe decreasing lheir hysicaI
size and cosl. Comulers nov Iay a crilicaI roIe in virluaIIy aII asecls
of modern Iife, a far cry from Thomas }. Walson quole. So far in lhis unil
ve have focused on hardvare asecls of comuler syslems bul hardvare
needs lo be conlroIIed in order for il lo funclion. The raid deveIomenl
of comuler hardvare over lhe years has araIIeIed lhe evoIulion of
modern syslem soflvare.
Syslem soflvare encomasses oeraling syslems and soflvare lhal
suorls or assisls lhe oeraling syslem. These can incIude comiIers,
rogramming Ianguages and olher uliIilies vhich viII be discussed in
Sludy Guide 12. In lhis Sludy Guide ve are concerned vilh oeraling
syslem soflvare.
As defined by Wikiedia an oeraling syslem is:
?%7# ":"%#- "*+%A'0# 0#".*$"&B(# +*0 %7# <&0#6% 6*$%0*( '$< -'$'2#-#$% *+
7'0<A'0# '$< B'"&6 ":"%#- *.#0'%&*$"D 5<<&%&*$'((:F &% .0*C&<#" ' +*/$<'%&*$
/.*$ A7&67 %* 0/$ '..(&6'%&*$ "*+%A'0# "/67 '" A*0< .0*6#""&$2 .0*20'-" '$<
A#B B0*A"#0"DE
hll://en.vikiedia.org/viki/Oeraling_syslem
&'() NuII and Lobur, chaler 8, ages 357-359 (lo 8.2.1)
9.2 Evolution of Operating Systems
The evoIulion of oeraling syslems is crilicaI lo underslanding lhe key
eIemenls and funclion of modern oeraling syslems.
Modern oeraling syslems can be lraced back lo lhe era of mainframe
comuling. IniliaIIy allemls lo make lhe seriaI rocessing more
aulomaled by balching simiIar |obs / rograms (lhose usuaIIy vrillen in
FIT1001 Computer Systems
"##
lhe same comuler Ianguage) and inlroducing monilors, simIe soflvare
lo conlroI lhe execulion of |obs, imroved lhe efficiency and uliIizalion of
lhese syslems. To rovide beller roleclion and efficiency, limers, syslem
caIIs / inlerruls, monilor mode and user mode vere inlroduced inlo
balch syslems. MuIlirogramming / muIlilasking syslems aIIoved
muIliIe rograms lo reside in memory concurrenlIy and each uliIise lhe
rocessor in smaII orlions unliI lhe rogram vas comIeled. The
concel of muIlirogramming vas adaled lo ermil lhe rocessor lo
handIe muIliIe user rograms. These lime sharing syslems ermilled
muIliIe users simuIlaneous access lo lhe syslem and lhe oeraling
syslem rovided smaII lime sIices / quanlum of rocessor lime for each
user.
&'() NuII and Lobur, chaler 8, ages 359 (from 8.2.1) 362 (lo
ReaI-lime, MuIlirocessor, and Dislribuled/Nelvorked
Syslems)
Batch and Multiprogramming An Example
The concel of muIlirogramming is a core concel of modern oeraling
syslems. The foIIoving examIe is summarised from SlaIIings, age 60-
61.
Consider a comuler vilh 250M of memory (nol used by lhe oeraling
syslem), a disk, lerminaI (monilor) and a rinler. Three |obs, }O1, }O2
and }O3 are submilled for rocessing al lhe same lime. Iach |ob has lhe
foIIoving allribules:
}O1 }O2 }O3
Tye of |ob Heavy CIU Heavy I/O Heavy I/O
Duralion 5 min 15 min 10 min
Memory required 50 M 100 M 75 M
Need disk` No No Yes
Need lerminaI` No Yes No
Need rinler` No No Yes
Study Guide 9: Introduction to Operating Systems
"#*
Irom lhe allribules ve can assume lhal }O2 and }O3 viII require
minimaI rocessor requiremenls and }O3 viII require conlinuous disk
and rinl use.
Ior a balch syslem lhese |obs viII be execuled in sequence, }O1 viII lake
5 minules, }O2 musl vail lhe 5 minules and comIeles 15 minules afler
lhal. So }O3 does nol slarl for 20 minules, and comIeles 30 minules
afler il vas submilled. So lhe rocessor use overaII is 20%, memory use is
33%, disk use is 33% rinler use is 33%, eIased lime 30 minules,
lhroughul is 6 |obs er hour and mean resonse lime is 18 minules.
In a muIlirogramming syslem aII lhree |obs are finished vilhin 15
minules. As lhere is IillIe comelilion for resources, and }O2 and }O3
are rovided vilh enough rocessor lime lo kee lheir inul and oulul
oeralions aclive, aII lhree |obs can coexisl and execule. }O1 viII sliII
require 5 minules, bul }O2 viII be one lhird finished and }O3 haIf
finished. So lhe rocessor use overaII is 40%, memory use is 67%, disk
use is 67% rinler use is 67%, eIased lime 25 minules, lhroughul is 12
|obs er hour and mean resonse lime is 10 minules.
So lhe benefils of muIlirogramming are fairIy evidenl. These lyes of
syslems reIy on cerlain hardvare fealures such as I/O inlerruls and DMA
(direcl memory access).
Time Sharing An Example
To undersland lhe basic idea of lime sharing ve viII Iook al one of lhe
firsl syslems deveIoed for lime sharing, lhe CTSS (ComalibIe Time
Sharing Syslem). CTSS vas deveIoed al MIT and inlroduced vilh lhe
IM 709 in 1961 (and evenluaIIy couId suorl a maximum of 32 users).
WhiIe CTSS is rimilive comared lo modern lime sharing syslems il is a
good Iace lo begin. The foIIoving examIe is summarised from
SlaIIings, age 64-65.
CTSS ran on a syslem vilh 32,000 vords of main memory vilh lhe
residenl monilor using lhe firsl 5000. The remaining 27,000 vords vere
aIIocaled for user usage. A user's rogram and dala vas aIvays Ioaded
inlo lhe 5000
lh
vord. A syslem cIock generaled an inlerrul aboul every
0.2 seconds, vhich aIIoved lhe oeraling syslem lo regain conlroI of lhe
rocessor. This aIIoved differenl users access lhe rocessor. To save lhe
revious user's dala for Ialer resumlion orlions of lhe dala (or aII lhe
dala) vas vrillen lo disk before nev rograms and dala vas Ioaded.
When lhe oId user is aIIocaled rocessor lime again lhe saved dala is
Ioaded back. To avoid heavy disk lraffic lhe memory vas onIy saved
vhen lhe incoming rogram vouId overvrile il, so lhe orlion of
FIT1001 Computer Systems
"#+
memory nol vrillen by lhe nev rogram vas sliII heId in memory. This
ermilled quicker reslore lime for a revious user. Of course if lhe nev
rogram vas Iarger lhan lhe revious user lhe syslem vouId save aII lhe
memory aIIocaled lhe revious user.
Other Types of Modern Operating Systems
WhiIe ve see muIlirogramming /muIlilasking and lime sharing
emIoyed on many Ialforms loday lhe iniliaI oeraling syslems for
ersonaI comulers had neilher. These lyes of oeraling syslems vere
onIy caabIe of running one aIicalion al lime and couId onIy suorl
one user al a lime. These syslems can be described as singIe user/singIe
lask syslems or unirogramming syslems. IvenluaIIy, due lo lhe increase
in comuling over and lhe demand for beller erformance, lhese
oeraling syslems (and never ones) incororaled many of lhe fealures
avaiIabIe in mainframe and minicomuler oeraling syslems.
One melhod emIoyed in recenl years lo increase lhe rocessing abiIily of
syslems is lo use muIliIe rocessors in lhe same syslem symmelric
muIlirocessing. This rovides addilionaI chaIIenges lo lhe oeraling
syslem in lerms of I/O requesls, scheduIing and synchronisalion of
rocesses. MuIlirocessor oeraling syslems have lo be designed lo
recognise and uliIise such rocessor configuralions.
Wilh lhe increasing use and reIiance on nelvork conneclivily, and lhe
need lo manage and conlroI crilicaI equimenl, lhe need for reaI-lime and
dislribuled / nelvorked oeraling syslems is evidenl. ReaI-lime syslems
need lo riorilise and comIele lasks by cerlain deadIines (vilhoul faiI)
olhervise hysicaI damage or Ioss of Iife may occur. Dislribuled /
nelvorked syslems rovide addilionaI issues as lhe oeraling syslem has
lo conlroI a number of comulers syslems lo erform lasks, making I/O,
rocess synchronisalion and scheduIing a chaIIenge.
&'() NuII and Lobur, chaler 8, ages 362 (from ReaI-lime,
MuIlirocessor, and Dislribuled/Nelvorked
Syslems) 364 (lo 8.2.2)
&'() Reader - SlaIIings, chaler 2, ages 56 (from 2.2) 66 (lo 2.3)
Study Guide 9: Introduction to Operating Systems
"#,
9.3 Operating System Design
Modern oeraling syslems are much more comIex lhan lheir earIier
incarnalions and cousins. Desile commonIy knovn oeraling syslems
Iike Windovs, MacOS, UNIX and Linux lhere are many olher oeraling
syslems avaiIabIe. These oeraling syslems may have simiIar inlerfaces
and erform lasks in a simiIar manner bul vary in lheir design and
imIemenlalion. Il is fair lo say lhal no lvo oeraling syslems are
idenlicaI. Il is aIso fair lo say lhal no one oeraling syslem is suerior in
aII resecls.
The key lo oeraling syslem design in lhe core funclions rovided by lhe
oeraling syslem, lhis is knovn as lhe kerneI. There are lvo aroaches
in kerneI design: microkerneI and monoIilhic. Designers of oeraling
syslems have lo consider a number of imorlanl issues:
KerneI archileclure
Irocess / lhread managemenl
Memory managemenl
Informalion roleclion and securily
ScheduIing and resource managemenl
Syslem slruclure
&'() NuII and Lobur, chaler 8, ages 364 (from 8.2.2) 366 (8.2.3)
&'() Reader - SlaIIings, chaler 2, ages 66 (from 2.3) 81 (lo 2.5)
9.4 Operating System Services
Irom lhe receding seclion you shouId undersland and areciale lhe
chaIIenges faced by oeraling syslem designers. An oeraling shouId
rovide lhe core services of rocess managemenl, memory managemenl,
I/O managemenl, securily and roleclion (lo ensure lhe syslem vorks
efficienlIy).
In lhis seclion ve viII focus more on rocess (and lherefore lhread)
managemenl as rocesses are lhe core eIemenl of modern oeraling
FIT1001 Computer Systems
"#-
syslems. We viII cover lheir basic slruclure and hov lhe oeraling
syslem manages lhe rocesses lhrough lhe rocessor.
&'() NuII and Lobur, chaler 8, ages 366 (from 8.2.3) 378 (8.4)
&'() Reader - urd, chaler 11, ages 439 (from Irocess
Managemenl) 452 (lo usiness Iocus)
9.5 Concurrency
You shouId recaII from SlaIIings (Reader) lhe issues in regards lo rocess
coordinalion, and from urd (Reader) hov lhe oeraling syslem manages
lhe rocessor, aIIocales resources and conlroIs rocesses.
Concurrency as SlaIIing vriles is concerned vilh lhe issues of
?6*--/$&6'%&*$ '-*$2 .0*6#""#"F "7'0&$2 '$< 6*-.#%&$2 +*0 0#"*/06#"F
":$670*$&"'%&*$ *+ %7# '6%&C&%&#" *+ -/(%&.(# .0*6#""#" '$< %7# '((*6'%&*$ *+
.0*6#""*0 %&-# %* .0*6#""#"DE
In lhis seclion ve viII Iook al lhe basic rinciIes of concurrency (as il
reIales lo inlerrocess communicalions), consideralions for lhe oeraling
syslem and some examIes of muluaI excIusion, race condilion, deadIock,
slarvalion and lhe use of crilicaI seclions.
&'() Reader - SlaIIings, chaler 5, ages 203 - 212 (lo 5.2)
Web Access
.'/ 122'33 Access 456)7 869)' ! seclion of lhe unil vebsile and
comIele Iab / luloriaI exercises.
Study
Guide
!"
File Systems
Features and Formats
LEARNING OBJECTIVES
On comIelion of lhis sludy guide you viII be abIe lo:
exIain lhe concels and urose of fiIes and direclories in a
fiIe syslem,
discuss various fiIe naming reslriclions imosed by common
fiIe syslems,
undersland sequenliaI, direcl and indexed fiIe access melhods,
exIain lhe concel and funclion of voIumes / arlilions in a fiIe
syslem,
discuss lhe various allribules slored in reference lo fiIes,
direclories and voIumes / arlilions,
define lhe lerms currenl / vorking direclory, absoIule and
reIalive alhs,
discuss fiIe access conlroI melhods,
exIain aIIocalion melhods conliguous, Iinked and indexed,
exIain hov free sace is managed in a fiIe syslem,
exIain and iIIuslrale raclicaI imIemenlalions of modern fiIe
syslem, IAT16/32, NTIS, UIS/IxlIS and ISO 9660.
FIT1001 Computer Systems
!#"
Contents
10.1 Inlroduclion
10.2 IiIe Syslem asics
10.3 ImIemenling IiIe Syslems
10.4 IiIe Syslem IxamIes
Reading
Prescribed readings
Reader: SiIberschalz, GaIvin and Gange, !"#$%&'() +,-&#. /0(1#"&-2
Chaler 10: IiIe-Syslem Inlerface, 373-397/402-407
Chaler 11: IiIe- Syslem ImIemenlalion, 411-431
Reader: IaImer, WaIlers, adgell and }onker, 34'5# &0 !"#$%&'() +,-&#.-:
Chaler 4: IiIe Syslems, 105-140
Reader: Tanenbaum, 605#$( !"#$%&'() +,-&#.-2
Chaler 6: IiIe Syslems, 430-435
Study Guide 10: File System Features and Formats
!#!
10.1 Introduction
As ve have seen in Sludy Guide 9 lhe oeraling syslem lransfers required
rograms and dala from secondary slorage devices, such as hard disks,
CD/DVD, laes lo memory for lhe rocessor lo execule. GeneraIIy lhe
oulul is saved back lo lhese devices for furlher maniuIalion or generaI
slorage. These rogram and dala fiIes are imorlanl resources as syslem
and aIicalion soflvare are comrised of fiIes. The lask of crealing,
managing and maniuIaling fiIes vilhin a oeraling syslems is erformed
by lhe IiIe Syslem.
SlaIIings defines a fiIe managemenl syslem as:
78 9':# .%(%)#.#(& -,-&#. '- &;%& -#& 09 -,-&#. -09&<%$# &;%& "$0='5#- -#$='1#- &0
4-#$- %(5 %"":'1%&'0(- '( &;# 4-# 09 9':#-> ?,"'1%::,@ &;# 0(:, <%, &;%& % 4-#$ 0$
%"":'1%&'0( .%, %11#-- 9':#- '- &;$04); &;# 9':# .%(%)#.#(& -,-&#.> ?;'- $#:'#=#-
&;# 4-#$ 0$ "$0)$%..#$ 09 &;# (#1#--'&, 09 5#=#:0"'() -"#1'%:A"4$"0-# -09&<%$# 90$
#%1; %"":'1%&'0( %(5 "$0='5#- &;# -,-&#. <'&; % 10(-'-&#(&@ <#::A5#9'(#5 .#%(- 09
10(&$0::'() '&- .0-& '."0$&%(& %--#&>B
SlaIIings aIso indicales a number of ob|eclives for a fiIe syslem:
To meel lhe dala managemenl needs and requiremenls of lhe user,
vhich incIude slorage of dala and lhe abiIily lo a slandard sel of
oeralions
To guaranlee, lo lhe exlenl ossibIe, lhal dala in lhe fiIe are vaIid
To olimise erformance, bolh from lhe syslem oinl of viev in
lerms of overaII lhroughul and from lhe user's oinl of viev in
lerms of resonse lime
To rovide I/O suorl for a variely of slorage device lyes
To minimise or eIiminale lhe olenliaI for Iosl or deslroyed dala
To rovide a slandardised sel of I/O inlerface roulines lo use
rocesses
To rovide I/O suorl for muIliIe users, in lhe case of muIliIe-
user syslems
SlaIIings,
Oeraling Syslems InlernaIs and Design IrinciIes (538-539)
FIT1001 Computer Systems
!#$
IaImer, WaIlers, adgell and }onker indicale lhe generaI lasks for a fiIe
syslem:
Iarlilion and formal disks lo slore and relrieve informalion
InabIe fiIes lo be organised lhrough direclories and foIders
IslabIish fiIe naming convenlions
Irovide uliIilies lo mainlain and manage lhe fiIe syslem and
slorage media
Irovide for fiIe and dala inlegrily
InabIe error recovery or revenlion
Secure lhe informalion in fiIes
IaImer, WaIlers, adgell and }onker
Guide lo Oeraling Syslems (106)
10.2 File System Basics
There are many lyes of fiIe syslems rovided vilh oeraling syslems,
and modern oeraling syslems can suorl various fiIe syslems.
A crilicaI funclion of lhe fiIe syslem is lhe abiIily lo lransIale lhe hysicaI
slorage of bils inlo a more IogicaI viev for users. This IogicaI viev can be
seen as a coIIeclion of fiIes and direclories via a number of uliIilies
rovided by lhe oeraling syslem. The hysicaI slorage viev is
concerned vilh hov lhe dala is slored, maniuIaled and accessed,
funclions lhal lhe user does nol reaIIy vanl lo knov aboul, or care.
In lhis seclion ve viII cover lhe basic concels lhal aIy lo mosl modern
fiIe syslems.
Files
IiIes are imorlanl as lhey rovide a vay lo slore and relrieve
informalion on slorage devices. IiIes are lhe virluaI viev of vhal is
acluaIIy slored on lhese devices. IiIes mask lhe user from lhe
mechanisms of hov and vhere informalion is slored and hov lhe slorage
devices acluaIIy vork. When a user issues a save or oen command for
an aIicalion or dala fiIe, vhelher il be via a mouse cIick or a command
Iine, lhey are nol concerned vilh lhe hysicaI Iocalion, lhe lye of slorage
Study Guide 10: File System Features and Formats
!#%
media or hov lhe fiIe syslem carries oul lhe command, lhey |usl vanl lhe
fiIe oened or saved. This is akin lo slarling a car, a driver is nol
concerned vilh hov lhe car slarls, bul |usl as Iong as il does. A fiIe
syslem musl suorl common fiIe oeralions incIuding reading, crealing,
vriling, deIeling, aending and lruncaling a fiIe, as veII as kee lrack of
oen fiIes.
IiIes can reresenl bolh rogram and dala fiIes as binary and lexl
(commonIy in ASCII formal). Texl fiIes consisl of |usl lhal, lexl vhich can
be read as easiIy as lhis book. The advanlage of lexl fiIes in lhal lhey can
be rinled or ediled vilh simIe lexl edilors. The image beIov is a lexl
fiIe disIayed in a common lexl edilor:
inary fiIes conlain informalion in binary formal, readabIe by lhe
aIicalion or oeraling syslem onIy. In a lexl edilor lhe conlenls of a
binary fiIe aears as random characler |unk, incomrehensibIe lo lhe
human mind. GeneraIIy you viII find syslem soflvare fiIes, rogram
aIicalions and some dala fiIes (such as vord and sreadsheel
documenls) slored in binary fiIes. Over lhe age is a orlion of lhe same
senlence from a Microsofl Word saved documenl disIayed in a common
lexl edilor.
FIT1001 Computer Systems
!#&
The names aIIocaled lo fiIes are very much deendenl on lhe fiIe naming
convenlion emIoyed by lhe oeraling syslem. Some characlers and
vords are reserved by lhe oeraling syslems so lhey cannol be used in a
fiIe name. A fiIe name has lvo seclions, a fiIename and an exlension. The
exlension is an idenlifier receded by a eriod so lhe fiIe 2005-summer.lxl
has an exlension of lxl, vhich is commonIy designaled as a lexl fiIe. This
exlension reIales lo lhe fiIe formal, vhich is hov lhe dala is arranged in
lhe fiIe ilseIf. Ior examIe, a Microsofl Word fiIe viII have a differenl
inlernaI slruclure lo a Microsofl IxceI fiIe, and bolh vouId differ lo an
execulabIe fiIe mainIy designaled vilh an .exe exlension. Of course lhe
receding examIe aII reIale lo binary lye fiIes. The acluaI fiIename
shouId have some meaning for fulure reference. IiIe syslems aIso reslricl
lhe size of lhe fiIename and exlension. Ior inslance DOS (Disk Oeraling
Syslem) has a reslriclion of 8 characlers for lhe fiIename and 3 for lhe
exlension, vhich makes roviding a meaningfuI name difficuIl. Hovever
currenl oeraling syslems rovide u lo 256 characlers for lhe fiIename
and exlension, vilh lhe exlension of any Ienglh ermilled.
The slruclure of a fiIe is delermined and suorled by lhe oeraling
syslem or lhe aIicalions using lhem. In lhe case of aIicalions il is lhe
aIicalion lhal defines lhe slruclure of il's' dala fiIes, nol lhe oeraling
syslem. If lhe aIicalion is missing lhe oeraling syslem is nol abIe lo
oen or undersland lhe conlenl of lhal fiIe. RegardIess of lhe fiIe
slruclure aII fiIes are recorded on slorage devices in a sequence of byles.
A fiIe can be accessed in lhree common vays:
SequenliaI
Direcl access
Indexed
Directories
A fiIe direclory conlains informalion aboul lhe fiIes, allribules, Iocalion
and ovnershi. The direclory ilseIf is a fiIe vhich can be accessed by
various fiIe managemenls rograms, vhich generaIIy suIy informalion
lo users and aIicalions. The informalion recorded in lhe direclory is
deendenl on lhe fiIe syslem. The lyes of informalion lhal couId be
slored are:
asic fiIe names, fiIe lye, fiIe slruclure
Address voIume Iocalion, slarling address, size used, size
aIIocaled
Study Guide 10: File System Features and Formats
!##
Access conlroI ovner, access ermissions, ermilled aclions
Usage dale crealed, idenlily of crealor, dale Iasl modified
Some of lhe informalion can aIso be slored vilh lhe fiIe bul lhis is
deendenl on lhe fiIe syslem ilseIf.
Some earIy singIe user syslems emIoyed a simIe Iisl vilh each fiIe
having an enlry. This roved inadequale for muIli-user syslems, and even
singIe user syslems vilh many fiIes, as lhe simIe Iisl couId nol suorl
lhe concel of subdireclories. The imIemenlalion of lhe lvo-IeveI
scheme soIved lhe iniliaI robIem for muIli-users syslems as each user
vas designaled a direclory, vilh lhe masler / rool direclory having enlries
for each user direclory. WhiIe lhis assisled access reslriclion il enforced
lhe requiremenl for aII fiIe names lo be unique and did nol rovide any
melhod for slrucluring a coIIeclion of fiIes. The hierarchicaI direclory
slruclure, or lree slruclure, aIIovs as many direclories as needed lo be
crealed under lhe masler / rool direclory, and lhose subdireclories can
have addilionaI subdireclories. A varialion of lhis is lhe Grah Direclory
Slruclure, vhich aIIovs fiIes and subdireclories lo be conlained vilhin
muIliIe direclories bul refer back lo lhe originaI Iocalion. Ior examIe,
lvo rogrammers can see and access lhe same rogram source direclory
from lheir ovn direclories.
Volumes / Partitions
TyicaIIy a comuler syslem viII have a number of secondary slorage
devices vhich are fixed (eg. hard disks) or removabIe (eg. CD/DVD, US,
IireWire elc). HisloricaIIy hard disks conlained onIy a singIe voIume bul
vilh lhe increasing size of had disks and fiIe syslem imrovemenls, lhey
can be sIil in a number of voIumes, or arlilions. Iach voIume is
assigned secific informalion such as, voIume name, fiIe syslem lye, fiIe
and direclory oinlers. So in order lo creale a fiIe syslem on a hard disk il
musl be formalled lo accommodale lhe fiIe syslem used by lhe oeraling
syslem. Iormalling lhe hard disk aIso rovides lhe abiIily for lhe
oeraling syslems lo bool of lhal device.
'()* Reader SiIberschalz, GaIvin and Gange, chaler 10,
ages 373 - 397 (lo 10.5)
FIT1001 Computer Systems
!#+
File Access and Control
In modern oeraling syslems, vilh lheir muIliIe user and fiIe sharing
caabiIilies, lhe issue fiIe roleclion and access is a crilicaI faclor.
GeneraIIy fiIes can be conlroIIed by lhe lye of access requesled. On a fiIe
lhis can be read, vrile, execule, aend, deIele and Iisl. Hovever access
conlroI lakes lhis one sle furlher by conlroIIing access by user. One
melhod is lhe Access ConlroI Malrix, vhich creales an access Iisl
indicaling users and lheir lye of access. Hovever lhis becomes difficuIl
lo manage as users and fiIes increase. The mosl common melhod is lhe
Access ConlroI Lisl (ACL), vhich combines lhe access conlroI malrix vilh
lhree cIassificalions of users, ovner, grou and universe / vorId. Iach
cIassificalion is assigned arlicuIar access righls. Is a user is nol lhe
ovner or in a grou lhey are denied access lo lhe fiIe. This aroach aIso
aIies lo direclories. Olher melhods incIude CaabiIily Lisls and
Lockvords.
'()* Reader SiIberschalz, GaIvin and Gange, chaler 10,
ages 402 (from 10.6) - 407 (lo 10.7)
10.3 Implementing File Systems
A fiIe syslem is comosed of many differenl Iayers. When you lhink lhal
a fiIe syslem has lo rovide a virluaI viev lo users, and slore lhe fiIes
hysicaIIy lo a slorage device, lhe number of lasks required is quile
comIex, hence a Iayered aroach heIs simIify imIemenlalion and
suorl various fiIe syslems vilhoul duIicaling cerlain funclions.
The concel of bIock aIIocalion is used in many modern oeraling
syslems lo slruclure hard disks, lhe rimary slorage device inslaIIed in
nearIy aII comuler syslems. The basis of bIock aIIocalion is lhe aIIocalion
unil, lhe smaIIesl number of byles lhal can be aIIocaled lo a fiIe. This is a
IogicaI division vilh each bIock referring lo arlicuIar seclors, heads and
lracks on a hard disk. GeneraIIy lhese are 512 byles bul can vary
deending on lhe fiIe syslem.
The imIemenlalion of a fiIe syslem suorls lhe oeraling syslem and
requires bolh on disk and memory slruclures lo funclion correclIy and
efficienlIy. GeneraIIy lhese slruclures can incIude:
On disk:
o A bool conlroI bIock
Study Guide 10: File System Features and Formats
!#,
o Iarlilion conlroI bIock
o Direclory slruclure
o IiIe conlroI bIock
Memory
o In-memory arlilion labIe
o In-memory direclory slruclure
o Syslem vide oen fiIe labIe
o Ier rocess oen fiIe labIe
Direclory imIemenlalion is an imorlanl faclor lo erformance and
reIiabiIily. Tvo common melhods are Iinear Iisl and has labIe.
Allocation Methods
AIIocaling sace lo fiIes is anolher imorlanl consideralion. There are
lhree ma|or melhods of disk sace aIIocalion:
Conliguous
Linked
Indexed
Iach melhod has advanlages and disadvanlages in imIemenlalion and
erformance.
Free Space Management
RecIaiming free sace is done via mainlaining a free-sace Iisl. The free
sace Iisl mainlains a Iisl of unaIIocaled / free bIock. There are a number
of common melhods used lo mainlain a free-sace Iisl:
il veclor / bil ma
Linked Iisl
Grouing
Counling
FIT1001 Computer Systems
!#-
'()* Reader SiIberschalz, GaIvin and Gange, chaler 11,
ages 411 - 431 (lo 11.6)
10.4 File System Examples
In lhis seclion ve viII exIore acluaI imIemenlalions of fiIes syslems lo
see hov lhe lheorelicaI eIemenls discussed in revious seclions aIy.
The ma|or fiIe syslems lhal are covered are:
IAT16/32 used in DOS and various Windovs varianls
NTIS used rimariIy in Windovs NT3.1 / NT4 / 2000 / XI /
Server 2003
UIS / IxlIS used rimariIy in UNIX syslems / a modified version
of UIS used in Linux based syslems
ISO9660 (vilh Rock Ridge / }oIiel exlensions) used vilh CD
lechnoIogy
'()* Reader - IaImer, WaIlers, adgell and }onker, chaler 4,
ages 116 (from Windovs 2000/XI/Server 2003 IiIe Syslems)
- 140 (lo The NelWare IiIe Syslem)
'()* Reader Tanenbaum, chaler 6, ages 430 (6.4.1) lo 435 (lo
6.4.2)
Web Access
.(/ 122(33 Access 456*7 869*( !" seclion of lhe unil vebsile and
comIele Iab / luloriaI exercises.
Study
Guide
!!
User Interfaces
LEARNING OBJECTIVES
On comIelion of lhis sludy guide you viII be abIe lo:
exIain lhe concel of user inlerfaces,
discuss user inlerface imIemenlalion in lerms of a Iayered
aroach,
exIain use inlerface imIemenlalion in lerms of command,
menu and evenl driven environmenls,
discuss hisloricaI deveIomenls and design issues of MS DOS,
MS Windovs and UNIX / Linux in reIalion lo user inlerface
design and imIemenlalion,
exIain lhe concel of sheIIs and lheir exislence in modern
oeraling syslems,
exIain hov lhe command Iine in a sheII is rocessed,
demonslrale and differenliale belveen basic CLI commands
under MS DOS / Windovs and UNIX / Linux,
demonslrale lhe abiIily lo creale and execule a basic scril,
demonslrale lhe abiIily lo modify alhs via CLI and GUI
inlerfaces.
FIT1001 Computer Systems
!"#
Contents
11.1 Inlroduclion lo User Inlerfaces
11.2 Melhods of imIemenling user inlerfaces
11.3 MS-DOS, MS Windovs and UNIX/Linux User Inlerfaces
11.4 Windovs, UNIX and Linux SheII Irogramming asics
Reading
Prescribed readings
Reader: Davis and Ra|kumar, !"#$%&'() +,-&#.- / 0 +,-&#.%&'1 0""$2%134
Chaler 5: The User Inlerface, lhe IiIe Syslem, and lhe
IOCS, 95-102
Reader: IIynn and McHoes, 5(6#$-&%(6'() !"#$%&'() +,-&#.-4
Chaler 13: MS-DOS Oeraling Syslems, 400-404 / 416-
422
Chaler 14: Windovs Oeraling Syslems, 426-432 / 451-
457
Chaler 15: UNIX and Linux Oeraling Syslems
462-469 / 487-494
Reader: Iord, 7'(628- +3#99 +1$'"&'() %(6 7+:4
Chaler 2: Overviev of SheII Scriling and WSH, 23-42
Chaler 5: Working vilh VariabIes, 89-106
Reader: SobeII: 0 ;$%1&'1%9 <='6# &2 >'(=?4
Chaler 5: The SheII, 107-132
Chaler 8: The ourne Again SheII, 255-274, 284-285
Study Guide 11: User Interfaces
!"!
11.1 Introduction to User Interfaces
Hov a user inleracls vilh lhe oeraling syslems is a crilicaI design issue.
The urose of any user inlerface is lo rocess requesls from lhe user.
Once lhe user has requesled a lask lhe oeraling syslem inlerrels and
execules lhe requesl. Modern oeraling syslems imIemenl lhe user
inlerface as a arlicuIar individuaI Iayer, in much lhe same vay as fiIe
syslems. Using lhis Iayer aroach aIIovs lhe oeraling syslem lo
suorl muIliIe user inlerfaces.
HisloricaIIy lhe user vas reslricled lo vhal is referred lo as a command
Iine inlerface (CLI) or command inlerreler. In a CLI lhe users had lo
lye in commands / inslruclions in order for lhe oeraling syslem lo
execule any rogram. Some oeraling syslems incIude lhe CLI as arl of
lhe kerneI, olhers lreal lhe CLI as a seciaI rogram vhich is execuled
vhen lhe syslem slarls or lhe user Iogs in. A CLI can suorl a number
commands vhich in generaI covers fiIe maniuIalion such as creale,
deIele, Iisl, execule elc. There are lvo main aroaches for imIemenling
CLIs. One is lo embed aII lhe code required lo erform lhe oeralion
vilhin lhe CLI, an examIe of lhis is DOS. The olher aroach is lo
suIy searale rograms for each command. The CLI onIy idenlifies lhe
command and Ioads lhe aroriale fiIe for execulion. IxamIes of lhis
aroach can be seen in UNIX and Linux. Some oeraling syslems, such
as UNIX and Linux syslems, offer muIliIe CLIs, lhese are commonIy
referred lo as sheIIs.
The deveIomenl of fasler machines sav lhe inlroduclion of lhe grahicaI
user inlerface (GUI). A GUI rovides a desklo (a grahicaI screen viev)
vhere an inul devices' oinler (generaIIy a mouse or olher oinling
device) is moved inlo osilion over an icon, or image. This icon can
reresenl rograms, fiIes, direclories or syslem funclions. SeIecling lhe
icon, be generaIIy cIicking lhe mouse, can invoke lhe rogram, disIay lhe
fiIe or direclory or disIay menus (vhich conlain commands lo seIecl).
11.2 Methods of implementing User
Interfaces
Command Line Inlerrelers or sheIIs can be conslrucled using a rogram
conlaining a sequence of slages lhal reeal in a conlinuous Ioo Iike lhal
shovn beIov:
1. Wrile a roml lo lhe oulul device
2. Read a Iine of lexl from lhe inul device
FIT1001 Computer Systems
!"$
3. AnaIyse lhe lexl as a command, idenlifying and searaling lhe
various arls. TyicaIIy, lhe firsl vord is a command or fiIename
and subsequenl vords are aramelers lhal are use by lhe
command in some vay
4. Ixecule lhe command, assing lhe aramelers so lhal lhey are
avaiIabIe lo lhe command during ils execulion
5. Reeal lhe above unliI some end condilion (eg Ind of Inul)
occurs.
This simIe rocedure is lhe basis of mosl command driven
environmenls. UsuaIIy, lhe inul is lhe keyboard and lhe oulul is lhe
screen of a video disIay unil, bul lhis aIso vorks if lhe inul and oulul
are lexl fiIes, or lexl boxes in a Grahic User Inlerface (described in more
delaiI beIov). The inul of commands from fiIes, logelher vilh command
Iine synlax aIIoving reIacemenl of aramelers vilh inul variabIes,
makes il ossibIe lo vrile rogrammabIe sequences of commands knovn
as balch fiIes or scrils. These are described in seclion 4 beIov.
One imorlanl oinl aboul CLIs is lhal lhey are imIicilIy synchronous,
lhe commands are onIy execuled one al a lime as each Iine of lexl is read
from lhe inul device. So lhe sequence and liming of execulion is
delermined in advance by lhe user, and lhe nexl command is onIy slarled
afler lhe revious command has comIeled. Some CLIs and sheIIs have
lhe abiIily lo slarl commands and lhen roml immedialeIy for anolher
command, even before lhe currenl command has finished. Commands
execuled in lhis vay are said lo be running in lhe background or
running in delached mode, as lhe inul and oulul devices may be
disconnecled from lhe running command and conlinue lo be used by lhe
CLI rogram. This fealure oflen makes use of lhe muIli-rogramming and
fiIe sharing fealures of lhe oeraling syslem, by arranging so lhal lhe CLI
and command rograms run in searale bul concurrenl rocesses.
ackground execulion inlroduces a Iimiled kind of asynchronous or
araIIeI execulion of commands, for examIe, a user may lhen be abIe lo
execule Ienglhy non-inleraclive commands in lhe background, vhiIe
conlinuing lo run olher inleraclive commands.
IarIy comuling environmenls rovided onIy a command Iine inlerface,
and users vere required lo knov lhe commands needed, for examIe, lo
slarl a arlicuIar aIicalion rogramming syslem, and had lo lye lhem
in. A refinemenl on lhis sorl of user inlerface is lhe idea of a menu. A
menu is a disIayed Iisl of choices, from vhich lhe user makes a seIeclion,
usuaIIy by lying in lhe number of lhe desired choice. ul lhis is sliII a
singIe-user, synchronous inlerface, aIlhough some menu choices mighl be
running in lhe background.
Study Guide 11: User Interfaces
!"%
GrahicaI User Inlerfaces require much grealer IeveIs of asynchronous
aclivily, since lhe user inul is deIivered by a number of inul devices as
veII as lhe keyboard, and is associaled vilh lhe currenl osilion of a
cursor on lhe screen, ralher lhan lhe synlax of a lexl command. This is a
quile differenl lye of inlerface and needs lo be abIe lo monilor and reacl
lo severaI inuls al lhe same lime. Ralher lhan a conlroI rogram lhal
reacls lo lhe arrivaI of a Iine of lexl, a GUI conlroI rogram musl reacl lo
one or more inuls concurrenlIy and in any sequence. The soIulion is lo
define lhe many ossibIe inuls as evenls and lo slore informalion
aboul lhese evenls in a firsl-in-firsl-oul queue immedialeIy vhen each
evenl occurs (erhas as arl of a device inlerrul service rouline). The
conlroI rogram can be imIemenled as a disalch Ioo vhich exlracls
evenls from lhe queue one al a lime and asses lhem lo evenl handIers for
rocessing. This is knovn as an Ivenl Driven Irogram.
Ivenl driven rogramming is a rogramming aradigm. A rogramming
aradigm refers lo lhe vay of conceluaIising and slrucluring lhe lasks of
a comuler syslem. Olher common aradigms incIude roceduraI, ob|ecl
orienled and decIaralive. The evenl driven aradigm focuses on seIecling
user inlerface eIemenls and defining evenl handIing roulines. The
roulines are lhen lriggered by various hardvare aclivilies such as a mouse
cIick or keyboard inul. GUIs, by lheir nalure, are generaIIy rogrammed
in an evenl driven aradigm.
There are lhree generaI sles in designing an evenl driven GUI:
Ivenl handIers a sel of rograms or roulines (smaII seclions of
rogramming code) is crealed lo resond lo a requesl
FIT1001 Computer Systems
!"&
inding evenl handIers ensures lhal lhe evenl handIer is Iinked
lo lhe aroriale evenl
Ivenl Disalcher - monilors resources consislenlIy for changes, if a
change in lhe resource aears, such as a nev fiIe in a foIder, a
keyboard or mouse requesl, a lrigger evenl (an evenl handIer) is
caIIed lo rocess il
'()* Reader Davis and Ra|kumar, chaler 5, ages 95 102
(lo The IiIe Syslem)
11.3 MS-DOS, MS Windows and
UNIX/Linux User Interfaces
In order lo undersland lhe evoIulion of arlicuIar user inlerfaces, and
hov lhey funclion under various oeraling syslems, ve need lo firsl Iook
al lhe origins and design goaIs of lhe associaled oeraling syslems. The
design goaIs, vhelher lhe syslem be singIe or muIli-user, have a CLI or
GUI, suorl muIliIe inlerfaces and so on Iays an imorlanl arl in
deveIoing a user inlerface. The era in vhich lhe user inlerface vas
deveIoed is aIso a faclor, and infIuences lhe design goaIs. In lhis seclion
ve viII briefIy Iook al four ma|or oeraling syslems, lheir origins, basic
design goaIs and user inlerfaces.
Iarl of lhis reading shouId aIso reinforce some of lhe loics discussed in
earIier Sludy Guides and ul lhem in conlexl.
'()* Reader IIynn and McHoes, chaler 13, 400 - 404 (lo Memory
Managemenl), 416 (from User Inlerface) 422 (lo Key Terms)
'()* Reader IIynn and McHoes, chaler 14, 426 - 432 (lo Memory
Managemenl), 451 (from User Inlerface) 457 (lo ConcIusion)
'()* Reader IIynn and McHoes, chaler 15, 462 - 469 (lo Memory
Managemenl), 487 (from User Inlerface) 494 (lo ConcIusion)
Study Guide 11: User Interfaces
!"+
11.4 MS Windows, UNIX and Linux
Shell Basics
In lhe revious readings from IIynn and McHoes you vouId have
encounlered lhe lerms balch and scril fiIes. alch fiIes are reIaled lo
DOS and earIy Windovs syslems (Windovs 3.x and 9x) vhiIe scril fiIes
are generaIIy allribuled vilh UNIX / Linux, and modern Windovs
syslems (Windovs NT, 2000 and XI). The urose of lhe lvo fiIe lyes
are exaclIy lhe same lhe aulomalion of commands.
A sheII is lhe lerm aIied lo lhe CLI environmenl offered by lhe
oeraling syslem. In DOS and Windovs il is referred lo as |usl lhe
command Iine or command roml, as lhere are no olher sheIIs avaiIabIe.
UNIX and Linux users have had access lo differenl sheIIs, such as lhe
ourne and TC, for decades. The sheII found in DOS and earIy Windovs
oeraling syslems vere very Iimiled and il vas nol unliI Windovs NT
lhal Windovs syslems suorled nalive Windovs SheII Scriling. To fiII
lhe ga on Windovs 9x syslems Windovs Scril Hosling (WSH) vas
deveIoed and is suorled by Windovs NT, 200 and XI loday. WSH
invoIves inslaIIing indeendenl scriling engines and vriling scrils in a
arlicuIar scriling Ianguage. y defauIl Windovs syslems suorl
}scril and VScril onIy. In lhis unil ve viII be focusing on Windovs
SheII Scriling, bul you shouId be avare lhal Windovs syslems have lvo
melhods for imIemenling scriling.
Various sheIIs rovide lhe user vilh lhe abiIily lo rovide a cuslomized
user inlerface, somelhing lhal DOS and Windovs has slruggIed vilh over
lhe years.
What can a Shell Offer?
As indicaled earIier lhe main urose of scriling is lo aulomale lasks.
Hovever, a CLI in lhe hands of an exerl user is generaIIy quicker lhan if
lhey used a GUI. In some syslems a GUI is nol even inslaIIed, everylhing
is done via lhe CLI. GeneraIIy a sheII can offer funclions such as:
Inleracling vilh environmenl sellings
Crealing and modifying users and grous
Manage services / daemons
Manage / inlerface vilh lhe fiIe syslem / fiIes
TroubIeshooling syslems and nelvork fauIls
Aulomale mundane / reelilive / comIicaled / lasks via scrils
ScheduIing of lasks via scrils
FIT1001 Computer Systems
!""
In lhe reading beIov ve viII inlroduce lhe Windovs and Linux (ourne)
sheIIs and slarl lo areciale lhe overfuI nalure of sheIIs.
,-). Reader Iord, chaler 2, 23 - 42 (lo Windovs Scril Hosl
Comonenls)
'()* Reader Iord, chaler 2, 32 (from Command SheII Modes) -
33
/(0 2--(33 Access ,45*6 758*( !! seclion of lhe unil vebsile and
viev suorl informalion on lhe Windovs SheII
Invironmenl and Crealing Your Iirsl Scril.
'()* Reader Iord, chaler 5, 89 - 106 (lo MalhemalicaI VariabIes)
,-). Reader SobeII, chaler 5, 107-132
'()* Reader SobeII, chaler 5, 111 (from Irocessing lhe
Command Line) - 112
'()* Reader SobeII, chaler 8, 255-274, 284 (from IATH: Where
The SheII Looks for Irograms) -285 (lo MAIL: Where Your MaiI
Is Kel)
Web Access
/(0 2--(33 Access ,45*6 758*( !! seclion of lhe unil vebsile and
comIele Iab / luloriaI exercises.
Study
Guide
!"
Introduction to
System Software
LEARNING OBJECTIVES
Al lhe comIelion of lhis sludy guide you viII be abIe lo:
describe lhe reIalionshi belveen machine Ianguage, assembIer
code and high IeveI Ianguage,
undersland lhe use of syslem soflvare looIs incIuding
assembIers, Iinkers, Ioaders, edilors, comiIers, inlerrelers and
debuggers,
describe lhe concel of reIocalabiIily of rogram code,
exIain some melhods used lo define lhe synlax of comuler
Ianguages incIuding synlax (raiIroad) diagrams and NI,
Iisl lhe slages of high IeveI rogram comiIalion,
differenliale belveen Iink/Ioader syslems lhal erform earIy,
Iale and dynamic binding..
FIT1001 Computer Systems
!#$
Contents
12.1 Inlroduclion
12.2 Irogram TransIalion
12.3 Machine Language and AssembIer
12.4 Irogramming Language Definilion
12.5 ComiIers and Inlerrelers
12.6 ComiIers and Inlerrelers
12.7 Irogramming Language Definilion
Reading
Prescribed readings
NuII and Lobur, !""#$%&'(" *+ ,*-./%#0 102'$&3'%&*$ 4 5067&%#6%/0#8
Chaler 8: Syslem Soflvare
Reader: IngIander, 97# 5067&%#6%/0# *+ ,*-./%#0 :'0;<'0# '$; =>"%#-"
=*+%<'0#8
Chaler 17: Irogramming TooIs, 560-593
Study Guide 12: Introduction to System Software
!#%
12.1 Introduction
Syslem soflvare may be defined as a coIIeclion of rograms and
associaled dala lhal suorls lhe use of a comuler syslem. In facl, mosl
comulers vouId be unusabIe vilhoul syslem soflvare. The oeraling
syslem (sludied earIier) is a ma|or comonenl of lhis coIIeclion. DelaiIed
knovIedge and underslanding of lhe oeraling syslem is required by aII
syslem deveIoers.
In lhis sludy guide you viII be Iooking al rogram deveIomenl soflvare.
This incIudes lhe rograms used lo edil, lransIale, manage, lesl and
execule rograms. Syslem soflvare aIso incIudes dala slorage and
relrievaI comonenls as veII as lransaclion managemenl comonenls, bul
lhese are Iefl for furlher reading.
12.2 Program Translation
In order lo execule a rogram, il musl firsl be exressed in lhe binary
machine Ianguage for lhe inlended comuler. This machine Ianguage
code has lo be resenl in lhe comuler's memory al lhe lime il is lo be
execuled. Gelling a rogram inlo lhis slale is a very ledious and lime
consuming rocess and for lhis reason nearIy aII syslems are never
rogrammed in machine Ianguage. Inslead lhe rogram is encoded in a
more convenienl formal and lhe comuler ilseIf is used lo converl lhe
encoded rogram inlo machine Ianguage. The same aIies lo lesling and
managing lhe execulion of rograms, vhere seciaIized comuler
rograms knovn as inleraclive deveIomenl environmenls (IDIs) and
debuggers are used lo lesl and conlroI lhe execulion of nev syslems.
The encoded formal used lo vrile lhe rogram is usuaIIy slored in a fiIe
as Iines of lexl. The lexl is usuaIIy a Ianguage, vilh a vocabuIary (Iexicon)
and ruIes for lhe conslruclion of slalemenls (synlax), and lhe fiIe
conlaining lhe encoded rogram is caIIed lhe "*/06# +&(#. WhiIe any lexl
edilor rogram can be used lo creale lhe source fiIe, some edilors vilh
varying degrees of seciaIizalion for lhe lask, such as vi, emacs, gedil,
elc. are oflen used. These rogram edilors can aulomalicaIIy highIighl
lhe Ianguage synlax, using indenlalion or coIoured lexl, and aIso indicale
fauIls in lhe Ianguage exressions, such as missing synlax eIemenls.
Irogram edilors can aIso rovide Ianguage-reIaled disIay and navigalion
fealures, and olher rogram deveIomenl aides.
Irogramming Ianguages aeared soon afler lhe deveIomenl of slored
rogram comulers in lhe 1950's. These earIy Ianguages became knovn
FIT1001 Computer Systems
!&'
as 5""#-?(#0" because lhey vere used lo lransIale a symboIic
reresenlalion of lhe machine Ianguage inlo binary machine formal. One
Iine of assembIer is lransIaled inlo one machine Ianguage inslruclion.
AssembIer Ianguage is cIoseIy reIaled lo lhe machine inslruclions, bul
vilh names for lhe ocodes and variabIes and a simIe synlax used lo
reresenl lhe arls of lhe machine inslruclions. This meanl lhal rograms
vrillen in assembIer vere onIy meaningfuI for a arlicuIar machine, and
couId nol be lransorled lo differenl machines.
In lhe mid-1950's rogramming Ianguages such as Iorlran, AIgoI and
COOL aeared. These 7&27@(#A#( ('$2/'2#" had lhe advanlage lhal lhey
did nol deend on one machine archileclure and lhe source rograms
couId be lransorled lo any machine vhere a suilabIe lransIalor vas
avaiIabIe. The lransIalor rogram vas caIIed a 6*-.&(#0 and vas more
comIicaled lhal an assembIer because lhe Ianguages conlained synlax
eIemenls referring lo high-IeveI funclions ralher lhan machine
inslruclions. One Iine of Iorlran or COOL vas lransIaled inlo Iarge
numbers of machine inslruclions, and oflen used many suorling
subrouline funclions rovided by lhe comiIer in 0/$@%&-# (&?0'0&#".
()*+ Reader IngIander, chaler 17, 560 (from 17.2) 562 (lo 17.3)
12.3 Machine Language and Assembler
The concel of an assembIer has aIready been resenled in earIier sludy
guides, bul is vorlh revieving here.
,--)./0)1 3456*78 AssembIers simIy lransIale one Iine of code inlo one
machine Ianguage inslruclion, and each Iine has comonenls lhal
reresenl lhe machine Ianguage archileclure, incIuding names for lhe
differenl inslruclion lyes (ocodes) and olher names, caIIed ">-?*(" lo
reresenl memory slorage Iocalions (variabIes) and osilions vilhin lhe
code (IabeIs). AssembIers aIso accel ;&0#6%&A#" vhich rovide seciaI
delaiIs for lhe lransIalion, such as lhe *0&2&$, vhich is lhe slarling address
in memory vhere lhe inslruclions are lo be Iaced, or markers lhal
idenlify lhe lye of memory segmenl for vhich lhe generaled code (eg
DATA or CODI or STACK elc.).
9*:1;-8 Mosl rograms conlain arameler vaIues or sequences of
inslruclions lhal occur frequenlIy lhroughoul lhe code, for examIe, lhe
Ioading and unIoading of aramelers during subrouline caIIs or
rocedures lhal handIe errors. A B'60* 5""#-?(#0" can define a samIe of
Study Guide 12: Introduction to System Software
!&!
such a recurring code sequence, ossibIy vilh some vay lo subslilule
aramelers vilhin lhe macro code, and inserl a comIele coy of lhe
macro code vherever lhe name of lhe macro aears vilhin lhe source
code rogram. This nol onIy reduced lhe efforl in coding Iong rograms,
bul aIso aIIovs lhe code sequence lo be defined in one Iace and lhen
simIy reealed vhen needed, lhus reducing lhe occurrence of coding
errors.
()0;:*6*/0) <;+)8 During lhe lransIalion of assembIer slalemenls inlo
execulabIe inslruclions, lhe memory address used as lhe oerand is
caIcuIaled. Deending on lhe addressing mode used, lhe resuIl is usuaIIy
reIaled in some vay lo lhe osilion in memory vhere lhe rogram is lo be
execuled. This osilion is knovn as lhe *0&2&$ and is imIied or secified
by an assembIer direclive. AssembIers can generale '?"*(/%# 6*;# lhal can
onIy be execuled vhen Ioaded al a fixed osilion in memory vhich is lhe
same as lhe origin, or 0#(*6'%'?(# 6*;# vhich may be osilioned anyvhere
in memory, and lhen lhe origin is imIied lo be lhe Ioad oinl. AbsoIule
code is onIy used in a fev aIicalions. These incIude device drivers and
embedded conlroI rograms, vhere lhe oerand addresses musl refer lo
fixed osilions in memory, such as I/O device regislers or fixed
archilecluraI slruclures such as inlerrul veclor labIes. In muIli-
rogramming oeraling syslems lhe origin Ioad oinl of a rogram is
aIIocaled vhen lhe rogram is execuled, and deends on vhal arls of
memory are avaiIabIe al lhe lime. In lhis silualion, reIocalabIe code is
required. ase Regisler or Segmenl Regisler addressing modes rovide a
convenienl vay lo reIocale rogram code, since lhe oeraling syslem onIy
needs lo sel lhe vaIue of lhe base or segmenl regisler lo lhe address vhere
lhe rogram vas Ioaded for each rocess.
()*+ Reader IngIander, chaler 17, 562 (from 17.3) 572 (lo 17.4)
()*+ NuII and Lobur, chaler 8, ages 378 (from 8.4) - 381 (lo 8.4.2)
12.4 Programming Language Definition
High-IeveI Ianguages aIIov rogrammers lo more easiIy exress lhe
soIulion lo a robIem because lhey conlain lerms and oeralions lhal
more cIoseIy resembIe lhe funclions and dala ilems used in lhe robIem
area. TransIaling lhese funclions inlo assembIer roduces much Iarger and
more reelilive sequences of machine IeveI inslruclions. ecause of lhe
comIexily of lhe lransIalion rocess a more formaI aroach lo lhe
FIT1001 Computer Systems
!&"
secificalion of lhe rogramming Ianguages is needed. Language can be
defined as lhree inlerreIaled comonenls:
=)7>:*0 : definilions of vords used in lhe Ianguage and lheir
associalions,
3456*:6>: : definilions of lhe forms and conlenl of lhe Ianguage,
lhe grammar.
3).*56>: : definilion of lhe meanings associaled vilh exressions.
The more successfuI rogramming Ianguages have been defined so lhal
lheir IexicaI and synlaclic comonenls are reguIar and lighlIy conlroIIed.
Words and symboIs are given exacl and cIearIy defined meanings, so lhal
lhe Ianguage is moslIy defined by lhe Iexicon and lhe grammar.
AnaIyzing lhe synlax of each slalemenl logelher vilh some simIe
semanlic condilions is usuaIIy sufficienl lo lransIale lhe slalemenls onlo
sniels of machine code and lhe reIalionshi belveen slalemenls is oflen
sufficienl lo ul lhe sniels logelher lo form a machine rogram lhal
erforms lhe funclions exressed in lhe source code. IxeculabIe code
generaled by a comiIer may nol be as efficienl or comacl as assembIer
rograms vrillen by craflsman rogrammers, bul il is more roduclive.
There are severaI vays lo define lhe grammar of a comuler Ianguage.
These incIude:
IngIish narralive descrilions
Synlax diagrams, aIso knovn as raiI-road diagrams or synlax
grahs
ackus-Naur Iorm (NI), aIso knovn as conlexl-free grammar.
See lhe readings beIov for more delaiIed examIes of each of lhese
melhods.
In addilion lo lhe synlax, a Ianguage definilion musl incIude some
semanlic ruIes lhal conlroI hov lo undersland Ianguage slalemenls. These
incIude ruIes such as:
The order of definilion of variabIes, in some Ianguages, variabIes
musl aII be defined before lhey can be used.
Dala lye casling, lhe imIied lye of inlermediale dala ilems in a
caIcuIalion
Irecedence of oeralor evaIualion in arilhmelic exressions
Use of conlexl lo resoIve ambiguous exressions
Study Guide 12: Introduction to System Software
!&?
()*+ Reader IngIander, chaler 17, 572 (from 17.4) 585 (lo The
ComiIalion Irocess)
12.5 Compilers and Interpreters
The comiIalion rocess invoIves four main slages. Slarling vilh (#C&6'(
'$'(>"&", lhe source rogram is scanned and converled inlo a slream of
Ianguage eIemenls logelher vilh a labIe of lhe symboIs used as variabIes
and IabeIs in lhe rogram. The comiIer lhan begins ">$%'C '$'(>"&" vhich
verifies lhal lhe sequence of lokens conforms lo lhe aIIoved ruIes for
exression in lhe Ianguage.
@>A !"BCB! DE) -6*A)- ;F G1;A1*. :;.G>0*6>;5
Al lhe same lime, lhe inlerreIalionshi belveen lhe synlax lokens and
conlexl of exressions is used lo erform "#-'$%&6 '$'(>"&". The
recognilion of correcl and comIele synlax eIemenls causes 6*;# 2#$#0'%&*$,
vhere fragmenls of machine code are emilled. These fragmenls oflen
make use of reviousIy vrillen moduIes of code vhich may be caIIed
FIT1001 Computer Systems
!&H
from Ianguage suorl roulines Iocaled in Iibraries of re-comiIed code,
caIIed run-lime Iibraries.
In modern comiIers lhis is usuaIIy foIIoved by one or more slages of 6*;#
*.%&-&3'%&*$ in vhich lhe inlermediale code is insecled lo find vays lo
reduce lhe amounl of code and lo reorganize lhe code lo make il fasler or
more efficienl. This is of arlicuIar imorlance in RISC machines and
lhose lhal use ieIines lo heI avoid code combinalions lhal viII cause
inefficienl oeralions such as ieIine fIushes.
Anolher vay lo lransIale a high-IeveI Ianguage rogram inlo machine
code is lo use an inlerreler. WhiIe a comiIer lransIales lhe enlire
rogram inlo a binary execulabIe formal, an inlerreler onIy lransIales
one slalemenl al a lime and execules il immedialeIy, before moving on lo
lhe nexl source code slalemenl. WhiIe lhe inlerrelive aroach Ieads lo
much sIover rogram execulion seeds, il does have some advanlages
arlicuIarIy in a rogram deveIomenl environmenl. Synlax errors can be
immedialeIy delecled and correclions made slraighl avay by lhe
rogrammer and olher fauIls in lhe rogram lhal mighl olhervise be falaI
lo lhe enlire rocess can be inlerceled by lhe oeraling syslem and
conlroI relurned lo lhe rogrammer for reairs.
()*+ Reader IngIander, chaler 17, 585 (from The ComiIalion
Irocess) 589 (lo 17.5)
()*+ NuII and Lobur, chaler 8, ages 384 (from 8.4.4) - 389 (lo 8.5)
12.6 Linking and Loading
Il is more convenienl lo design and code Iarge syslems as a sel of inler-
reIaled moduIes or ob|ecls. This is good raclice vhen lhe same moduIe
or ob|ecl is reused in many Iaces vilhin a syslem. This oflen means lhal
each ob|ecl is coded as a searale rogram, and afler comiIalion lhe
various moduIes and ob|ecls musl be combined inlo an execulabIe unil.
This may invoIve some modificalion or ediling of lhe binary rograms so
lhal lhe caIIing references can be reIaced by lhe acluaI addresses of lhe
caIIed moduIes. This is done by a comiIer or oeraling syslem uliIily
caIIed a Iinker, Iink edilor or binder. Once an execulabIe unil has been
crealed, il musl be Ioaded inlo a rocess address sace lo be execuled.
This is done by anolher oeraling syslem uliIily rogram caIIed a Ioader.
The Ioader may make furlher changes lo lhe rogram, by reIocaling ils
various segmenls inlo differenl arls of a rocess address sace.
Study Guide 12: Introduction to System Software
!&C
There are four Iink/Ioading scenarios:
!B AbsoIule slalic code generaled al lhe end of a deveIomenl cycIe
in facl need no Iink ediling al aII. This scenario is commonIy used
for singIe-user or embedded conlroI environmenls.
@>A !"B#B! =>5I =;*+>5A -4-6). J>6E K*104 L>5+>5A
2. Slalic Ioad images are crealed using a Iinker or Iink edilor, vhich
galhers aII machine Ianguage comonenls logelher, edils and fixes-
u lhe caII references belveen lhem and vriles lhe enlire image lo
a fiIe. A searale uliIily (lhe Ioader) may lhen be used lo run lhe
rogram any number of limes vilhoul needing lo reeal lhe Iink
edil rocedure. This melhod is referred lo as #'0(> ?&$;&$2, and
vhiIe is Ieads lo fasl rogram Ioading and execulion, il may cause
inefficienl use of memory vhen severaI coies of lhe same
rogram or rograms conlaining lhe same sel of moduIes are
execuled concurrenlIy, since lhere viII be muIliIe coies of lhe
same moduIe code Ioaded inlo memory. AIso, a change lo lhe
source code of a commonIy used moduIe viII require lhal aII
rograms lhal use lhe moduIe musl be reIinked.
3. A more efficienl use of memory can be achieved using a ('%#
?&$;&$2 aroach. This is ossibIe vhen lhe funclions of lhe Iinker
and lhe Ioader uliIilies are combined. The execulabIe image of a
rogram is lhen crealed al lhe lime lhe rogram is execuled, ralher
lhan as a slalic Ioad image. This increases lhe efforl required lo run
a rogram, bul has lhe advanlage lhal moduIes Ioaded as arl of
FIT1001 Computer Systems
!&#
anolher rogram may aIready in memory and don'l need lo be
Ioaded again. Thus, onIy one coy of lhe moduIe is ever required.
This aIso means lhal a comiIed change lo lhe source code of lhal
moduIe viII be aulomalicaIIy incororaled inlo every rogram lhal
uses il vilhoul needing lo reIink.
4. The Iasl scenario is caIIed ;>$'-&6 ?&$;&$2. This melhod is aIso
caIIed a shared overIay, shared ob|ecl or dynamic Iink Iibrary
(DLL), and invoIved lhe slorage of moduIes and rograms in
searale fiIes by lhe Iinker. When lhe Ioader is required lo run a
rogram, onIy lhe main arl of lhe rogram is Ioaded inlo
memory. Once execulion has slarled, lhe rogram ilseIf Ioads each
moduIe as required, using seciaI oeraling syslem Ioader services
lo gel lhe required moduIe and incororale il inlo lhe rocess
address sace. WhiIe lhis is lhe sIovesl of aII execulion melhods il
Ieaves lhe binding of lhe moduIe code lo lhe Ialesl ossibIe lime
and makes mosl efficienl use of memory.
()*+ Reader IngIander, chaler 17, 589 (from 17.5) 592 (lo 17.6)
()*+ NuII and Lobur, chaler 8, ages 381 (from 8.4.2) - 384 (lo 8.4.4)
12.7 Debugging and Testing
High-IeveI Ianguages and comiIers viII idenlify mosl of lhe errors lhal
can occur during rogram deveIomenl, excel for mislakes in lhe Iogic
of lhe rogram. Ior lhis reason il is essenliaI lo execule rograms in a lesl
environmenl and verify lhal lhey acluaIIy do vhal lhe designers inlended.
A debugger is a rogram lhal can execule a lesl rogram one inslruclion
al a lime or u lo a reviousIy defined Iace in lhe code (caIIed a
breakoinl) and monilor lhe dala variabIes during ils execulion. A
debugger can be used lo sle lhe rogram lhrough il various slages and
valch lhe vay lhal il erforms lhe inlended lask. WhiIe lhe debugger has
conlroI of lhe rogram, lhe rogrammer can insecl or change memory
and regisler vaIues. Hovever, lhis is onIy usefuI if lhe rogrammer
underslands lhe assembIer IeveI rogram. Wilh high-IeveI rograms, a
machine IeveI debugger is of Iimiled use because lhe code being execuled
usuaIIy has IillIe resembIance lo lhe high-IeveI source code. A source-IeveI
debugger is a rogram lhal can access lhe symboI labIe roduced by lhe
comiIer and lhe source code of lhe rogram and rovide simiIar
Study Guide 12: Introduction to System Software
!&&
funclions lo lhe machine-IeveI debugger (inslruclion sle, breakoinl and
variabIe moniloring) bul al lhe source code IeveI.
Debuggers are oflen incIuded vilh rogram edilors, screen designers,
comiIers or inlerrelers, Iink edilors, ob|ecl brovsers, version conlroI
and Iibrary managers, as arl of a ackage caIIed an inleraclive
deveIomenl environmenl or IDI. There are IDIs for visuaI basic, .NIT
and |ava deveIomenl vhich may be exIored in Ialer unil of lhis degree.
()*+ Reader IngIander, chaler 17, 592 (from 17.6) 593
Web Access
M)/ ,::)-- Access 36N+4 ON>+) !" seclion of lhe unil vebsile and
comIele Iab / luloriaI exercises.
FIT1001 Computer Systems
!&$

S-ar putea să vă placă și