Introduction to Windows as a PlatformWord文档格式.docx
《Introduction to Windows as a PlatformWord文档格式.docx》由会员分享,可在线阅读,更多相关《Introduction to Windows as a PlatformWord文档格式.docx(14页珍藏版)》请在冰豆网上搜索。
Company:
ContentMasterLtd
Introduction
TheVisualStudioExpressEditionsfamilyprovidesafree,lightweight,andeasy-to-learnsuiteofprogrammingtoolsthatareaimedatthehobbyist,novice,andstudentdeveloper.Manypeopleinthiscategorywillnothavehadanyformaltrainingincomputerscience,andindeedtheymaynothaveanyprogrammingexperienceatall.Ifyoufallintothiscategory,don’tworry–thisguideisforyou!
Thisbeginner’sguideisdesignedforpeoplewithlittleornopriorknowledgeofcomputerprogramming,whowanttocreatecomputerprogramswiththeVisualStudioExpresstools.Ifyoualreadyhavesignificantprogrammingexperience,thenyouwillprobablynothavemuchtolearnfromthisarticle.
So,whatwillyoulearnbyreadingthroughthisguide?
Well,ifyouwanttowriteaprogramthatyoucanrunonyourMicrosoftWindowscomputer,thisguidewillintroduceyoutothefundamentalconceptsthatwillhelpyouunderstandhowtodojustthat.Youwilllearntheanswertoquestionssuchas:
∙Howdoesacomputerwork?
∙What’sthedifferencebetweenhardwareandsoftware?
∙What’sanOperatingSystem?
∙Howdoesacomputerrunmyprogram?
∙Whatarethecomponentpartsofaprogram?
ThepurposeofthisguideistohelpyouunderstandtheenvironmentinwhichaMicrosoftWindowsprogramruns.Thewaythataprogramworksisaffectedbymanyfactorsincludingthecomputerthatitrunson,theoperatingsystem,andthewaythatpeoplewillusetheprogram.Theenvironmentofacomputerprogramiscalleditsplatform.Whenyouunderstandtheprogrammingenvironment,youwillbeabletoappreciatehowthecomputerinterpretsyourprograms,andasaresult,learningtoprogramwillbecomeeasierandultimatelyyou’llwritebetterprograms.
ThisguidedescribestheMicrosoftWindowsplatformasaprogrammingenvironment.ItappliestoprogramsthatrunonWindowsandareusedbypeoplethatrunMicrosoftWindows–thesearecalledWindowsapplications.Ifyouwanttowriteanapplicationthatpeoplewillaccessbyusingthroughtheirbrowser,thenyouneedtocreateaWebapplication,notaWindowsapplication.Inthatcase,youshouldreadthecompanionguide“IntroductiontoWebasaplatform”,whichprovidesinformationabouttheWorldWideWebasanapplicationplatform.
HowComputersWork
Althoughcomputersconsistofadvancedtechnologicalcomponents,thebasicwayacomputeroperatesisverysimple,andhaschangedverylittlesincetheinventionofelectroniccomputersinthemiddleofthetwentiethcentury.Acomputercontainsthreemainfunctionalareas:
∙Input/Output.Thisreferstoanydeviceattachedtothecomputerthatprovidesameansofinteractionorcommunicationbetweenthecomputerandthe‘outsideworld’(fromthecomputer’sperspective).Examplesofinputdevicesincludethekeyboard,mouse,andjoystick.Examplesofoutputdevicesincludethemonitor,printerandsoundcard.
∙Memory.Thisisthepartofthecomputerthatprovidesinformationstorage.Acomputer’smemoryisdividedintomanythousandsofsmallunitscalledbytes.Allthedatathatacomputermanagesisstoredasoneormorebytes.Youcanimaginethesebytesasslotsorpigeonholes,eachwithitsownmemorylocationoraddressthatthecomputerusestofetchandstoredata,similartoaroomfullofPostOfficeboxes.Each‘box’orbytecontainsanumberthatthecomputercanprocess.
∙CentralProcessingUnit.TheCentralProcessingUnit(CPU)isthe‘brain’ofthecomputer,whichperformsallcalculationsandco-ordinatestheoperationofthememoryandinput/outputdevices.
TheInstructionCycle
AcomputeroperatesbycopyingbytesfromthememoryoraninputdeviceontotheCPU,performingsomecalculationsonthosebytes,andthencopyingtheresultofthecalculationstothememoryoranoutputdevice.Thisprocesscontinuesinacycleasshownbelow:
Forthiscycleofdataprocessingtobeuseful,thecomputerneedstohaveinstructionsthattellitwhattoreadandwrite,andwhichcalculationstoperform.TheseinstructionstelltheCPUwhatmemorylocationtoreadfrom(fetchingdatafrommemory)orwriteto(storingdatatomemory),andwhichinputoroutputdevicestoaccess.(Lateroninthisarticleyouwillseehowcomputermemorycanholdinformationthatrepresentsexternalentitiessuchasimagesorsound.)
Theinstructionsthatacomputerrunsaresimplynumberslikeanyotherdata,andtheyarestoredinthecomputer’smemory.TheCPUalwayskeepsaninternalrecordofwhichmemorylocation(address)containsthenextinstructionthatitwillexecute.Whenitcompletesoneinstruction,itreadsthenextinstructionfrommemory,andupdatesitsrecordtopointtotheinstructionafterthat.Afterithasupdateditsrecord,itcanprocesstheinstructionthatithasjustreadfrommemory.
SoacomputerprogramisjustaseriesofbytesthatcontaininstructionsfortheCPU.Whenthecomputerrunstheprogram,itmovessequentiallythroughthesetofinstructionbytes,loadingeachinstructionontotheCPU,performingthatinstruction,andthengoingbacktofetchthenextinstructionontotheCPU.TheprogramitselfdoesnotalwaysneedtotelltheCPUtomovetothenextinstruction–thishappensautomatically.
However,instructionscanalsotelltheCPUtomodifyitsinternalrecordsothatitwillreadthenextinstructionfromadifferentaddress.Theseinstructions,called‘jump’instructions,enablethecomputertoperformdifferentactionsdependingonthecircumstances.Let’shavealookathowinstructionsworkinsideacomputer,bytakingsomeexampleinstructionsandseeinghowthecomputerusesthem.
ThediagramdepictsseveralbytesofcomputermemorythatcontainCPUinstructions(inthelowersection)anddata(intheuppersection).
Inthelowersectionofmemorydepicted,thenumericalvaluesoftheCPUinstructionsaredisplayedinbluetext.AlongsidethenumericalvalueisamnemonicrepresentationoftheCPUinstructionsinsemi-readabletext.
Startingwiththelowestmemorylocation(atthebottomofthediagram)andreadingupwards,theCPUinstructionstelltheCPUtoperformthefollowingactions:
read[8000]
Readthevaluefromaddress8000intotheCPU.
sub100
Subtract100fromthevalueintheCPU(theresultofthesubtractionreplacesthevaluejustreadintotheCPU).
cmp121
ComparethecurrentvalueintheCPUto121.
jne+8
IftheCPUvalueisnotequal(jnestandsforJumpNotEqual),jumpforwardby8bytesfromthecurrentinstruction(toaddress2020)andcontinuebyexecutingtheinstructioncontainedatthatmemorylocation.
IftheCPUvalueisequalto121,thentheCPUwouldnotjump,anditwouldcontinuetoreaditsinstructionsfromthenextsequentialmemorylocation,whichis2016inthisexample.
jmp[2038]
Jumptoaddress2038andcontinuebyexecutingtheinstructioncontainedatthatmemorylocation.
write[8842]
WritethevalueintheCPUtomemorylocation8842.
Phew!
Ittakesquitealeapofimaginationtoseehowallthisnumberprocessingcouldenableacomputertoperformalltheactionsthatweusefromdaytoday,likewordprocessingorbrowsingtheInternet.Hangon–you’rethroughthemostcomplicatedpart,butyoustillneedabitmoreinformationtohelpyoumaketheleap.
Challenge:
Asaquickchallenge,seeifyoucanworkoutwhatwillhappenintheexampleabove.Assumingthatthevalueatmemorylocation8000containsthevalue221,workthroughtheCPUinstructionsandanswerthefollowingquestions:
∙Whatvaluegetswrittentomemorylocation8842?
∙Whatvaluegetswrittentomemorylocation8878?
Youcanfindtheanswersattheendofthisarticle.
InputandOutputDevices
Ifacomputersimplyprocessedinstructionsinmemory,itwouldnotserveanyusefulpurpose.Inordertobeuseful,thecomputerneedstoprovideawaytoenabletheusertoindicatewhatcalculationstoperform,andtodisplaytheresultsofitscalculations–tointeractwiththecomputer.
Interactionwithacomputertakesplacethroughcomponentscalledinput/outputdevices.Forexample,akeyboardisaninputdevice,becausethecomputercanreadfromthekeyboardtoseewhenakeyispressed.Fromthecomputer’sperspective,thekeypressisinformationthatiscomingin.Conversely,amonitorisanoutputdevice,becausethecomputersendsinformationouttothedisplayasaresultofitscalculations.
Youmaywonderhowthecomputercaninteractwiththesedevices,whenallitdoesiscopybytesfromoneplacetoanotherplace.Theansweristhatalltheinputandoutputinformationcanberepresentedasbytes.Forexample,eachkeyonthekeyboardhasitsownnumericvaluesothecomputercanidentifythekeyandstorethenumberinamemorylocation.
Lessobviously,theinformationdisplayedonyourmonitorrightnowisjustaseriesofbytestothecomputer.Eachdot(pixel)onthescreenisrepresentedbysomebytesthatindicatewhatcolortodisplayonthemonitoratthatpixel.
Infact,everythingthatacomputerdisplaysorstoresisasetofbytes,calledadigitalrepresentation–whetheritisaphoto,avideo,asong,orevenawordprocessingdocument.Ifyou’veeverseenthemovieTheMatrix,you’llrecognizetheimageofgreen0’sand1’scascadingdownablackscreen.Thisimageactuallyhassometruthtoit,sinceacomputerseesalldataasrepresentedbynumbers.Thetranslationbetweenwhatacomputerseesandwhatweseeonourmonitorsorasaprintoutisdonebytheinput/outputdevices.
Thejobofthecomputer’sinput/outputdevicesistoperformtheseconversionsbetweenth