Python Programming: An Introduction to Computer Science

(Nora) #1
1.4.HARDWAREBASICS 3

Input Devices

CPU

Secondary
Memory
Main Memory

Output Devices

Figure1.1:FunctionalView ofa Computer.

analysis.Formostproblems,thebottom-lineis whethera working,reliablesystemcanbebuilt.Oftenwe
requireempiricaltestingofthesystemtodeterminethatthisbottom-linehasbeenmet.Asyoubeginwriting
yourownprograms,youwillgetplentyofopportunitiestoobserve yoursolutionsinaction.


1.4 HardwareBasics


Youdon’t have toknow allthedetailsofhow a computerworkstobea successfulprogrammer, butunder-
standingtheunderlyingprincipleswillhelpyoumasterthestepswegothroughtoputourprogramsinto
action.It’s a bitlike drivinga car. Knowinga littleaboutinternalcombustionengineshelpstoexplainwhy
youhave todothingslike fillthegastank,starttheengine,stepontheaccelerator, etc. Youcouldlearn
todrive byjustmemorizingwhattodo,buta littlemoreknowledgemakesthewholeprocessmuchmore
understandable.Let’s take a momentto“lookunderthehood”ofyourcomputer.


Althoughdifferentcomputerscanvarysignificantlyinspecificdetails,at a higherlevel allmoderndigital
computersareremarkablysimilar. Figure1.1showsa functionalview ofa computer. Thecentralprocessing
unit(CPU)is the“brain”ofthemachine.Thisis whereallthebasicoperationsofthecomputerarecarried
out. TheCPUcanperformsimplearithmeticoperationslike addingtwo numbersandcanalsodological
operationslike testingtoseeif two numbersareequal.


Thememorystoresprogramsanddata.TheCPUcanonlydirectlyaccessinformationthatis storedin
mainmemory(calledRAMforRandomAccessMemory). Mainmemoryis fast,but it is alsovolatile.Thatis,
whenthepoweris turnedoff, theinformationin thememoryis lost.Thus,theremustalsobesomesecondary
memorythatprovidesmorepermanentstorage.Ina modernpersonalcomputer, thisis usuallysomesortof
magneticmediumsuchasa harddisk(alsocalleda harddrive) orfloppy.


Humansinteractwiththecomputerthroughinputandoutputdevices. Youareprobablyfamiliarwith
commondevicessuchasa keyboard,mouse,andmonitor(videoscreen).Informationfrominputdevicesis
processedbytheCPUandmaybeshuffledoff to themainorsecondarymemory. Similarly, wheninformation
needstobedisplayed,theCPUsendsit tooneormoreoutputdevices.


Sowhathappenswhenyoufireupyourfavoritegameorwordprocessingprogram?First,theinstructions
thatcomprisetheprogramarecopiedfromthe(more)permanentsecondarymemoryintothemainmemory
ofthecomputer. Oncetheinstructionsareloaded,theCPUstartsexecutingtheprogram.


TechnicallytheCPUfollowsa processcalledthefetch executecycle. Thefirstinstructionis retrieved
frommemory, decodedtofigureoutwhatit represents,andtheappropriateactioncarriedout.Thenthenext
instructionis fetched,decodedandexecuted.Thecyclecontinues,instructionafterinstruction.Thisis really
allthecomputerdoesfromthetimethatyouturnit onuntilyouturnit off again:fetch,decode,execute.It
doesn’t seemveryexciting,doesit?Butthecomputercanexecutethisstreamofsimpleinstructionswith
blazingspeed,zippingthroughmillionsofinstructionseachsecond.Putenoughsimpleinstructionstogether
injusttherightway, andthecomputerdoesamazingthings.

Free download pdf