考試試題csapp examb卷裝訂線內不要答題_第1頁
考試試題csapp examb卷裝訂線內不要答題_第2頁
考試試題csapp examb卷裝訂線內不要答題_第3頁
考試試題csapp examb卷裝訂線內不要答題_第4頁
考試試題csapp examb卷裝訂線內不要答題_第5頁
已閱讀5頁,還剩11頁未讀 繼續免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

復旦大學信息科學與 共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. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論