版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
LevelsofHighLevelProgramHighLevelProgram(e.g.,AssemblyAssemblyProgram(e.g.,
Anythingcanbeasanumber,i.e.,dataorMachineMachineLanguageProgram(MIPS)(e.g.,blockLogicCircuit(CircuitSchematic 內(nèi)容主要取材:CS61C的5?機(jī)器語(yǔ)寄存判斷航空航天大學(xué)計(jì)算機(jī)內(nèi)容主要取材:CS61C的5?寄存判斷航空航天大學(xué)計(jì)算機(jī)MachineLanguage“Word”acomputerunderstands:Vocabularyofall“words”acomputerunderstands:instructionsetarchitecture(ISA)WhymightyouwantthesameISA?WhymightyouwantdifferentISAs? andiPadusethe andMacbookuse Summer2012--Lecture MachineLanguageSingleLeveragecommoncompilers,operatingsystems,BUTfairlyeasytoretargetthesefordifferentISAs(e.g.Linux,gcc)MultipleSpecializedinstructionsforspecializedDifferenttradeoffsinresourcespowerconsumption,etc.)Competitionandinnovationisgood,especiallyinemergingenvironments(e.g.mobiledevices) Summer2012--Lecture WhyStudyLearntowritemorecompactandefficientCansometimeshandoptimizebetterthanaMoresensibleforminimalistice.g.distributedsensingandEliminatingOS,compilers,etc.reducesizeandpowerconsumptionEmbeddedcomputersoutnumber Summer2012--Lecture ReducedInstructionSetTheearlytrendwastoaddmoreandmoreinstructionstodoelaborateoperations–thisbecameknownasComplexInstructionSetComputing(CISC)OppositephilosophylaterbegantoReducedInstructionSetComputingSimpler(andsmaller)instructionsetmakesiteasiertobuildfasthardwareLetsoftwaredothecomplicatedoperationsbycomposingsimpleronesphilosophy/哲 Summer Lecturephilosophy/哲RISCDesignBasicRISCprinciple:“AsimplerCPU(thehardwarethatmachinelanguage)isafasterCPU”(CPU→FocusoftheRISCdesignisreductionofthenumberandcomplexityofinstructionsintheISAAnumberofthemorecommonstrategiesFixedinstructionlength,generallyasingleSimplifiesprocessoffetchinginstructionsfromSimplifiesprocessoffetchingoperandsfromFewerandsimplerinstructionsintheinstructionOnlyloadandstoreinstructionsaccessLetthecompilerdoit.Useagoodcompilertobreakcomplexhigh-levellanguagestatementsintoanumberofsimpleassemblylanguage Spring2012--Lecture Mainstream UsedinMacbooksandFoundinCorei3,Corei5,Corei7,AdvancedRISCMachine ,iPad,iPod,ThemostpopularRISC(20xmorecommonthanAirborneequipment:FlightControl,Radar,EngineEmbeddeddevcies:Networkswitch/router,airborne/航 Summer Lectureairborne/航
InstructionSetinCSInventedbyJohnHennessy@(WhynotBerkeley/SunRISCinventedbyDavePatterson?Askhim!)MIPSisarealworldStandardinstructionsetfornetworkingElegantexampleofReducedInstructionSetComputer(RISC)instructionset Spring2012--Lecture 內(nèi)容主要取材:CS61C的5?判斷航空航天大學(xué)計(jì)算機(jī)FiveComponentsofaWebeginourstudyofhowacomputerRegistersarepartofthe Summer2012--Lecture ComputerHardwareInhigh-levellanguages,numberofvariableslimitedonlybyavailablememoryISAshaveafixed,smallnumberofoperandscalledregistersSpeciallocationsbuiltdirectlyintoBenefit:RegistersareEXTREMELYFAST(fasterthan1billionthofasecond)Drawback:Operationscanonlybeperformedonthesepredeterminednumberofregistersoperand/操作 Summer Lectureoperand/操作MIPSMIPShas32Eachregisteris32bitswideandholdaTradeoffbetweenspeedandSmallernumbermeansfasterhardwarebutinsufficienttoholddatafortypicalCprogramsRegistershavenotype(Cconcept);theregistercontentsaretreatedavailability/ Summer Lecture availability/MIPSRegisterdenotedby‘$’canbereferencedbynumber($0-$31)orname:Registersthatholdprogrammer Registersthatholdtemporary
You’lllearnabouttheother14registersIngeneral,usingregisternamesmakescodemorereadable Summer2012--Lecture 內(nèi)容主要取材:CS61C的5?判斷航空航天大學(xué)計(jì)算機(jī)MIPSInstructionSyntaxisopdst,src1,1operator,3op=operationnamedst=registergettingresultsrc1=firstregisterforoperation(“sourcesrc2=secondregisterforoperation(“sourcesyntax/語(yǔ)法rigid/固定的operator/操作符syntax/語(yǔ)法rigid/固定的operator/操作符regularity/MIPSOneoperationperinstruction,atmostoneinstructionperlineAssemblyinstructionsarerelatedtoCoperations(=,+,-,*,/,&,|,etc.)Mustbe,sinceC posesintoAsinglelineofCmaybreakupintoseverallinesofMIPS Summer2012--Lecture MIPSInstructions(assumeherethatthevariablesa,b,andcareassignedregisters$s1,$s2,and$s3,IntegerAddition a=b+ add$s1,$s2,IntegerSubtraction a=b- sub$s1,$s2, Summer2012--Lecture MIPSInstructionsSupposea→$s0,b→$s1,c→$s2,d→$s3,ande→$s4.ConvertthefollowingCstatementtoMIPS:a=(b+c)–(d+Utilizetemporary Summer2012--Lecture CommentsinCommentsinMIPSfollowhashmark(#)untiltheendoflineImprovesreadabilityandhelpsyoukeeptrackof### Summer2012--Lecture TheZeroZeroappearssooftenincodeandissousefulthatithasitsownregister!Registerzero($0or$zero)alwayshasthevalue0andcannotbechanged!i.e.anyinstructionwith$0asdsthasnoExample–add#–add# Summer2012--Lecture NumericalconstantsarecalledSeparateinstructionsyntaxforopidst,src,–Operationnamesendwith‘i’,replace2ndsourceregisterwithanimmediate(checkGreenSheetforun/signed)Example–addi5#–addi1#Whynosubi Summer2012--Lecture 內(nèi)容主要取材:CS61C的5?判斷航空航天大學(xué)計(jì)算機(jī)FiveComponentsofaregisters(Datapath)andMemoryAllowustofetchandstoreoperandsinStoreLoadSummer2012--LectureDataCvariablesmapontoWhataboutlargedatastructureslikeDon’tforgetmemory,ourone-dimensionalarrayindexedbyaddressesstartingat0SpecializeddatatransferinstructionsmovedatabetweenregistersandmemoryStore:registerTOLoad:registerFROM Summer2012--Lecture DataInstructionsyntaxfordataopreg,op=operationnamereg=registerforoperationsourceorbAddr=registerwithpointertomemory(“baseoff=addressoffset(immediate)inbytesReminder:Aregisterholdsawordofrawdata(notype)–makesuretousearegister(andoffset)thatpointtoavalidmemoryaddress Summer2012--Lecture MemoryisByte-WhatwasthesmallestdatatypewesawinAchar,whichwasabyte(8Everythinginmultiplesof8bits(e.g.1word=4bytes)Memoryaddressesareindexedbybytes,notwordsWordaddressesare4bytesWordaddrissameasleft-most
Addroflowestbyte…………5670…………5670123Offsetsaremultiplesof4tobe“word-PointerarithmeticnotdoneforyouinMusttakedatasizeintoaccount Summer2012--Lecture DataTransferLoadWordTakesdataataddressbAddr+offFROMmemoryandplacesitintoregStoreWordTakesdatainregandstoresitTOmemoryatExample#addrofintA[]->$s3,a->### Summer2012--Lecture Registersvs.WhatifmorevariablesthanKeepmostfrequentlyusedinregistersandmovetheresttomemory(calledspillingtomemory)WhynotallvariablesinSmallerisfaster:registers100-500timesRegistersmoreIn1arithmeticinstruction:read2operands,performoperation,and1In1datatransferinstruction:1read/write, Summer2012--Lecture GreatIdea#3:PrincipleofLocality/MemoryHierarchyQuestion:Whichofthefollowingisadd$t0,$t1,4($t2)isvalidCanbyteaddress8GBwithaMIPSoffoffmustbeamultipleof4lw$t0,off($s0)tobeCharsandRecall:AstringisjustanarrayofcharactersandacharinCuses8-bitASCIIMethod1:Movewordsinandoutofmemoryusingbit-maskingandshifting andi$s0,$s0,0xFF#lowestMethod2:Load/storebyte Offsetsnolongertobemultiplesof Summer2012--Lecture Bytelb/sbutilizetheleastsignificantbyteoftheOnsb,upper24bitsareOnlb,upper24bitsarefilledbysign-Forexample,let*($s0)= ###Normallyyoudon’twanttosign-extend–Uselbu(loadbyte Summer2012--Lecture BigEndian:Most-significantbyteatleastaddressofwordaddress=addressofmostsignificantLittleEndian:Least-significantbyteatleastaddressofwordaddress=addressofleastsignificant little big MIPSisbi-endian(cangoeitherUsingMARSsimulatorinlab,whichislittleWhyisthisDatastoredinreverseorderthanyouwriteitData storedas04030201in
LectIreasing 內(nèi)容主要取材:CS61C的5?判斷航空航天大學(xué)計(jì)算機(jī)ComputerDecisionInC,wehadcontrol esofcomparative/logicalstatementsdeterminedwhichblocksofcodetoexecuteInMIPS,wecan’tdefineblocksofcode;allwehavearelabelsDefinedbytextfollowedbyacolon(e.g.main:)andreferstotheinstructionthatfollowsGenerateflowcontrolby Chasthesetoo,buttheyareconsideredbad Summer2012--Lecture DecisionMakingBranchIfEqualbeqIfvalueinreg1=valueinreg2,gotoBranchIfNotEqualbneIfvalueinreg1≠valueinreg2,gotoJumpjUnconditionaljumpto Summer2012--Lecture BreakingDowntheIfCif(i==j)a= /*then}elsea=-b/*else}InIfTRUE,executetheTHENIfFALSE,executetheELSE
MIPS#i→$s0,j→$s1#a→$s2,beqThislabelsub$s2,$0,$s3 add$s2,$s3,$0 Summer2012--Lecture BreakingDowntheIfCif(i==j)a= /*then}elsea=-b/*else}InIfTRUE,executetheTHENIfFALSE,executetheELSE
MIPS#i→$s0,j→$s1#a→$s2,bneadd$s2,$s3,$0 sub$s2,$0,$s3 Summer2012--Lecture LoopsinTherearethreetypesofloopsinwhile,do…while,andEachcanberewrittenaseitheroftheothertwo,sothesameconceptsofdecision-makingapplyYouwillexaminehowtowritetheseinMIPSinKeyConcept:ThoughtherearemultiplewaystowritealoopinMIPS,thekeytodecision-makingistheconditionalbranch Summer2012--Lecture ComputersunderstandtheinstructionsoftheirISARISCDesignSmallerisfaster,keepitMIPSRegisters:$s0-$s7,$t0-$t9,MIPSData
add,sub,addilw,sw,lb,sb,lbubeq,bne,j Summer2012--Lecture Youareresponsibleforthematerialcontainedonthefollowingslides,thoughwemaynothaveenoughtimetogettotheminlecture.Theyhavebeenpreparedinawaythatshouldbeeasilyreadableandthematerialwillbetoucheduponinthefollowinglecture. Summer2012--Lecture 測(cè)試:2種寫(xiě)法的區(qū)測(cè)試:2種寫(xiě)法的區(qū)別while(*p*q++=*p++Let’sputourallofournewMIPSknowledgetouseinanexample:“FastStringCopy”Ccodeisas/*Copystringfromptoq*/char*p,*q;while((*q++=*p++)!=‘\0’)WhatdoweknowaboutitsCtoMIPSStartwithcode#copyStringpto#p→$s0,q→$s1
j
#$t0=*p#*q=$t0#p=p+1#q=q+#if*p==0,goto#goto Summer2012--Lecture CtoMIPS?Fillin#copyStringpto#p→$s0,q→$s1 #$t0= #*q=addi#p=p+addi#q=q+beq#if*p==0,gotoj#gotoSummer2012--LectureCtoMIPS#copyStringpto#p→$s0,q→$s1 #$t0= #*q=addi#p=p+addibeq#q=q+#if*p==0,goj#goto#NcharsinpN*6 Summer2012--Lecture CtoMIPSAlternatecodeusing#copyStringpto#p→$s0,q→$s1Loop:lb $t0,0($s0)#$t0=*p $t0,0($s1)#*q=$t0addi$s0,$s0,1 #p=p+1addi #q=q+bne$t0,$0,Loop#if*p!=0,goto#Ncharsinp=>N*5 Summer2012--Lecture MIPSArithmeticThefollowingcommandsplaceresultsinthespecialregistersHIandLOAccessthesevalueswith“movefrom(mfhidst)and“movefromLO”(mfloMultiplicationmultsrc1*src2:lower32-bitsinLO,upper32-bitsinDivisiondivsrc1/src2:putsquotientinLO,remainderin Summer2012--Lecture MIPSArithmetic#modusingdiv:$s2=$s0mod#=#=$s0 Summer2012--Lecture ArithmeticRecall:Overflowoccurswhenthereisamistakeinarithmeticduetothelimitedprecisionincomputers–i.e.notenoughbitstorepresentanswerMIPSdetectsoverflow(throwsArithmetic“unsigned”instructionsignoreOverflowNoOverflowaddiaddiu Summer2012--Lecture Arithmetic
Recall:thisisthemostnegative# , $t0,$s0,$s0#overflow(error)addu$t1,$s0,$s0#$t1
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 《基于SPH方法的SLM過(guò)程三維數(shù)值模擬數(shù)學(xué)模型的建立》
- 《未成年人刑事案件合適成年人參與制度研究》
- 2023年西安高新區(qū)魚(yú)化寨社區(qū)衛(wèi)生服務(wù)中心招聘筆試真題
- 2023年河北廊坊燕京職業(yè)技術(shù)學(xué)院選聘專任教師筆試真題
- 2023年安徽省生態(tài)環(huán)境產(chǎn)業(yè)集團(tuán)有限公司招聘筆試真題
- 2024年臨桂縣人民醫(yī)院高層次衛(wèi)技人才招聘筆試歷年參考題庫(kù)頻考點(diǎn)附帶答案
- 快樂(lè)假期安全第一
- 橋梁下部工程勞務(wù)分包合同模板
- 鐘點(diǎn)工清潔合同
- 墊資合同范本
- 【部編】人教版六年級(jí)上冊(cè)道德與法治全冊(cè)知識(shí)點(diǎn)總結(jié)梳理
- 網(wǎng)絡(luò)設(shè)備駐場(chǎng)運(yùn)維服務(wù)方案
- 【幼兒的不良飲食習(xí)慣及影響因素探究11000字(論文)】
- 六年級(jí)趣味數(shù)學(xué)思維拓展題50道及答案
- 靜脈治療護(hù)理小組職責(zé)
- 第六章《發(fā)展與合作》課件-2024-2025學(xué)年人教版初中地理七年級(jí)上冊(cè)
- 醫(yī)院感染監(jiān)測(cè)規(guī)范
- 風(fēng)險(xiǎn)分級(jí)管控和隱患排查治理體系培訓(xùn)考試試題(附答案)
- 項(xiàng)目四任務(wù)1:認(rèn)識(shí)毫米波雷達(dá)(課件)
- 四川省住宅設(shè)計(jì)標(biāo)準(zhǔn)
- 中央空調(diào)設(shè)備采購(gòu)及安裝合同
評(píng)論
0/150
提交評(píng)論