




下載本文檔
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
LevelsofHighLevelProgramHighLevelProgram(e.g.,AssemblyAssemblyProgram(e.g.,
Anythingcanbeasanumber,i.e.,dataorMachineMachineLanguageProgram(MIPS)(e.g.,blockLogicCircuit(CircuitSchematic 內(nèi)容主要取材:CS61C的5?機器語寄存判斷航空航天大學計算機內(nèi)容主要取材:CS61C的5?寄存判斷航空航天大學計算機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?判斷航空航天大學計算機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?判斷航空航天大學計算機MIPSInstructionSyntaxisopdst,src1,1operator,3op=operationnamedst=registergettingresultsrc1=firstregisterforoperation(“sourcesrc2=secondregisterforoperation(“sourcesyntax/語法rigid/固定的operator/操作符syntax/語法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?判斷航空航天大學計算機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?判斷航空航天大學計算機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 測試:2種寫法的區(qū)測試:2種寫法的區(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. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年男士護理項目立項申請報告范文
- 月光下的古鎮(zhèn)夜晚寫景演講稿(5篇)
- 2025-2026學年四川省綿陽市部分學校高一上學期開學分班檢測英語試題(解析版)
- 2025安徽蕪湖市國有資本投資運營有限公司招聘10人模擬試卷及答案詳解(名師系列)
- 魯濱遜漂流記的啟示與勇氣7篇
- 2025廣東惠州市惠陽區(qū)教育局選調(diào)下屬事業(yè)單位工作人員15人考前自測高頻考點模擬試題及完整答案詳解一套
- 循環(huán)經(jīng)濟領(lǐng)域資源回收承諾書7篇
- 先進技術(shù)運用服務保障承諾書9篇
- 咖啡烘焙品質(zhì)保障承諾書4篇
- 古董修復技術(shù)保證承諾書(6篇)
- 客運管理工作
- 人教版小學三年級數(shù)學上冊各單元測試卷含答案全套
- 初中地理跨學科主題學習設(shè)計與實施
- 人教版一年級上冊數(shù)學期中試卷(共5套-可直接打印)
- CVD 碳化硅涂層產(chǎn)品技術(shù)要求
- 2024版以房抵債協(xié)議范本
- 馬克思主義制度經(jīng)濟理論知到智慧樹章節(jié)測試課后答案2024年秋上海財經(jīng)大學
- 【部編】人教版六年級上冊道德與法治全冊知識點總結(jié)梳理
- 社區(qū)居家養(yǎng)老服務設(shè)計方案范文
- JT-T-1180.2-2018交通運輸企業(yè)安全生產(chǎn)標準化建設(shè)基本規(guī)范第2部分:道路旅客運輸企業(yè)
- 中國省市縣行政區(qū)劃
評論
0/150
提交評論