computing and informatics
TRANSCRIPT
-
7/27/2019 Computing and Informatics
1/34
Computing and Informatics Class Notes for AMIE
By Vinayak Ashok Bharadi
Local Area Networks
For historical reasons the industry refers to nearly e!ery type of network as an
"area network#" $he most commonly%discussed categories of computer networks
include the following %
& Local Area Network 'LAN( & )ide Area Network ')AN( & Metropolitan Area
Network 'MAN( & *torage Area Network '*AN( & *ystem Area Network '*AN( &
*er!er Area Network '*AN( & *mall Area Network '*AN( & +ersonal Area
Network '+AN( & ,esk Area Network ',AN( & Controller Area Network 'CAN( &
Cluster Area Network 'CAN(
LANs and )ANs were the original fla!ors of network design# $he concept of
"area" made good sense at this time -ecause a key distinction -etween a LAN
and a )AN in!ol!es the physical distance that the network spans# A third
category the MAN also fit into this scheme as it too is centered on a distance%
-ased concept#
As technology impro!ed new types of networks appeared on the scene# $hese
too -ecame known as !arious types of "area networks" for consistency.s sake
although distance no longer pro!ed a useful differentiator#
LAN Basics
A LAN connects network de!ices o!er a relati!ely short distance# A networked
office -uilding school or home usually contains a single LAN though sometimes
one -uilding will contain a few small LANs and occasionally a LAN will span a
group of near-y -uildings# In I+ networking one can concei!e of a LAN as a
single I+ su-net 'though this is not necessarily true in practice(#
Besides operating in a limited space LANs include se!eral other distincti!e
features# LANs are typically owned controlled and managed -y a single person
or organi/ation# $hey also use certain specific connecti!ity technologies
primarily Ethernet and $oken 0ing#
)AN Basics
As the term implies a wide%area network spans a large physical distance# A )AN
like the Internet spans most of the world1
A )AN is a geographically%dispered collection of LANs# A network de!ice called a
router connects LANs to a )AN# In I+ networking the router maintains -oth a
LAN address and a )AN address#
)ANs differ from LANs in se!eral important ways# Like the Internet most )ANs
are not owned -y any one organi/ation -ut rather e2ist under collecti!e or
-
7/27/2019 Computing and Informatics
2/34
distri-uted ownership and management# )ANs use technology like A$M Frame
0elay and 3#45 for connecti!ity#
LANs and )ANs at 6ome
6ome networkers with ca-le modem or ,*L ser!ice already ha!e encounteredLANs and )ANs in practice though they may not ha!e noticed# A ca-le7,*L
router like those in the Linksys family 8oin the home LAN to the )AN link
maintained -y one.s I*+# $he I*+ pro!ides a )AN I+ address used -y the router
and all of the computers on the home network use pri!ate LAN addresses# 9n a
home network like many LANs all computers can communicate directly with
each other -ut they must go through a central gateway location to reach
de!ices outside of their local area#
)hat A-out MAN *AN +AN ,AN and CAN:
Future articles will descri-e the many other types of area networks in moredetail# After LANs and )ANs one will most commonly encounter the following
three network designs;
A Metropolitan Area Network connects an area larger than a LAN -ut smaller
than a )AN such as a city with dedicated or high%performance hardware#
A *torage Area Network connects ser!ers to data storage de!ices through a
technology like Fi-re Channel#
A *ystem Area Network connects high%performance computers with high%speed
connections in a cluster configuration#
Conclusion
$o the uninitiated LANs )ANs and the other area network acroymns appear to
-e 8ust more alpha-et soup in a technology industry already drowning in
terminology# $he names of these networks are not nearly as important as the
technologies used to construct them howe!er# A person can use the
categori/ations as a learning tool to -etter understand concepts like su-nets
gateways and routers#
Bus ring star and other types of network topology In networking the term"topology" refers to the layout of connected de!ices on a network# $his article
introduces the standard topologies of computer networking#
$opology in Network ,esign 9ne can think of a topology as a network.s !irtual
shape or structure# $his shape does not necessarily correspond to the actual
physical layout of the de!ices on the network# For e2ample the computers on a
home LAN may -e arranged in a circle in a family room -ut it would -e highly
unlikely to find an actual ring topology there#
Network topologies are categori/ed into the following -asic types;
& -us & ring & star & tree & mesh
-
7/27/2019 Computing and Informatics
3/34
More comple2 networks can -e -uilt as hy-rids of two or more of the a-o!e -asic
topologies#
Bus $opology Bus networks 'not to -e confused with the system -us of a
computer( use a common -ack-one to connect all de!ices# A single ca-le the
-ack-one functions as a shared communication medium that de!ices attach ortap into with an interface connector# A de!ice wanting to communicate with
another de!ice on the network sends a -roadcast message onto the wire that all
other de!ices see -ut only the intended recipient actually accepts and processes
the message#
Ethernet -us topologies are relati!ely easy to install and don.t re?uire much
ca-ling compared to the alternati!es# =@Base%4 '"$hinNet"( and =@Base%5
'"$hickNet"( -oth were popular Ethernet ca-ling options many years ago for -us
topologies# 6owe!er -us networks work -est with a limited num-er of de!ices# If
more than a few do/en computers are added to a network -us performance
pro-lems will likely result# In addition if the -ack-one ca-le fails the entire
network effecti!ely -ecomes unusa-le#
0ing $opology In a ring network e!ery de!ice has e2actly two neigh-ors for
communication purposes# All messages tra!el through a ring in the same
direction 'either "clockwise" or "counterclockwise"(# A failure in any ca-le or
de!ice -reaks the loop and can take down the entire network#
$o implement a ring network one typically uses F,,I *9NE$ or $oken 0ing
technology# 0ing topologies are found in some office -uildings or school
campuses#
*tar $opology Many home networks use the star topology# A star network
features a central connection point called a "hu-" that may -e a hu- switch or
router# ,e!ices typically connect to the hu- with nshielded $wisted +air '$+(
Ethernet#
Compared to the -us topology a star network generally re?uires more ca-le -ut
a failure in any star network ca-le will only take down one computer.s network
access and not the entire LAN# 'If the hu- fails howe!er the entire network also
fails#(
$ree $opology $ree topologies integrate multiple star topologies together onto a
-us# In its simplest form only hu- de!ices connect directly to the tree -us and
each hu- functions as the "root" of a tree of de!ices# $his -us7star hy-rid
approach supports future e2panda-ility of the network much -etter than a -us
'limited in the num-er of de!ices due to the -roadcast traffic it generates( or a
star 'limited -y the num-er of hu- connection points( alone#
Mesh $opology Mesh topologies in!ol!e the concept of routes# nlike each of the
pre!ious topologies messages sent on a mesh network can take any of se!eral
possi-le paths from source to destination# '0ecall that e!en in a ring although
two ca-le paths e2ist messages can only tra!el in one direction#( *ome )ANslike the Internet employ mesh routing#
-
7/27/2019 Computing and Informatics
4/34
*ummary $opologies remain an important part of network design theory# ou
can pro-a-ly -uild a home or small -usiness network without understanding the
difference -etween a -us design and a star design -ut understanding the
concepts -ehind these gi!es you a deeper understanding of important elements
like hu-s -roadcasts and routes
Internet protocol suite
Internet protocol suite
Layer +rotocols
5# Application ,N* $L*7**L $F$+ F$+ 6$$+ IMA+ I0C +9+D *I+ *M$+
*NM+ **6 $ELNE$ 0$+
# $ransport $C+ ,+ 0*V+ ,CC+ *C$+
D# Network I+ 'I+! I+!( ICM+ IGM+ A0+ 0A0+
4# ,ata link Ethernet )i%Fi +++ F,,I A$M Frame
0elay G+0* Bluetooth
=# +hysical Modems I*,N *9NE$7*,6 0*4D4 *B Ethernet physical layer )i%
Fi G*M Bluetooth
$he Internet protocol suite is the set of communications protocols that
implement the protocol stack on which the Internet and most commercial
networks run# It is sometimes called the $C+7I+ protocol suite after the two mostimportant protocols in it; the $ransmission Control +rotocol '$C+( and the
Internet +rotocol 'I+( which were also the first two defined#
$he Internet protocol suite H like many protocol suites H can -e !iewed as a set
of layers each layer sol!es a set of pro-lems in!ol!ing the transmission of data
and pro!ides a well%defined ser!ice to the upper layer protocols -ased on using
ser!ices from some lower layers# pper layers are logically closer to the user and
deal with more a-stract data relying on lower layer protocols to translate data
into forms that can e!entually -e physically transmitted# $he original $C+7I+
reference model consisted of four layers -ut has e!ol!ed into a fi!e layer model#
$he 9*I model descri-es a fi2ed se!en layer stack for networking protocols#
Comparisons -etween the 9*I model and $C+7I+ can gi!e further insight into the
significance of the components of the I+ suite -ut can also cause confusion
since the definition of the layers are slightly different#
6istory
$he Internet protocol suite came from work done -y ,A0+A in the early =J@s#
After -uilding the pioneering A0+ANE$ ,A0+A started work on a num-er of
other data transmission technologies# In =J4 0o-ert E# Kahn was hired at the
,A0+A Information +rocessing $echnology 9ffice where he worked on -oth
satellite packet networks and ground%-ased radio packet networks and
-
7/27/2019 Computing and Informatics
5/34
recogni/ed the !alue of -eing a-le to communicate across them# In the spring of
=JD Vinton Cerf the de!eloper of the e2isting A0+ANE$ Network Control
+rogram 'NC+( protocol 8oined Kahn to work on open%architecture
interconnection models with the goal of designing the ne2t protocol for the
A0+ANE$#
By the summer of =JD Kahn and Cerf had soon worked out a fundamental
reformulation where the differences -etween network protocols were hidden -y
using a common internetwork protocol and instead of the network -eing
responsi-le for
relia-ility as in the A0+ANE$ the hosts -ecame responsi-le# 'Cerf credits 6u-ert
immerman and Louis +ou/in with
important influences on this design#(
)ith the role of the network reduced to the -are minimum it -ecame possi-le to
8oin almost any networks together no matter what their characteristics werethere-y sol!ing Kahn.s initial pro-lem# '9ne popular saying has it that $C+7I+ the
e!entual product of Cerf and Kahn.s work will run o!er "two tin cans and a
string" and it has in fact -een implemented using homing pigeons#( A computer
called a gateway 'later changed to router to a!oid confusion with other types of
gateway( is pro!ided with an interface to each network and forwards packets
-ack and forth -etween them#
$he idea was worked out in more detailed form -y Cerf.s networking research
group at *tanford in the =JDJ period# '$he early networking work at 3ero2
+A0C which produced the +A0C ni!ersal +acket protocol suite much of whichwas contemporaneous was also a significant technical influence people mo!ed
-etween the two#(
,A0+A then contracted with BBN $echnologies *tanford ni!ersity and the
ni!ersity College London to de!elop operational !ersions of the protocol on
different hardware platforms# Four !ersions were de!eloped; $C+ != $C+ !4 a
split into $C+ !D and I+ !D in the spring of =JO and then sta-ility with $C+7I+ !
H the standard protocol still in use on the Internet today#
In =J5 a two%network $C+7I+ communications test was performed -etween
*tanford and ni!ersity College London 'CL(# In No!em-er =JJ a three%network $C+7I+ test was conducted -etween the #*# K and Norway# Between
=JO and =OD se!eral other $C+7I+ prototypes were de!eloped at multiple
research centres# A full switcho!er to $C+7I+ on the A0+ANE$ took place Panuary
= =OD#
In March =O4 the * ,epartment of ,efense made $C+7I+ the standard for
all military computer networking# In =O5 the Internet Architecture Board held a
three day workshop on $C+7I+ for the computer industry attended -y 45@ !endor
representati!es helping populari/e the protocol and leading to its increasing
commercial use#
-
7/27/2019 Computing and Informatics
6/34
9n No!em-er 4@@5 Kahn and Cerf were presented with the +residential Medal
of Freedom for their contri-ution to American culture#
Layers in the Internet protocol suite stack
I+ suite stack showing the physical network connection of two hosts !ia tworouters and the corresponding layers used at each hop
*ample encapsulation of data within a ,+ datagram within an I+ packet
$he I+ suite uses encapsulation to pro!ide a-straction of protocols and ser!ices#
Generally a protocol at a higher le!el uses a protocol at a lower le!el to help
accomplish its aims# $he Internet protocol stack can -e roughly fitted to the four
layers of the original $C+7I+ model;
,N* $F$+ $L*7**L F$+ 6$$+ IMA+ I0C NN$+ +9+D *I+ *M$+ *NM+ **6
$ELNE$ EC69 Bit$orrent 0$+ +N0+ rlogin EN0+
# Application
0outing protocols like BG+ and 0I+ which for a !ariety of reasons run o!er $C+
and ,+ respecti!ely may also -e considered part of the application or network
layer#
$C+ ,+ ,CC+ *C$+ IL 0,+
D# $ransport
0outing protocols like 9*+F which run o!er I+ may also -e considered part ofthe transport or network layer# ICM+ and IGM+ run o!er I+ may -e considered
part of the network layer#
I+ 'I+! I+!(
4# Internet
A0+ and 0A0+ operate underneath I+ -ut a-o!e the link layer so they -elong
somewhere in -etween#
=# Network access
Ethernet )i%Fi $oken ring +++ *LI+ F,,I A$M Frame 0elay *M,*
In many modern te2t-ooks this model has e!ol!ed into the fi!e layer $C+7I+
model where the Network access layer is splitted into a ,ata link layer on top of
a +hysical layer and the Internet layer is called Network layer#
Implementations
$oday most commercial operating systems include and install the $C+7I+ stack
-y default# For most users there is no need to look for implementations# $C+7I+ is
included in all commercial ni2 systems Mac 9* 3 and all free%software ni2%
-
7/27/2019 Computing and Informatics
7/34
like systems such as Linu2 distri-utions and B*, systems as well as Microsoft
)indows#
ni?ue implementations include Lightweight $C+7I+ an open source stack
designed for em-edded systems and KAQ N9* a stack and associated
protocols for amateur packet radio systems and personal computers connected!ia serial lines#
Karnaugh map
$he Karnaugh map also known as a Veitch diagram 'K%map or KV%map for short(
is a tool to facilitate management of Boolean alge-raic e2pressions# A Karnaugh
map is uni?ue in that only one !aria-le changes !alue -etween s?uares in other
words the rows and columns are ordered according to the principles of Gray
code#
6istory and nomenclature
$he Karnaugh map was in!ented in =5D -y Maurice Karnaugh a
telecommunications engineer at Bell La-s#
sage in -oolean logic
Normally e2tensi!e calculations are re?uired to o-tain the minimal e2pression of
a Boolean function -ut one can use a Karnaugh map instead#
+ro-lem sol!ing uses
& Karnaugh maps make use of the human -rain.s e2cellent pattern%matchingcapa-ility to decide which terms should -e com-ined to get the simplest
e2pression# & K%maps permit the rapid identification and elimination of potential
race ha/ards something that -oolean e?uations alone cannot do# & A Karnaugh
map is an e2cellent aid for simplification of up to si2 !aria-les -ut with more
!aria-les it -ecomes hard e!en for our -rain to discern optimal patterns# & For
pro-lems in!ol!ing more than si2 !aria-lessol!ing the -oolean e2pressions is
more preferred than the Karnaugh map#
Karnaugh maps also help teach a-out Boolean functions and minimi/ation#
+roperties
A mapping of minterms on a Karnaugh map# $he arrows indicate which s?uares
can -e thought of as "switched" 'rather than -eing in a normal se?uential order(#
A Karnaugh map may ha!e any num-er of !aria-les -ut usually works -est
when there are only a few % -etween 4 and for e2ample# Each !aria-le
contri-utes two possi-ilities to each possi-ility of e!ery other !aria-le in the
system# Karnaugh maps are organi/ed so that all the possi-ilities of the system
are arranged in a grid form and -etween two ad8acent -o2es only one !aria-le
can change !alue# $his is what allows it to reduce ha/ards#
-
7/27/2019 Computing and Informatics
8/34
)hen using a Karnaugh map to deri!e a minimi/ed function one "co!ers" the
ones on the map -y rectangular "co!erings" that contain a num-er of -o2es
e?ual to a power of 4 'for e2ample -o2es in a line -o2es in a s?uare O
-o2es in a rectangle etc(# 9nce a person has co!ered the ones that person can
produce a term of a sum of products -y finding the !aria-les that do not change
throughout the entire co!ering and taking a = to mean that !aria-le and a @ asthe complement of that !aria-le# ,oing this for e!ery co!ering gi!es you a
matching function#
9ne can also use /eros to deri!e a minimi/ed function# $he procedure is identical
to the procedure for ones e2cept that each term is a term in a product of sums %
and a = means the compliment of the !aria-le while @ means the !aria-le non%
complimented#
Each s?uare in a Karnaugh map corresponds to a minterm 'and ma2term(# $hepicture to the right shows the location of each minterm on the map#
E2ample
Consider the following function;
f'ABC,( R E'O=@===4==5(
$he !alues inside E tell us which rows ha!e output =#
$his function has this truth ta-le;
S A B C , f'ABC,(
@ @ @ @ @ @
= @ @ @ = @
4 @ @ = @ @
D @ @ = = @
@ = @ @ =
5 @ = @ = @
@ = = @ @
J @ = = = @
O = @ @ @ =
= @ @ = =
=@ = @ = @ =
== = @ = = =
-
7/27/2019 Computing and Informatics
9/34
=4 = = @ @ =
=D = = @ = @
= = = = @ =
=5 = = = = =
$he input !aria-les can -e com-ined in = different ways so our Karnaugh map
has to ha!e = positions# $he most con!enient way to arrange this is in a 2
grid#
$he -inary digits in the map represent the function.s output for any gi!en
com-ination of inputs# )e write @ in the upper leftmost corner of the map
-ecause f R @ when A R @ B R @ C R = , R @# *imilarly we mark the -ottom
right corner as = -ecause A R = B R @ C R @ , R @ gi!es f R =# Note that the!alues are ordered in a Gray code so that precisely one !aria-le flips -etween
any pair of ad8acent cells#
After the Karnaugh map has -een constructed our ne2t task is to find the
minimal terms to use in the final e2pression# $hese terms are found -y encircling
groups of =.s in the map# $he encirclings must -e rectangular and must ha!e an
area that is a positi!e power of two 'i#e# 4 O (# $he rectangles should -e as
large as possi-le without containing any @.s# $he optimal encirclings in this map
are marked -y the green red and -lue lines#
For each of these encirclings we find those !aria-les that ha!e the same state in
each of the fields in the encircling# For the first encircling 'the red one( we find
that;
& $he !aria-le A maintains the same state '=( in the whole encircling therefore it
should -e included in the term for the red encircling# & Varia-le B does not
maintain the same state 'it shifts from = to @( and should therefore -e e2cluded#
& C does not change; it is always =# & , changes#
$hus the first term in the Boolean e2pression is AC#
For the green encircling we see that A and B maintain the same state -ut C and
, change# B is @ and has to -e negated -efore it can -e included# $hus the
second term is AB.#
In the same way the -lue rectangle gi!es the term BC.,. and so the whole
e2pression is; AC T ABUT BCU,U#
$he grid is toroidally connected which means that the rectangles can wrap
around edges so AB,U is a !alid term although not part of the minimal set#
$he in!erse of a function is sol!ed in the same way -y encircling the @.s instead#
-
7/27/2019 Computing and Informatics
10/34
In a Karnaugh map with n !aria-les a Boolean term mentioning k of them will
ha!e a corresponding rectangle of area 4n%k#
Karnaugh maps also allow easy minimi/ations of functions whose truth ta-les
include "don.t care" conditions 'that is sets of inputs for which the designer
doesn.t care what the output is( -ecause "don.t care" conditions can -e includedin a ring to make it larger -ut do not ha!e to -e ringed# $hey are usually
indicated on the map with a hyphen7dash in place of the num-er# $he !alue can
-e a "@" "=" or the hyphen7dash73 depending on if
one can use the "@" or "=" to simplify the KM more# If the "don.t cares" don.t help
you simplify the KM more then use the hyphen7dash73#
0ace ha/ards
Karnaugh maps are useful for detecting and eliminating race ha/ards# $hey are
!ery easy to spot using a Karnaugh map -ecause a race condition may e2istwhen mo!ing -etween any pair of ad8acent -ut dis8ointed regions circled on the
map#
& In the a-o!e e2ample a potential race condition e2ists when C and , are -oth
@ A is a = and B changes from a @ to a = 'mo!ing from the green state to the
-lue state(# For this case the output is defined to remain unchanged at = -ut
-ecause this transition is not co!ered -y a specific term in the e?uation a
potential for a glitch 'a momentary transition of the output to @( e2ists# & A
harder possi-le glitch to spot is if , was @ and A and B were -oth = with C
changing from @ to =# In this case the glitch wraps around from the -ottom of the
map to the top of the map#
)hether these glitches do occur depends on the physical nature of the
implementation and whether we need to worry a-out it depends on the
application#
In this case an additional term of TA,. would eliminate the potential race
ha/ard -ridging -etween the green and -lue output states or -lue and red
output states#
$he term is redundant in terms of the static logic of the system -ut such
redundant terms are often needed to assure race%free dynamic performance#
)hen not to use K%maps
$he diagram -ecomes cluttered and hard to interpret if there are more than four
!aria-les on an a2is# $his argues against the use of Karnaugh maps for
e2pressions with more than si2 !aria-les# For such e2pressions the Quine%
McCluskey algorithm also called the method of prime implicants should -e
used#
$his algorithm generally finds most of the optimal solutions ?uickly and easily
-ut selecting the final prime implicants 'after the essential ones are chosen( may
-
7/27/2019 Computing and Informatics
11/34
still re?uire a -rute force approach to get the optimal com-ination 'though this is
generally far simpler than trying to -rute force the entire pro-lem(#
Logic gate
A logic gate performs a logical operation on one or more logic inputs andproduces a single logic output# $he logic normally performed is Boolean logic and
is most commonly found in digital circuits# Logic gates are primarily implemented
electronically using diodes or transistors -ut can also -e constructed using
electromagnetic relays fluidics optical or e!en mechanical elements#
Logic le!els
A Boolean logical input or output always takes one of two logic le!els# $hese
logic le!els can go -y many names including; on 7 off high '6( 7 low 'L( one '=( 7
/ero '@( true '$( 7 false 'F( positi!e 7 negati!e positi!e 7 ground open circuit 7
close circuit potential difference 7 no difference yes 7 no#
For consistency the names = and @ will -e used -elow#
Logic gates
A logic gate takes one or more logic%le!el inputs and produces a single logic%le!el
output# Because the output is also a logic le!el an output of one logic gate can
connect to the input of one or more other logic gates# $wo outputs cannot -e
connected together howe!er as they may -e attempting to produce different
logic !alues# In electronic logic gates this would cause a short circuit#
In electronic logic a logic le!el is represented -y a certain !oltage 'which
depends on the type of electronic logic in use(# Each logic gate re?uires power so
that it can source and sink currents to achie!e the correct output !oltage# In
logic circuit diagrams the power is not shown -ut in a full electronic schematic
power connections are re?uired#
Background
$he simplest form of electronic logic is diode logic# $his allows AN, and 90 gates
to -e -uilt -ut not in!erters and so is an incomplete form of logic# $o -uild a
complete logic system !al!es or transistors can -e used# $he simplest family oflogic gates using -ipolar transistors is called resistor%transistor logic or 0$L#
nlike diode logic gates 0$L gates can -e cascaded indefinitely to produce more
comple2 logic functions# $hese gates were used in early integrated circuits# For
higher speed the resistors used in 0$L were replaced -y diodes leading to
diode%transistor logic or ,$L# It was then disco!ered that one transistor could do
the 8o- of two diodes in the space of one diode so transistor% transistor logic or
$$L was created# In some types of chip to reduce si/e and power consumption
still further the -ipolar transistors were replaced with complementary field%
effect transistors 'M9*FE$s( resulting in complementary metal%o2ide%
semiconductor 'CM9*( logic#
-
7/27/2019 Computing and Informatics
12/34
For small%scale logic designers now use prefa-ricated logic gates from families
of de!ices such as the $$L J@@ series in!ented -y $e2as Instruments and the
CM9* @@@ series in!ented -y 0CA and their more recent descendants# $hese
de!ices usually contain transistors with multiple emitters used to implement the
AN, function which are not a!aila-le as separate components# Increasingly
these fi2ed%function logic gates are -eing replaced -y programma-le logicde!ices which allow designers to pack a huge num-er of mi2ed logic gates into
a single integrated circuit# $he field%programma-le nature of programma-le logic
de!ices such as F+GAs has remo!ed the .hard. property of hardware it is now
possi-le to change the logic design of a hardware system -y
reprogramming some of its components thus allowing the features or function of
a hardware implementation of a logic system to -e changed#
Electronic logic gates differ significantly from their relay%and%switch e?ui!alents#
$hey are much faster consume much less power and are much smaller 'all -y a
factor of a million or more in most cases(# Also there is a fundamental structural
difference# $he switch circuit creates a continuous metallic path for current to
flow 'in either direction( -etween its input and its output# $he semiconductor
logic gate on the other hand acts as a high%gain !oltage amplifier which sinks a
tiny current at its input and produces a low% impedance !oltage at its output# It is
not possi-le for current to flow -etween the output and the input of a
semiconductor logic gate#
Another important ad!antage of standardised semiconductor logic gates such as
the J@@ and @@@ families is that they are cascada-le# $his means that the
output of one gate can -e wired to the inputs of one or se!eral other gates andso on ad infinitum ena-ling the construction of circuits of ar-itrary comple2ity
without re?uiring the designer to understand the internal workings of the gates#
In practice the output of one gate can only dri!e a finite num-er of inputs to
other gates a num-er called the .fanout limit. -ut this limit is rarely reached in
the newer CM9* logic circuits as compared to $$L circuits# Also there is always
a delay called the .propagation delay. from a change in input of a gate to the
corresponding change in its output# )hen gates are cascaded the total
propagation delay is appro2imately the sum of the indi!idual delays an effect
which can -ecome a pro-lem in high%speed circuits#
Electronic logic le!els
$he two logic le!els in -inary logic circuits are represented -y two !oltage
ranges "low" and "high"# Each technology has its own re?uirements for the
!oltages used to represent the two logic le!els to ensure that the output of any
de!ice can relia-ly dri!e the input of the ne2t de!ice# sually two non%
o!erlapping !oltage ranges one for each le!el are defined# $he difference
-etween the high and low le!els ranges from @#J !olts in Emitter coupled logic to
around 4O !olts in relay logic#
Logic gates and hardware
-
7/27/2019 Computing and Informatics
13/34
NAN, and N90 logic gates are the two pillars of logic in that all other types of
Boolean logic gates 'i#e# AN, 90 N9$ 390 3N90( can -e created from a
suita-le network of 8ust NAN, or 8ust N90 gate's(# $hey can -e -uilt from relays
or transistors or any other technology that can create an in!erter and a two%
input AN, or 90 gate# 6ence the NAN, and N90 gates are called the uni!ersal
gates#
For an input of 4 !aria-les there are = possi-le -oolean alge-ra outputs# $hese
= outputs are enumerated -elow with the appropriate function or logic gate for
the possi-le com-inations of A and B# Note that not all outputs ha!e a
corresponding
function or logic gate although those that do not can -e produced -y
com-inations of those that can#
A @ @ = =
IN+$
B @ = @ =
@ @ @ @ @
A AN, B @ @ @ =
@ @ = @
A @ @ = =
@ = @ @
B @ = @ =
A 390 B @ = = @
A 90 B @ = = =
A N90 B = @ @ @
A 3N90 B = @ @ =
9$+$
N9$ B = @ = @
= @ = =
N9$ A = = @ @
= = @ =
A NAN, B = = = @
= = = = =
-
7/27/2019 Computing and Informatics
14/34
Logic gates are a !ital part of many digital circuits and as such e!ery kind is
a!aila-le as an IC# For e2amples see the @@@ series of CM9* logic chips or the
J@@ series#
*ym-ols
$here are two sets of sym-ols in common use -oth now defined -y AN*I7IEEE
*td =% =O and its supplement AN*I7IEEE *td =a%==# $he "distincti!e shape"
set -ased on traditional schematics is used for simple drawings and is ?uicker
to draw -y hand# It is sometimes unofficially descri-ed as "military" reflecting its
origin if not its modern usage# $he "rectangular shape" set -ased on IEC @=J%
=4 has rectangular outlines for all types of gate and allows representation of a
much wider range of de!ices than is possi-le with the traditional sym-ols# $he
IEC.s system has -een adopted -y other standards such as EN @=J%=4;= in
Europe and B* EN @=J%=4;= in the nited Kingdom#
$ype ,istincti!e shape 0ectangular shape
Boolean alge-ra -etween A B $ruth ta-le
AN,
IN+$ 9$+$ A B A AN, B @ @ @ @ = @ = @ @
= = =
90
A T B
IN+$ 9$+$ A B A 90 B @ @ @ @ = = = @ = = = =
N9$
IN+$ 9$+$ A N9$ A @ = = @
In electronics a N9$ gate is more commonly called an in!erter# $he circle on the
sym-ol is called a -u--le and is generally used in circuit diagrams to indicate an
in!erted input or output#
NAN,
IN+$ 9$+$ A B A NAN, B @ @ = @ = = = @ = = = @
N90
IN+$ 9$+$ A B A N90 B @ @ = @ = @ = @ @ = = @
In practice the cheapest gate to manufacture is usually the NAN, gate#
Additionally
Charles +eirce showed that NAN, gates alone 'as well as N90 gates alone( can-e used to reproduce all the other logic gates#
-
7/27/2019 Computing and Informatics
15/34
*ym-olically a NAN, gate can also -e shown using the 90 shape with -u--les
on its inputs and a N90 gate can -e shown as an AN, gate with -u--les on its
inputs# $his reflects the e?ui!alency due to ,e Morgans law -ut it also allows a
diagram to -e read more easily or a circuit to -e mapped onto a!aila-le physical
gates in packages easily since any circuit node that has -u--les at -oth ends
can -e replaced -y a simple -u--le% less connection and a suita-le change ofgate# If the NAN, is drawn as 90 with input -u--les and a N90 as AN, with
input -u--les this gate su-stitution occurs automatically in the diagram
'effecti!ely -u--les "cancel"(# $his is commonly seen in real logic diagrams %
thus the reader must not get into the ha-it of associating the shapes e2clusi!ely
as 90 or AN, shapes -ut also take into account the -u--les at -oth inputs and
outputs in order to determine the "true" logic function indicated#
$wo more gates are the e2clusi!e%90 or 390 function and its in!erse e2clusi!e%
N90 or 3N90# $he two input E2clusi!e%90 is true only when the two input !alues
are different false if they are e?ual regardless of the !alue# If there are morethan two inputs the gate generates a true at its output if the num-er of trues at
its input is odd '(# In practice these gates are -uilt from com-inations of
simpler logic gates#
390
IN+$ 9$+$ A B A 390 B @ @ @ @ = = = @ = = = @
3N90
IN+$ 9$+$ A B A 3N90 B @ @ = @ = @ = @ @ = = =
$he J@@ chip containing four NAN,s# $he two additional contacts supply power
'T5 V( and connect the ground#
,eMorgan e?ui!alent sym-ols
By use of ,e Morgan.s theorem an AN, gate can -e turned into an 90 gate -y
in!erting the sense of the logic at its inputs and outputs# $his leads to a separate
set of sym-ols with in!erted inputs and the opposite core sym-ol# $hese sym-ols
can make circuit diagrams for circuits using acti!e low signals much clearer andhelp to show accidental connection of an acti!e high output to an acti!e low
input or !ice%!ersa#
*torage of -its
0elated to the concept of logic gates 'and also -uilt from them( is the idea of
storing a -it of information# $he gates discussed up to here cannot store a !alue;
when the inputs change the outputs immediately react# It is possi-le to make a
storage element either through a capacitor 'which stores charge due to its
physical properties( or -y feed-ack# Connecting the output of a gate to the input
causes it to -e put through the logic again and choosing the feed-ack correctly
allows it to -e preser!ed or modified through the use of other inputs# A set of
-
7/27/2019 Computing and Informatics
16/34
gates arranged in this fashion is known as a "latch" and more complicated
designs that utilise clocks 'signals that oscillate with a known period( and change
only on the rising edge are called edge%triggered "flip%flops"# $he com-ination of
multiple flip%flops in parallel to store a multiple%-it !alue is known as a register#
$hese registers or capacitor%-ased circuits are known as computer memory#$hey !ary in performance -ased on factors of speed comple2ity and relia-ility
of storage and many different types of designs are used -ased on the
application#
$hree%state logic gates
A tristate -uffer can -e thought of as a switch# If B is on the switch is closed# If
B is off the switch is open# Main article; $ri%state -uffer
$hree%state or D%state logic gates ha!e three states of the output; high '6( low
'L( and high%impedance '(# $he high%impedance state plays no role in the logicwhich remains strictly -inary# $hese de!ices are used on -uses to allow multiple
chips to send data# A group of three%states dri!ing a line with a suita-le control
circuit is -asically e?ui!alent to a multiple2er which may -e physically
distri-uted o!er separate de!ices or plug%in cards#
.$ri%state. a widely%used synonym of .three%state. is a trademark of the National
*emiconductor Corporation#
Miscellaneous
Logic circuits include such de!ices as multiple2ers registers arithmetic logicunits 'ALs( and computer memory all the way up through complete
microprocessors which can contain more than a =@@ million gates# In practice
the gates are made from field effect transistors 'FE$s( particularly metal%o2ide%
semiconductor FE$s 'M9*FE$s(#
In re!ersi-le logic $offoli gates are used#
6istory and de!elopment
$he earliest logic gates were made mechanically# Charles Ba--age around
=ODJ de!ised the Analytical Engine# 6is logic gates relied on mechanical gearingto perform operations# Electromagnetic relays were later used for logic gates# In
=O= Almon *trowger patented a de!ice containing a logic gate switch circuit
'#*# +atent @J=O(# *trowger.s patent was not in widespread use until the
=4@s# *tarting in =OO Nikola $esla filed for patents of de!ices containing logic
gate circuits 'see List of $esla patents(# E!entually !acuum tu-es replaced
relays for logic operations# Lee ,e Forest.s modification in =@J of the Fleming
!al!e can -e used as AN, logic gate# Claude E# *hannon introduced the use of
Boolean alge-ra in the analysis and design of switching circuits in =DJ# )alther
Bothe in!entor of the coincidence circuit got part of the =5 No-el +ri/e in
physics for the first modern electronic AN, gate in =4# Acti!e research istaking place in molecular logic gates#
-
7/27/2019 Computing and Informatics
17/34
Common Basic Logic ICs
CM9* $$L Function
@@= J@4 Quad two%input N90 gate
@== J@@ Quad two%input NAN, gate
@ J@ 6e2 N9$ gate 'in!erting -uffer(
@J@ JO Quad two%Input 390 gate
@J= JD4 Quad two%input 90 gate
@JJ J4 Quad two%input 3N90 gate
@O= J@O Quad two%input AN, gate
For more CM9* logic ICs including gates with more than two inputs see @@@series#
Adders 'electronics(
In electronics an adder is a de!ice which will perform the addition * of two
num-ers# In computing the adder is part of the AL and some ALs contain
multiple adders# Although adders can -e constructed for many numerical
representations such as Binary% coded decimal or e2cess%D the most common
adders operate on -inary num-ers# In cases where two.s complement is -eing
used to represent negati!e num-ers it is tri!ial to modify an adder into an adder%
su-tracter#
For single -it adders there are two general types# A half adder has two inputs
generally la-elled A and B and two outputs the sum * and carry output Co# * is
the two%-it 2or of A and B and Co is the two%-it and of A and B# Essentially the
output of a half adder is the two%-it arithmetic sum of two one%-it num-ers with
Co -eing the most significant of these two outputs#
$he other type of single -it adder is the full adder which is like a half adder -ut
takes an additional input carry Ci# A full adder can -e constructed from two half
adders -y connecting A and B to the input of one half adder connecting the sumfrom that to an input to the second adder connecting Ci to the other input and
or the two carry outputs# E?ui!alently * could -e made the three%-it 2or of A B
and Ci and Co could -e made the
three%-it ma8ority function of A B and Ci# $he output of the full adder is the two%
-it arithmetic sum of three one%-it num-ers#
$he purpose of the carry input on the full%adder is to allow multiple full%adders to
-e chained together with the carry output of one adder connected to the carry
input of the ne2t most significant adder# $he carry is said to ripple down the
carry lines of this sort of adder gi!ing it the name ripple carry adder#
-
7/27/2019 Computing and Informatics
18/34
6alf adder
6alf adder circuit diagram
A half adder is a logical circuit that performs an addition operation on two -inary
digits# $he half adder produces a sum and a carry !alue which are -oth -inarydigits#
Following is the logic ta-le for a half adder;
Input 9utput
A B C *
@ @ @ @
@ = @ =
= @ @ =
= = = @
Full adder
Full adder circuit diagram A T B T CarryIn R *um T Carry9ut
A full adder is a logical circuit that performs an addition operation on three
-inary digits# $he full adder produces a sum and carry !alue which are -oth
-inary digits# It can -e com-ined with other full adders 'see -elow( or work on its
own#
Input 9utput
A B Ci Co *
@ @ @ @ @
@ @ = @ =
@ = @ @ =
@ = = = @
= @ @ @ =
= @ = = @
= = @ = @
= = = = =
Note that the final 90 gate -efore the carry%out output may -e replaced -y an
390 gate without altering the resulting logic# $his is -ecause the only
discrepancy -etween 90 and 390 gates occurs when -oth inputs are = for the
-
7/27/2019 Computing and Informatics
19/34
adder shown here one can check this is ne!er possi-le# sing only two types of
gates is con!enient if one desires to implement the adder directly using common
IC chips#
9nes. complement
Alternati!ely a system known as ones. complement can -e used to represent
negati!e num-ers# $he ones. complement form of a -inary num-er is the -itwise
N9$ applied to it H the complement of its positi!e counterpart# Like sign%and%
magnitude representation ones. complement has two representations of @;
@@@@@@@@ 'T@( and ======== 'W@(#
As an e2ample the ones. complement form of @@=@=@== 'D( -ecomes
==@=@=@@ 'WD(# $he range of signed num-ers using ones. complement in a
con!entional eight%-it -yte is W=4J=@ to T=4J=@#
$o add two num-ers represented in this system one does a con!entional -inaryaddition -ut it is then necessary to add any resulting carry -ack into the
resulting sum# $o see why this is necessary consider the case of the addition of
W= '=======@( to T4 '@@@@@@=@(# $he -inary addition alone gi!es @@@@@@@@H
not the correct answer1 9nly when the carry is added -ack in does the correct
result '@@@@@@@=( appear#
$his numeric representation system was common in older computers the +,+%=
and NIVAC ==@@744@@ series among many others used ones.%complement
arithmetic#
'A remark on terminology; $he system is referred to as "ones. complement"-ecause the negation of 2 is formed -y su-tracting 2 from a long string of ones#
$wo.s complement arithmetic on the other hand forms the negation of 2 -y
su-tracting 2 from a single large power of two#(
$wo.s complement
$wo.s complement is the most popular method of representing signed integers in
computer science# It is also an operation of negation 'con!erting positi!e to
negati!e num-ers or !ice !ersa( in computers which represent negati!e num-ers
using two.s complement# Its use is u-i?uitous today -ecause it doesn.t re?uire
the addition and su-traction circuitry to e2amine the signs of the operands to
determine whether to add or
su-tract making it -oth simpler to implement and capa-le of easily handling
higher precision arithmetic# Also @ has only a single representation o-!iating
the su-tleties associated with negati!e /ero 'which e2ists in one.s complement(#
sign -it @ = = = = = = = R =4J @ @ @ @ @ @ = @ R 4 @ @ @ @ @ @ @ = R = @ @ @ @ @ @
@ @ R @ = = = = = = = = R W= = = = = = = = @ R W4 = @ @ @ @ @ @ = R W=4J = @ @ @
@ @ @ @ R W=4O O%-it two.s complement integers
E2planation $wo.s complement ,ecimal @@@= = @@@@ @ ==== W= ===@ W4 ==@=
WD ==@@ W $wo.s complement using a %-it integer
-
7/27/2019 Computing and Informatics
20/34
$wo.s complement represents signed integers -y counting -ackwards and
wrapping around#
$he -oundary -etween positi!e and negati!e num-ers may theoretically -e
anywhere 'as long as you check for it(# For con!enience all num-ers whose left%
most -it is = are considered negati!e# $he largest num-er representa-le this waywith -its is @=== 'J( and the smallest num-er is =@@@ '%O(#
$o understand its usefulness for computers consider the following# Adding @@==
'D( to ==== '%=( results in the seemingly%incorrect =@@=@# 6owe!er ignoring the
5th -it 'from the right( as we did when we counted -ackwards gi!es us the
actual answer @@=@ '4(# Ignoring the 5th -it will work in all cases 'although you
ha!e to do the aforementioned o!erflow checks when eg @=@@ is added to
@=@@(# $hus a circuit designed for addition can handle negati!e operands
without also including a circuit capa-le of su-traction 'and a circuit which
switches -etween the two -ased on the sign(# Moreo!er -y this method an
addition circuit can e!en perform su-tractions if you con!ert the necessary
operand into the "counting%-ackwards" form# $he procedure for doing so is called
taking the two.s
complement 'which admittedly re?uires either an e2tra cycle or its own adder
circuit(# Lastly a !ery important reason for utili/ing two.s complement
representation is that it would -e considera-ly more comple2 to create a
su-traction circuit which would take @@@= % @@=@ and gi!e =@@= 'ie %@@=( than it
is to make one that returns ====# ',oing the former means you ha!e to check
the sign then check if there will -e a sign re!ersal then possi-ly rearrange the
num-ers and finally su-tract# ,oing the latter means you simply su-tractpretending there.s an e2tra left%most -it hiding somewhere#(
In an n%-it -inary num-er the most significant -it is usually the 4nW=s place# But
in the two.s complement representation its place !alue is negated it -ecomes
the W4nW=s place and is called the sign -it#
If the sign -it is @ the !alue is positi!e if it is = the !alue is negati!e# $o negate
a two.s complement num-er in!ert all the -its then add = to the result#
If all -its are = the !alue is W=# If the sign -it is = -ut the rest of the -its are @
the !alue is the most negati!e num-er W4nW= for an n%-it num-er# $he a-solute!alue of the most negati!e num-er cannot -e represented with the same
num-er of -its -ecause it is greater than the most positi!e num-er that two.s
complement num-er -y e2actly =#
A two.s complement O%-it -inary numeral can represent e!ery integer in the
range W=4O to T=4J# If the sign -it is @ then the largest !alue that can -e stored
in the remaining se!en -its is 4J W = or =4J#
sing two.s complement to represent negati!e num-ers allows only one
representation of /ero and to ha!e effecti!e addition and su-traction while still
ha!ing the most significant -it as the sign -it#
-
7/27/2019 Computing and Informatics
21/34
Calculating two.s complement
In finding the two.s complement of a -inary num-er the -its are in!erted or
"flipped" -y using the -itwise N9$ operation the !alue of = is then added to the
resulting !alue# Bit o!erflow is ignored which is the normal case with /ero#
For e2ample -eginning with the signed O%-it -inary representation of the
decimal !alue 5;
@@@@ @=@= '5(
$he first -it is @ so the !alue represented is indeed a positi!e 5# $o con!ert to
W5 in two.s complement notation the -its are in!erted @ -ecomes = and =
-ecomes @;
==== =@=@
At this point the numeral is the ones. complement of the decimal !alue 5# $oo-tain the two.s complement = is added to the result gi!ing;
==== =@== '%5(
$he result is a signed -inary numeral representing the decimal !alue W5 in two.s
complement form# $he most significant -it is = so the !alue is negati!e#
$he two.s complement of a negati!e num-er is the corresponding positi!e !alue#
For e2ample in!erting the -its of W5 'a-o!e( gi!es;
@@@@ @=@@
And adding one gi!es the final !alue;
@@@@ @=@= '5(
$he decimal !alue of a two.s complement -inary num-er is calculated -y taking
the !alue of the most significant -it where the !alue is negati!e when the -it is
one and adding to it the !alues for each power of two where there is a one#
E2ample;
==== =@== 'W5( R W=4O T T D4 T = T O T @ T 4 T = R 'W4XJ T 4X T ###(
R W5
Note that the two.s complement of /ero is /ero; in!erting gi!es all ones and
adding one changes the ones -ack to /eros 'the o!erflow is ignored(# Also the
two.s complement of the most negati!e num-er representa-le 'e#g# a one as the
sign -it and all other -its /ero( is itself# $his happens -ecause the most negati!e
num-er.s "positi!e counterpart" is occupied -y "@" which gets classed as a
positi!e num-er in this argument# 6ence there appears to -e an .e2tra. negati!e
num-er#
-
7/27/2019 Computing and Informatics
22/34
A more formal definition of two.s complement negati!e num-er 'denoted -y NY
in this e2ample( is deri!ed from the e?uation N Y R 4 W N n where N is the
corresponding positi!e num-er and n is the num-er of -its in the representation#
For e2ample to find the -it representation of %5;
N '-ase =@( R 5 therefore N '-ase 4( R @=@= n R
6ence;
N Y R 4 W N R -ase4 W @=@= R =@@@@ W @=@= R =@== n
N#B# ou can also think of the e?uation as -eing entirely in -ase =@ con!erting
to -ase 4 at the end e#g#;
N Y R 4 W N R 4 W 5 R -ase=@ R -ase4 n
9-!iously "NY ### R ==" isn.t strictly true -ut as long as you interpret the e?ualssign as "is represented -y" it is perfectly accepta-le to think of two.s
complements in this fashion#
Ne!ertheless a shortcut e2ists when con!erting a -inary num-er in two.s
complement form#
@@== ==@@
Con!erting from right to left copy all the /eros until the first = is reached# Copy
down that one and then flip the remaining -its# $his will allow you to con!ert to
two.s complement without first con!erting to one.s complement and adding = tothe result# $he two.s complemented form of the num-er a-o!e in this case is;
==@@ @=@@
*ign e2tension ,ecimal %-it two.s complement O%-it two.s complement 5 @=@=
@@@@ @=@= %D ==@= ==== ==@= sign%-it repetition in and O%-it integers
)hen turning a two.s complement num-er with a certain num-er of -its into one
with more -its 'e#g# when copying from a = -yte !aria-le to a two -yte !aria-le(
the sign -it must -e repeated in all the e2tra -its#
*ome processors ha!e instructions to do this in a single instruction# 9n other
processors a conditional must -e used followed with code to set the rele!ant -its
or -ytes#
*imilarly when a two.s complement num-er is shifted to the right the sign -it
must -e maintained# 6owe!er when shifted to the left a @ is shifted in# $hese
rules preser!e the common semantics that left shifts multiply the num-er -y two
and right shifts di!ide the num-er -y two#
Both shifting and dou-ling the precision are important for some multiplication
algorithms# Note that unlike addition and su-traction precision e2tension andright shifting are done differently for signed !s unsigned num-ers#
-
7/27/2019 Computing and Informatics
23/34
$he weird num-er
)ith only one e2ception when we start with any num-er in two.s complement
representation if we flip all the -its and add = we get the two.s complement
representation of the negati!e of that num-er# Negati!e =4 -ecomes positi!e =4
positi!e 5 -ecomes negati!e 5 /ero -ecomes /ero etc#
W=4O =@@@ @@@@ in!ert -its @=== ==== add one =@@@ @@@@ $he two.s
complement of %=4O results in the same O%-it -inary num-er#
$he most negati!e num-er in two.s complement is sometimes called "the weird
num-er" -ecause it is the only e2ception#
$he two.s complement of the minimum num-er in the range will not ha!e the
desired effect of negating the num-er# For e2ample the two.s complement of
%=4O results in the same -inary num-er# $his is -ecause a positi!e !alue of =4O
cannot -e represented with an O%-it signed -inary numeral# Note that this isdetected as an o!erflow condition since there was a carry into -ut not out of the
sign -it#
Although the num-er is weird it is a !alid num-er# All arithmetic operations work
with it -oth as an operand and 'unless there was an o!erflow( a result#
)hy it works
$he 4n possi-le !alues of n -its actually form a ring of e?ui!alence classes
namely the integers modulo 4n 7'4n(# Each class represents a set Z8 T k4n [ k
is an integer\ for some integer 8 @ ] 8 ] 4n W =# $here are 4n such sets andaddition and multiplication are well%defined on them#
If the classes are taken to represent the num-ers @ to 4n W = and o!erflow
ignored then these are the unsigned integers# But each of these num-ers is
e?ui!alent to itself minus 4n# *o the classes could -e understood to represent
W4nW= to 4nW= W = -y su-tracting 4n from half of them 'specifically (#
For e2ample with eight -its the unsigned -ytes are @ to 455# *u-tracting 45
from the top half '=4O to 455( yields the signed -ytes W=4O to =4J#
$he relationship to two.s complement is realised -y noting that 45 R 455 T =
and '455 W 2( is the ones. complement of 2#
,ecimal $wo.s complement =4J @=== ==== @=@@ @@@@ = @@@@ @@@= @ @@@@
@@@@ %= ==== ==== % ==@@ @@@@
%=4J =@@@ @@@= %=4O =@@@ @@@@ *ome special num-ers to note
E2ample
W5 modulo 45 is e?ui!alent to == since
-
7/27/2019 Computing and Informatics
24/34
W5 T 45 R W5 T 455 T = R 455 W 5 T = R =@ T = R == ==== ====
455 W @=@= ==== W 5 RRRRRRRRRRR RRRRR
=@=@ @@@@ 'ones. complement( =@ T = T =
RRRRRRRRRRR RRRRR =@=@ @@@= 'two.s complement( ==
Arithmetic operations
Addition
Adding two.s complement num-ers re?uires no special processing if the
operands ha!e opposite signs; the sign of the result is determined automatically#
For e2ample adding =5 and %5;
===== === 'carry( @@@@ ==== '=5( T ==== =@== '%5(
RRRRRRRRRRRRRRRRRR @@@@ =@=@ '=@(
$his process depends upon restricting to O -its of precision a carry to the
'none2istent( th most significant -it is ignored resulting in the arithmetically
correct result of =@#
$he last two -its of the carry row 'reading right%to%left( contain !ital information;
whether the calculation resulted in an arithmetic o!erflow a num-er too large
for the -inary system to represent 'in this case greater than O -its(# An o!erflow
condition e2ists when a carry 'an e2tra =( is generated into -ut not out of the far
left sign -it or out of -ut not into the sign -it# As mentioned a-o!e the sign -it
is the leftmost -it of the result#
In other terms if the last two carry -its 'the ones on the far left of the top row inthese e2amples( are -oth =.s or @.s the result is !alid if the last two carry -its
are "= @" or "@ =" a sign o!erflow has occurred# Con!eniently an 390 operation
on these two -its can
?uickly determine if an o!erflow condition e2ists# As an e2ample consider the %
-it addition of J and D;
@=== 'carry( @=== 'J( T @@== 'D( RRRRRRRRRRRRR =@=@ 'W( in!alid1
In this case the far left two 'M*B( carry -its are "@=" which means there was a
two.s complement addition o!erflow# $hat is ten is outside the permitted rangeof WO to J#
*u-traction
Computers usually use the method of complements to implement su-traction#
But although using complements for su-traction is related to using complements
for representing signed num-ers they are independent direct su-traction works
with two.s complement num-ers as well# Like addition the ad!antage of using
two.s complement is the elimination of e2amining the signs of the operands to
determine if addition or su-traction is needed# For e2ample su-tracting %5 from
=5 is really adding 5 to =5 -ut this is hidden -y the two.s complementrepresentation;
-
7/27/2019 Computing and Informatics
25/34
====@ @@@ '-orrow( @@@@ ==== '=5( W ==== =@== 'W5( RRRRRRRRRRR
@@@= @=@@ '4@(
9!erflow is detected the same way as for addition -y e2amining the two
leftmost 'most significant( -its of the -orrows o!erflow occurred if they are
different#
Another e2ample is a su-traction operation where the result is negati!e; =5 W D5
R W4@;
===@@ @@@ '-orrow( @@@@ ==== '=5( W @@=@ @@== 'D5( RRRRRRRRRRR
===@ ==@@ 'W4@(
Multiplication
$he product of two n%-it num-ers can potentially ha!e 4n -its# If the precision of
the two two.s complement operands is dou-led -efore the multiplication direct
multiplication 'discarding any e2cess -its -eyond that precision( will pro!ide the
correct result# For e2ample take 5 ^ W R WD@# First the precision is e2tended
from -its to O# $hen the num-ers are multiplied discarding the -its -eyond O
'shown -y .2.(;
@@@@@=@= '5( ^ =====@=@ 'W( RRRRRRRRR
@ =@= @ =@= =@= =@= 2@= 22= RRRRRRRRR 22===@@@=@
'WD@(
$his is !ery inefficient -y dou-ling the precision ahead of time all additions
must -e dou-le%precision and at least twice as many partial products are needed
than for the more efficient algorithms actually implemented in computers# *ome
multiplication algorithms are designed for two.s complement nota-ly Booth.s
algorithm# Methods for multiplying sign%magnitude num-ers don.t work with
two.s complement num-ers without adaptation# $here isn.t usually a pro-lem
when the multiplicand 'the one -eing repeatedly added to form the product( is
negati!e the issue is setting the initial -its of the product correctly when the
multiplier is negati!e# $wo methods for adapting algorithms to handle two.s
complement num-ers are common;
& First check to see if the multiplier is negati!e# If so negate 'i#e# take the two.scomplement of( -oth operands -efore multiplying# $he multiplier will then -e
positi!e so the algorithm will work# And since -oth operands are negated the
result will still ha!e the correct sign#
& *u-tract the partial product resulting from the sign -it instead of adding it like
the other partial products#
As an e2ample of the second method take the common add%and%shift algorithm
for multiplication# Instead of shifting partial products to the left as is done with
pencil and paper the accumulated product is shifted right into a second register
that will e!entually hold the least significant half of the product# *ince the least
significant -its are not changed once they are calculated the additions can -e
-
7/27/2019 Computing and Informatics
26/34
single precision accumulating in the register that will e!entually hold the most
significant half of the product# In the following e2ample again multiplying 5 -y
W the two registers are separated -y "[";
@=@= '5( ^=@=@ 'W( RRRR[RRRR @@@@[@@@@ 'first partial product
'rightmost -it is @(( @@@@[@@@@ 'shift right( @=@=[@@@@ 'add second partialproduct 'ne2t -it is =(( @@=@[=@@@ 'shift right( @@=@[=@@@ 'add third partial
product; @ so no change( @@@=[@=@@ 'shift right( ==@@[@=@@ 'su-tract last
partial product since it.s from sign -it( ===@[@@=@ 'shift right preser!ing sign
-it gi!ing the final answer WD@(
Memory hierarchy
$he hierarchical arrangement of storage in current computer architectures is
called the memory hierarchy# It is designed to take ad!antage of memory locality
in computer programs# Each le!el of the hierarchy is of higher speed and lower
latency and is of smaller si/e than lower le!els#
Most modern C+s are so fast that for most program workloads the locality of
reference of memory accesses and the efficiency of the caching and memory
transfer -etween different le!els of the hierarchy is the practical limitation on
processing speed# As a result the C+ spends much of its time idling waiting for
memory I79 to complete#
$he memory hierarchy in most computers is as follows;
& +rocessor registers fastest possi-le access 'usually = C+ cycle( only
hundreds of -ytes in si/e & Le!el = 'L=( cache often accessed in 8ust a fewcycles usually tens of kilo-ytes & Le!el 4 'L4( cache higher latency than L= -y
4^ to =@^ often 5=4 KiB or more & Le!el D 'LD( cache 'optional( higher
latency than L4 often se!eral MiB & Main memory ',0AM( may take hundreds
of cycles -ut can -e multiple giga-ytes# Access times may not -e uniform in the
case of a NMA machine# & ,isk storage hundreds of thousands of cycles
latency -ut !ery large & $ertiary storage tape optical disk ')90M(
Virtual memory
$he memory pages of the !irtual address space seen -y the process may reside
non% contiguously in primary or e!en secondary storage#
Virtual memory or !irtual memory addressing is a memory management
techni?ue used -y computer operating systems more common in multitasking
9*es wherein non% contiguous memory is presented to a software 'aka process(
as contiguous memory# $his contiguous memory is referred to as the !irtual
address space#
Virtual memory addressing is typically used in paged memory systems# $his in
turn is often com-ined with memory swapping 'also known as anonymous
memory paging( where-y memory pages stored in primary storage are written
-
7/27/2019 Computing and Informatics
27/34
to secondary storage 'often to a swap file or swap partition( thus freeing faster
primary storage for other processes to use#
In technical terms !irtual memory allows software to run in a memory address
space whose si/e and addressing are not necessarily tied to the computer.s
physical memory# $o properly implement !irtual memory the C+ 'or a de!iceattached to it( must pro!ide a way for the operating system to map !irtual
memory to physical memory and for it to detect when an address is re?uired that
does not currently relate to main memory so that the needed data can -e
swapped in# )hile it would certainly -e possi-le to pro!ide !irtual memory
without the C+.s assistance it would essentially re?uire emulating a C+ that
did pro!ide the needed features#
Background
Most computers possess four kinds of memory; registers in the C+ C+ caches
'generally some kind of static 0AM( -oth inside and ad8acent to the C+ mainmemory 'generally dynamic 0AM( which the C+ can read and write to directly
and reasona-ly ?uickly and disk storage which is much slower -ut much larger#
C+ register use is generally handled -y the compiler 'and if preempti!e
multitasking is in use swapped -y the operating system on conte2t switches( and
this isn.t a huge -urden as they are small in num-er and data doesn.t generally
stay in them !ery long# $he decision of when to use cache and when to use main
memory is generally dealt with -y hardware so generally -oth are regarded
together -y the programmer as simply physical memory#
Many applications re?uire access to more information 'code as well as data( thancan -e stored in physical memory# $his is especially true when the operating
system allows multiple processes7applications to run seemingly in parallel# $he
o-!ious response to the pro-lem of the ma2imum si/e of the physical memory
-eing less than that re?uired for all running programs is for the application to
keep some of its information on the disk and mo!e it -ack and forth to physical
memory as needed -ut there are a num-er of ways to do this#
9ne option is for the application software itself to -e responsi-le -oth for
deciding which information is to -e kept where and also for mo!ing it -ack and
forth# $he programmer would do this -y determining which sections of the
program 'and also its data( were
mutually e2clusi!e and then arranging for loading and unloading the appropriate
sections from physical memory as needed# $he disad!antage of this approach is
that each application.s programmer must spend time and effort on designing
implementing and de-ugging this mechanism instead of focusing on his or her
application this hampers programmers. efficiency# Also if any programmer
could truly choose which of their items of data to store in the physical memory at
any one time they could easily conflict with the decisions made -y another
programmer who also wanted to use all the a!aila-le physical memory at that
point#
-
7/27/2019 Computing and Informatics
28/34
Another option is to store some form of handles to data rather than direct
pointers and let the 9* deal with swapping the data associated with those
handles -etween the swap area and physical memory as needed# $his works -ut
has a couple of pro-lems namely that it complicates application code that it
re?uires applications to play nice 'they generally need the power to lock the data
into physical memory to actually work on it( and that it stops the languagesstandard li-rary doing its own su-allocations inside large -locks from the 9* to
impro!e performance# $he -est known e2ample of this kind of arrangement is
pro-a-ly the =%-it !ersions of )indows#
$he modern solution is to use !irtual memory in which a com-ination of special
hardware and operating system software makes use of -oth kinds of memory to
make it look as if the computer has a much larger main memory than it actually
does and to lay that space out differently at will# It does this in a way that is
in!isi-le to the rest of the software running on the computer# It usually pro!ides
the a-ility to simulate a main memory of almost any si/e 'In practice there.s alimit imposed on this -y the si/e of the addresses# For a D4%-it system the total
si/e of the !irtual memory can -e 4D4 or appro2imately giga-ytes# For the
newer %-it chips and operating systems that use or O -it addresses this
can -e much higher# Many operating systems do not allow the entire address
space to -e used -y applications to simplify kernel access to application memory
-ut this is not a hard design re?uirement#(
Virtual memory makes the 8o- of the application programmer much simpler# No
matter how much memory the application needs it can act as if it has access to
a main memory of that si/e and can place its data where!er in that !irtual space
that it likes# $he programmer can also completely ignore the need to manage the
mo!ing of data -ack and forth -etween the different kinds of memory# $hat said
if the programmer cares a-out performance when working with large !olumes of
data he needs to minimise the num-er of near-y -locks -eing accessed in order
to a!oid unnecessary swapping#
+aging
Virtual memory is usually '-ut not necessarily( implemented using paging# In
paging the low order -its of the -inary representation of the !irtual address are
preser!ed and used directly as the low order -its of the actual physical addressthe high order -its are treated as a key to one or more address translation
ta-les which pro!ide the high order -its of the actual physical address#
For this reason a range of consecuti!e addresses in the !irtual address space
whose si/e is a power of two will -e translated in a corresponding range of
consecuti!e physical addresses# $he memory referenced -y such a range is
called a page# $he page si/e is typically in the range of 5=4 to O=4 -ytes 'with
K currently -eing !ery common( though page si/es of mega-ytes or larger
may -e used for special purposes# 'sing the same or a related mechanism
contiguous regions of !irtual memory larger than a page are often mappa-le to
contiguous physical memory for purposes other than !irtuali/ation such assetting access and caching control -its#(
-
7/27/2019 Computing and Informatics
29/34
$he operating system stores the address translation ta-les the mappings from
!irtual to physical page num-ers in a data structure known as a page ta-le#
If a page that is marked as una!aila-le 'perhaps -ecause it is not present in
physical memory -ut instead is in the swap area( when the C+ tries to
reference a memory location in that page the MM responds -y raising ane2ception 'commonly called a page fault( with the C+ which then 8umps to a
routine in the operating system# If the page is in the swap area this routine
in!okes an operation called a page swap to -ring in the re?uired page#
$he page swap operation in!ol!es a series of steps# First it selects a page in
memory for e2ample a page that has not -een recently accessed and
'prefera-ly( has not -een modified since it was last read from disk or the swap
area# '*ee page replacement algorithms for details#( If the page has -een
modified the process writes the modified page to the swap area# $he ne2t step
in the process is to read in the information in the needed page 'the page
corresponding to the !irtual address the original program was trying to reference
when the e2ception occurred( from the swap file# )hen the page has -een read
in the ta-les for translating !irtual addresses to physical addresses are updated
to reflect the re!ised contents of the physical memory# 9nce the page swap
completes it e2its and the program is restarted and continues on as if nothing
had happened returning to the point in the program that caused the e2ception#
It is also possi-le that a !irtual page was marked as una!aila-le -ecause the
page was ne!er pre!iously allocated# In such cases a page of physical memory
is allocated and filled with /eros the page ta-le is modified to descri-e it and
the program is restarted as a-o!e#
,etails
$he translation from !irtual to physical addresses is implemented -y an MM
'Memory Management nit(# $his may -e either a module of the C+ or an
au2iliary closely coupled chip#
$he operating system is responsi-le for deciding which parts of the program.s
simulated main memory are kept in physical memory# $he operating system also
maintains the translation ta-les which pro!ide the mappings -etween !irtual and
physical addresses for use -y the MM# Finally when a !irtual memorye2ception occurs the operating system
is responsi-le for allocating an area of physical memory to hold the missing
information 'and possi-ly in the process pushing something else out to disk(
-ringing the rele!ant information in from the disk updating the translation
ta-les and finally resuming e2ecution of the software that incurred the !irtual
memory e2ception#
In most computers these translation ta-les are stored in physical memory#
$herefore a !irtual memory reference might actually in!ol!e two or more
physical memory references; one or more to retrie!e the needed address
-
7/27/2019 Computing and Informatics
30/34
translation from the page ta-les and a final one to actually do the memory
reference#
$o minimi/e the performance penalty of address translation most modern C+s
include an on%chip MM and maintain a ta-le of recently used !irtual%to%physical
translations called a $ranslation Lookaside Buffer or $LB# Addresses with entriesin the $LB re?uire no additional memory references 'and therefore time( to
translate 6owe!er the $LB can only maintain a fi2ed num-er of mappings
-etween !irtual and physical addresses when the needed translation is not
resident in the $LB action will ha!e to -e taken to load it in#
9n some processors this is performed entirely in hardware the MM has to do
additional memory references to load the re?uired translations from the
translation ta-les -ut no other action is needed# In other processors assistance
from the operating system is needed an e2ception is raised and on this
e2ception the operating system replaces one of the entries in the $LB with an
entry from the translation ta-le and the instruction which made the original
memory reference is restarted#
$he hardware that supports !irtual memory almost always supports memory
protection mechanisms as well# $he MM may ha!e the a-ility to !ary its
operation according to the type of memory reference 'for read write or
e2ecution( as well as the pri!ilege mode of the C+ at the time the memory
reference was made# $his allows the operating system to protect its own code
and data 'such as the translation ta-les used for !irtual memory( from corruption
-y an erroneous application program and to protect application programs from
each other and 'to some e2tent( from themsel!es 'e#g# -y pre!enting writes toareas of memory which contain code(
6istory
Before the de!elopment of the !irtual memory techni?ue programmers in the
=@s and =5@s had to manage two%le!el storage 'main memory or 0AM and
secondary memory in the form of hard disks or earlier magnetic drums( directly#
Virtual memory was de!eloped in appro2imately =5 % =4 at the ni!ersity
of Manchester for the Atlas Computer completed in =4# 6owe!er Frit/%0udolf
G_ntsch one of Germany.s pioneering computer scientists and later thede!eloper of the $elefunken $0 @ mainframe claims to ha!e in!ented the
concept in his doctoral dissertation Logischer Entwurf eines digitalen
0echenger`tes mit mehreren asynchron laufenden $rommeln und
automatischem *chnellspeicher-etrie- 'Logic Concept of a
,igital Computing ,e!ice with Multiple Asynchronous ,rum *torage and
Automatic Fast Memory Mode( in =5J#
In == Burroughs released the B5@@@ the first commercial computer with
!irtual memory#
-
7/27/2019 Computing and Informatics
31/34
Like many technologies in the history of computing !irtual memory was not
accepted without challenge# Before it could -e regarded as a sta-le entity many
models e2periments and theories had to -e de!eloped to o!ercome the
numerous pro-lems with !irtual memory# *peciali/ed hardware had to -e
de!eloped that would take a "!irtual" address and translate it into an actual
physical address in memory 'secondary or primary(# *ome worried that thisprocess would -e e2pensi!e hard to -uild and take too much processor power
to do the address translation#
By = the de-ates o!er !irtual memory for commercial computers were
o!er# An IBM research team lead -y ,a!id *ayre showed that
the !irtual memory o!erlay system worked consistently -etter than the -est
manual%controlled systems#
+ossi-ly the first minicomputer to introduce !irtual memory was the Norwegian
N90,%= minicomputer# ,uring the =J@s other minicomputer models such as
VA3 models running VM* implemented !irtual memories#
Virtual memory was introduced to the 2O architecture with the protected mode
of the Intel O@4O processor# At first it was done with segment swapping which
-ecomes inefficent as segments get larger# )ith the Intel O@DO comes support
for paging which lay under segmentation# $he page fault e2ception could -e
chained with other e2ceptions without causing a dou-le fault#
Compilers
A diagram of the operation of a typical multi%language multi%target compiler#
A compiler is a computer program 'or set of programs( that translates te2t
written in a computer language 'the source language( into another computer
language 'the target language(# $he original se?uence is usually called the
source code and the output called o-8ect code# Commonly the output has a form
suita-le for processing -y other programs 'e#g# a linker( -ut it may -e a human
reada-le te2t file#
$he most common reason for wanting to translate source code is to create an
e2ecuta-le program# $he name "compiler" is primarily used for programs that
translate source code from a high le!el language to a lower le!el language 'e#g#assem-ly language or machine language(# A program that translates from a low
le!el language to a higher le!el one is a decompiler# A program that translates
-etween high%le!el languages is usually called a language translator source to
source translator or language con!erter# A language rewriter is usually a
program that translates the form of e2pressions without a change of language#
A compiler is likely to perform many or all of the following operations; le2ing
preprocessing parsing semantic analysis code optimi/ations and code
Linker
-
7/27/2019 Computing and Informatics
32/34
Figure of the linking process where o-8ect files and static li-raries are assem-led
into a new li-rary or e2ecuta-le#
In computer science a linker or link editor is a program that takes one or more
o-8ects generated -y compilers and assem-les them into a single e2ecuta-le
program#
In IBM mainframe en!ironments such as 9*7D@ this program is known as a
linkage editor#
'9n ni2 !ariants the term loader is often used as a synonym for linker# Because
this usage -lurs the distinction -etween the compile%time process and the run%
time process this article will use linking for the former and loading for the latter#(
$he o-8ects are program modules containing machine code and information for
the linker# $his information comes mainly in the form of sym-ol definitions which
come in two !arieties;
& ,efined or e2ported sym-ols are functions or !aria-les that are present in the
module represented -y the o-8ect and which should -e a!aila-le for use -y
other modules# & ndefined or imported sym-ols are functions or !aria-les that
are called or referenced -y this o-8ect -ut not internally defined#
In short the linker.s 8o- is to resol!e references to undefined sym-ols -y finding
out which other o-8ect defines a sym-ol in ?uestion and replacing placeholders
with the sym-ol.s address#
Linkers can take o-8ects from a collection called a li-rary# *ome linkers do notinclude the whole li-rary in the output they only include its sym-ols that are
referenced from other o-8ect files or li-raries# Li-raries for di!erse purposes
e2ist and one or more system li-raries are usually linked in -y default#
$he linker also takes care of arranging the o-8ects in a program.s address space#
$his may in!ol!e relocating code that assumes a specific -ase address to
another -ase# *ince a compiler seldom knows where an o-8ect will reside it often
assumes a fi2ed -ase location 'for e2ample /ero(# 0elocating machine code may
in!ol!e re%targeting of a-solute 8umps loads and stores#
$he e2ecuta-le output -y the linker may need another relocation pass when it isfinally loaded into memory '8ust -efore e2ecution(# 9n hardware offering !irtual
memory this is usually omitted thoughHe!ery program is put into its own
address space so there is no conflict e!en if all programs load at the same -ase
address#
Assem-ler
$ypically a modern assem-ler creates o-8ect code -y translating assem-ly
instruction mnemonics into opcodes and -y resol!ing sym-olic names for
memory locations and other entities# $he use of sym-olic references is a key
feature of assem-lers sa!ing tedious calculations and manual address updates
after program modifications# Most assem-lers also include macro facilities for
-
7/27/2019 Computing and Informatics
33/34
performing te2tual su-stitution H e#g# to generate common short se?uences of
instructions to run inline instead of in a su-routine#
Assem-lers are generally simpler to write than compilers for high%le!el
languages and ha!e -een a!aila-le since the =5@s# '$he first assem-lers in
the early days of computers were a -reakthrough for a generation of tiredprogrammers#( Modern assem-lers especially for 0I*C -ased architectures such
as MI+* *un *+A0C and 6+ +A%0I*C optimi/e instruction scheduling to e2ploit
the C+ pipeline efficiently#
More sophisticated 6igh%le!el assem-lers pro!ide language a-stractions such as;
& Ad!anced control structures & 6igh%le!el procedure7function declarations and
in!ocations & 6igh%le!el a-stract data types including structures7records
unions classes and sets & *ophisticated macro processing
Note that in normal professional usage the term assem-ler is often usedam-iguously; It is fre?uently used to refer to an assem-ly language itself rather
than to the assem-ler utility# $hus; "C+7CM* was written in *7D@ assem-ler" as
opposed to "A*M%6 was a widely%used *7DJ@ assem-ler#"
$he C Compilation Model
)e will -riefly highlight key features of the C Compilation model here#
$he +reprocessor
)e will study this part of the compilation process in greater detail later 'Chapter
=D# 6owe!er we need some -asic information for some C programs#
$he +reprocessor accepts source code as input and is responsi-le for
& remo!ing comments & interpreting special preprocessor directi!es denoted -y
S#
For e2ample
& Sinclude %% includes contents of a named file# Files usually called header files#
e#g o Sinclude math#hb %% standard li-rary maths file# o Sinclude stdio#hb %%
standard li-rary I79 file & Sdefine %% defines a sym-olic name or constant# Macro
su-stitution# o Sdefine MA3A00A*IE =@@
C Compiler
$he C compiler translates source to assem-ly code# $he source code is recei!ed
from the preprocessor#
Assem-ler
-
7/27/2019 Computing and Informatics
34/34
$he assem-ler creates o-8ect code# 9n a NI3 system you may see files with a #o
suffi2 '#9BP on M*,9*( to indicate o-8ect code files#