




版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
復旦大學信息科學與 共6 考試形式:√開卷□閉 2007年6專 學 成—二—二三四五 int int Supposetheabovecodegeneratesthefollowingassemblycode:pushl%ebppushl%ebxmovl8(%ebp),%ecxmovl12(%ebp),%ebxleal(%ecx,%ecx,6),%edxsall$2,%edxmovl%ebx,%eaxsall$3,%eaxsall$3,%eaxmovlarray2(%eax,%ecx,4),%eaxmovl%eax,array1(%edx,%ebx,4)popl%ebxpopl%ebp((裝訂線內不要答題)復旦大學信息科學與 共6 考試形式:√開卷□閉 2007年6(120分鐘,答案必須寫在試卷上,做在草稿紙上無效專 學 成 —二三四五Problem1.Considerthesourcecodebelow.Manreconstantsdeclaredwith#define.intarray1[M][N];intarray2[N][M];{}Supposetheabovecodegeneratesthefollowingassemblycode:pushl%ebppushl%ebxsall$2,%edxmovl%ebx,%eaxsall$3,%eaxsubl%ebx,%eaxsall$3,%eaxmovlarray2(%eax,%ecx,4),%eaxmovl%eax,array1(%edx,%ebx,4)popl%ebxmovl%ebp,%esppopl%ebpM N-1M N-1ProblemConsiderthefollowingassemblyrepresentationofafunctionfoocontainingaforpushl%ebpmovl%esp,%ebppushl%ebxmovl8(%ebp),%ebxleal4(%ebx),%edxxorl%ecx,%ecxcmpl%ebx,%ecxjlleal2(%ecx,%edx,2),%edxleal4(%ecx),%eaximull%eax,%edxl%ecxcmpl%ebx,%ecxjge.L6movl%edx,%eaxpopl%ebxmovl%ebp,%esppopl%ebpBasedontheassemblycodeabove,fillintheblanksbelowinitscorrespondingCsourcebelow—donotuseregisternames.)Fillintheblankstoprovidethefunctionalityoftheintfoo(int{intintresult= for( ; ;i++) }return}-2ProblemConsiderthefollowingassemblyrepresentationofafunctionfoocontainingaforpushl%ebppushl%ebxxorl%ecx,%ecxcmpl%ebx,%ecxjl.L4leal4(%ecx),%eaxl%ecxjge.L6popl%ebxpopl%ebpBasedontheassemblycodeabove,fillintheblanksbelowinitscorrespondingCsourcecode.(Note:youmayonlyusethesymbolicvariablesi,a,andresultinyourexpressionsbelow—donotuseregisternames.)Fillintheblankstoprovidethefunctionalityoftheintfoo(int{intintresult ;i++);;}return}-2ProblemConsiderthefollowingfunctionforcomputingtheproductofanarrayofnintegers.Wehaveunrolledtheloopbyafactorof3.intaprod(inta[],int{inti,x,y,z;intr=1;for(i=0;i<n-2;i+=3)x=a[i];y=a[i+1];z=r=r*x*y*z;//Product}for(;i<n;r*=a[i];returnr;}ForthelinelabeledProductcomputation,wecanuseparenthesestocreate5differentassociationsofthecomputation,asfollows:r=((r*x)*y)*z;//A1r=(r*(x*y))*z;//A2r=r*((x*y)*z);//A3r=r*(x*(y*z));//A4r=(r*x)*(y*z);//Weexpresstheperformanceofthefunctionintermsofthenumberofcyclesperelement(CPE).Asdescribedinthebook,thismeasureassumestheruntime,measuredlockcycles,foranarrayoflengthnisafunctionoftheformCn+K,whereCistheCPE.Wemeasuredthe5versionsofthefunctiononanInPentiumIII.Recallthattheintegermultiplicationoperationonthismachinehasalatencyof4cyclesandanissuetimeof1ThefollowingtableshowssomevaluesoftheCPE,andothervaluesmissing.ThemeasuredCPEvaluesarethosethatwereactuallyobserved.“TheoreticalCPE”meansthatperfor-mancethatwouldbeachievediftheonlylimitingfactorwerethelatencyandissuetimeoftheintegermultiplier.MeasuredTheoretical4/3=8/3=Fillinthemissingentries.ForthemissingvaluesofthemeasuredCPE,youcanusethevaluesfromotherversionsthatwouldhavethesamecomputationalbehavior.ForthevaluesofthetheoreticalCPE,youcandetermhenumberofcyclesthatwouldberequiredforanitionconsideringonlythelatencyandissuetimeofthemultiplier,andthendivideby-3ProblemConsiderthefollowingfunctionforcomputingtheproductofanarrayofnintegers.Wehaveunrolledtheloopbyafactorof3.intaprod(inta[],int{inti,x,y,z;intr=1;for(i=0;i<n-2;i+=3)x=a[i];y=a[i+1];z=r=r*x*y*z;//Product}for(;i<n;r*=a[i];returnr;}ForthelinelabeledProductcomputation,wecanuseparenthesestocreate5differentassociationsofthecomputation,asfollows:r=((r*x)*y)*z;//A1r=(r*(x*y))*z;//A2r=r*((x*y)*z);//A3r=r*(x*(y*z));//A4r=(r*x)*(y*z);//A5Weexpresstheperformanceofthefunctionintermsofthenumberofcyclesperelement(CPE).Asdescribedinthebook,thismeasureassumestheruntime,measuredlockcycles,foranarrayoflengthnisafunctionoftheformCn+K,whereCistheCPE.Wemeasuredthe5versionsofthefunctiononanInPentiumIII.Recallthattheintegermultiplicationoperationonthismachinehasalatencyof4cyclesandanissuetimeof1ThefollowingtableshowssomevaluesoftheCPE,andothervaluesmissing.ThemeasuredCPEvaluesarethosethatwereactuallyobserved.“TheoreticalCPE”meansthatperfor-mancethatwouldbeachievediftheonlylimitingfactorwerethelatencyandissuetimeoftheintegermultiplier.MeasuredTheoretical4/3=8/3=Fillinthemissingentries.ForthemissingvaluesofthemeasuredCPE,youcanusethevaluesfromotherversionsthatwouldhavethesamecomputationalbehavior.ForthevaluesofthetheoreticalCPE,youcandetermhenumberofcyclesthatwouldberequiredforanitionconsideringonlythelatencyandissuetimeofthemultiplier,andthendividebyProblemConsidertheCprogrambelow.(Forspacereasons,wearenotcheckingerrorreturncodes,soassumethatallfunctionsreturnnormally.)intmain()if(fork()==0)if(fork()==0)}elsepid_tpid;intif((pid=wait(&status))>0){}}}else}return0;}Foreachofthefollowingstrings,circlewhether(Y)ornot(N)thisstringisapossibleoutputoftheprogram.A.YNB.YNC.YND.YNE.YN-4-3ProblemThefollowingproblemconcernsdynamicstorage locatorthatusesanimplicit list.Thelayoutofeachallocatedandmemoryblockisasfollows: 21 BlockSize BlockSize Eaemoryblock,eitherallocatedor,hasasizethatisamultipleofeightbytes.Thus,onlythe29higherorderbitsintheheaderandfooreneededtorecordblocksize,ludestheheaderandfooter.Theusageoftheremaining3lowerorderbitsisasbit0indicatestheuseofthecurrentblock:1forallocated,0 bit1indicatestheuseofthepreviousadjacentblock:1forallocated,0 bit2isunusedandisalwayssettobeFivehelperroutinesaredefinedtofacilitatetheimplementationof (void*p).Thefunctionalityofeachroutineiinedinthecommentabovethefunctiondefinition.Fillinthebodyofthehelperroutinesthecodesectionlabelthatimplementthecorrespondingfunctionalitycorrectly./*givenapointerpto locatedblock,i.e.,pisapointerreturnedbysomepreviousmalloc()/realloc()call;returnsthepointertotheheaderoftheblock*/void*header(void*{void returnptr;}ptr=(void*)((int*)p-ptr=(void*)((int*)p-/*givenapointertoavalidblockheaderorfooter,returnsthesizeoftheblock*/-5ProblemConsidertheCprogrambelow.(Forspacereasons,wearenotcheckingerrorreturncodes,soassumethatallfunctionsreturnnormally.)intmain()if(fork()==0)if(fork()==0)}elsepid_tpid;intif((pid=wait(&status))>{}}}else}return0;}Foreachofthefollowingstrings,circlewhether(Y)ornot(N)thisstringisapossibleoutputoftheprogram.A.YNB.YNC.YND.YNE.YNintsize(void{int returnresult;}result=((*(charresult=(*(int/*givenapointerp locatedblock,i.e.papointerreturnedbysomepreviousmalloc()/realloc()call;returnsthepointertothefooteroftheblock*/void*footer(void{void returnptr;}/*givenapointertoavalidblockheaderorfooter,returnstheusageofthecurrectblock,1forallocated,0for intallocated(void*hp){int return}result=(*(intresult=(*(int/*givenapointertoavalidblockreturnsthepointertotheheaderofpreviousblockinmemory*/void*prev(void*hp){void returnptr;}ptr=hp-ptr=hp-size(hp-ptr=hp-size(hp-4)+-6-4ProblemThefollowingproblemconcernsdynamicstorageConsiderlocatorthatusesanimplicitlist.Thelayoutofeachallocatedandmemoryblockisasfollows: 21||||||||||||||||||||||||Eaemoryblock,eitherallocatedor,hasasizethatisamultipleofeightbytes.Thus,onlythe29higherorderbitsintheheaderandfooreneededtorecordblocksize,whichludestheheaderandfooter.Theusageoftheremaining3lowerorderbitsisasfollows:bit0indicatestheuseofthecurrentblock:1forallocated,0 bit1indicatestheuseofthepreviousadjacentblock:1forallocated,0 bit2isunusedandisalwayssettobeFivehelperroutinesaredefinedtofacilitatetheimplementationof (void*p).Thefunctionalityofeachroutineiinedinthecommentabovethefunctiondefinition.Fillinthebo
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 花卉種養殖管理制度
- 茶企業公司管理制度
- 草莓園室內管理制度
- 觀感質量驗收標準
- 讓流動的花兒綻放-潁泉區北京路一小“關愛流動兒童”案例
- 財務會計工作計劃 (五)
- 課程建設方案
- 行政監督之案例分析
- VMware虛擬化成功案例
- 第一講 案例(中國好聲音 餐飲團購)
- 低壓電工證考試試題及答案
- 2025年大學生學術研究洞察報告
- 2025年廣東中考化學模擬演練化學試卷B(含答案)
- 2025春學期三年級語文下冊教學工作總結 (三篇)
- 2025年全國二卷數學高考真題文字版
- 成都香城悅動置業有限公司招聘考試真題2024
- 2025年成都市初中學業水平考試道德與法治試題(含答案)
- 浙江省寧波2025年八年級下學期期末數學試題及答案
- T/CTRA 01-2020廢輪胎/橡膠再生油
- 可信數據空間解決方案星環科技
- 2025-2030IVD原酶料市場發展態勢剖析及未來需求趨勢預測研究報告
評論
0/150
提交評論