1ComputerSystemOverviewChapter12BasicElementsofComputerProcessorMainMemoryVolatile(易失的),referredtoasrealmemoryorprimarymemoryI/Omodulessecondarymemorydevices(辅助存储设备)communicationsequipmentTerminals(终端)Systembuscommunicationamongprocessors,memory,andI/Omodules3ComputerComponents:Top-LevelView4ProcessorRegisters(寄存器)Memoryaddressregister(MAR)SpecifiestheaddressforthenextreadorwriteMemorybufferregister(MBR)ContainsdatawrittenintomemoryorreceivesdatareadfrommemoryI/OaddressregisterI/Obufferregister5ProcessorRegistersUser-visibleregistersEnableprogrammertominimizemain-memoryreferencesbyoptimizingregisteruseControlandstatusregistersUsedbyprocessortocontroloperatingoftheprocessorUsedbyprivilegedoperating-systemroutinestocontroltheexecutionofprograms6User-VisibleRegisters(1)MaybereferencedbymachinelanguageAvailabletoallprograms-applicationprogramsandsystemprogramsTypesofregistersDataAddressIndexSegmentpointerStackpointer7User-VisibleRegisters(2)AddressRegistersIndexInvolvesaddinganindextoabasevaluetogetanaddressSegmentpointerWhenmemoryisdividedintosegments,memoryisreferencedbyasegmentandanoffsetStackpointerPointstotopofstack8ControlandStatusRegisters(1)ProgramCounter(PC,程序计数器)ContainstheaddressofaninstructiontobefetchedInstructionRegister(IR)ContainstheinstructionmostrecentlyfetchedProgramStatusWord(PSW,程序状态字)ConditioncodesInterruptenable/disableSupervisor/usermode9ControlandStatusRegisters(2)ConditionCodesorFlagsBitssetbytheprocessorhardwareasaresultofoperationsExample:arithmeticoperationPositiveresultNegativeresultZeroOverflow10InstructionExecution(指令执行)TwostepsProcessorreadsinstructionsfrommemoryProcessorexecuteseachinstructionInstructioncycle(指令周期)11InstructionFetchandExecuteTheprocessorfetchestheinstruction(取指令)frommemoryProgramcounter(PC,程序计数器)holdsaddressoftheinstructiontobefetchednextProgramcounterisincrementedaftereachfetch12InstructionRegisterFetchedinstructionisplacedintheinstructionregister(指令寄存器)Categoriesofactions:Processor-memory(处理器和内存之间)TransferdatabetweenprocessorandmemoryProcessor-I/O(处理器和I/O设备之间)Datatransferredtoorfromaperipheraldevice(外部设备)DataprocessingArithmetic(算术)orlogicoperationondataControlAltersequence(顺序)ofexecution13CharacteristicsofaHypotheticalMachine14ExampleofProgramExecution15Interrupts(中断)MostI/OdevicesareslowerthantheprocessorProcessormustpausetowaitfordeviceInterruptthenormalsequencingoftheprocessorInterruptsareprovidedprimarilyasawaytoimproveprocessorutilization16ClassesofInterrupts17ProgramFlowofControlWithoutInterrupts18ProgramFlowofControlWithInterrupts,ShortI/OWait19ProgramFlowofControlWithInterrupts,LongI/OWait20InterruptHandler(中断服务程序)ProgramtoserviceaparticularI/OdeviceGenerallypartoftheoperatingsystemInterruptServiceRoutine(ISR,中断服务程序)21InterruptsSuspends(挂起)thenormalsequenceofexecution22InterruptCycle23InterruptCycleProcessorchecksforinterruptsIfnointerruptsfetchthenextinstructionforthecurrentprogramIfaninterruptispending,suspendexecutionofthecurrentprogram,andexecutetheinterrupt-handlerroutine24TimingDiagramBasedonShortI/OWait25TimingDiagramBasedonShortI/OWait26SimpleInterruptProcessing27ChangesinMemoryandRegistersforanInterrupt28ChangesinMemoryandRegistersforanInterrupt29MultipleInterruptsDisableinterruptswhileaninterruptisbeingprocessed30MultipleInterruptsDefinepriorities(优先级)forinterrupts31MultipleInterrupts32Multiprogramming(多道)ProcessorhasmorethanoneprogramtoexecuteThesequencetheprogramsareexecuteddependontheirrelativepriorityandwhethertheyarewaitingforI/OAfteraninterrupthandlercompletes,controlmaynotreturntotheprogramthatwasexecutingatthetimeoftheinterrupt33MemoryHierarchy(存储层次)Fasteraccesstime,greatercostperbitGreatercapacity,smallercostperbitGreatercapacity,sloweraccessspeed34MemoryHierarchy35GoingDowntheHierarchyDecreasingcostperbitIncreasingcapacityIncreasingaccesstimeDecreasingfrequencyofaccessofthememorybytheprocessorLocalityofreference36SecondaryMemory(辅助存储器)UsedtostoreprogramanddatafilesNonvolatile(非易失的)Auxiliarymemory(辅助存储)37DiskCache(磁盘高速缓存)AportionofmainmemoryusedasabuffertotemporarilytoholddataforthediskDiskwritesareclusteredSomedatawrittenoutmaybereferencedagain.Thedataareretrievedrapidlyfromthesoftwarecacheinsteadofslowlyfromdisk38CacheMemory(高速缓存)InvisibletooperatingsystemIncreasethespeedofmemoryProcessorspeedisfasterthanmemoryspeedExploittheprincipleoflocality39CacheMemoryContainsacopyofaportionofmainmemoryProcessorfirstcheckscacheIfnotfoundincache,theblockofmemorycontainingtheneededinformationismovedtothecacheanddeliveredtotheprocessor40Cache/MainMemorySystem41CacheReadOperation42CacheDesignCachesizeSmallcacheshaveasignificantimpactonperformanceBlocksizeTheunitofdataexchangedbetweencacheandmainmemoryLargerblocksizemorehitsuntilprobabilityofusingnewlyfetcheddatabecomeslessthantheprobabilityofreusingdatathathavetobemovedoutofcache43CacheDesignMappingfunctionDetermineswhichcachelocationtheblockwilloccupyReplacementalgorithmDetermineswhi