资源描述:
《编译原理2E全套配套课件龙书 Chapter_eight(3).ppt》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、COMPILERCONSTRUCTIONPrinciplesandPracticeKennethC.Louden8.CodeGenerationContentsPartOne8.1IntermediateCodeandDataStructureforcodeGeneration8.2BasicCodeGenerationTechniquesPartTwo8.3CodeGenerationofDataStructureReference8.4CodeGenerationofControlStatementsandLogicalExpression8.5CodeGenera
2、tionofProcedureandFunctioncallsPartThree8.6CodeGenerationonCommercialCompilers:TwoCaseStudies8.7TM:ASimpleTargetMachine8.8ACodeGeneratorfortheTINYLanguage8.9ASurveyofCodeOptimizationTechniques8.10SimpleOptimizationsforTINYCodeGenerator8.6CodeGenerationinCommercialCompilers:TwoCaseStudies
3、Borland’sCCompilerfor80X86Sun’sCCompilerforSparcStationsForexample,ConsidertheCprocedureVoidf(intx,charc){inta[10];doubley;…}OffsetofxfpOffsetofcOffsetofaOffsetofyTheactivationrecordforacalltofwouldappearasxcControllinkReturnaddressa[9]…a[1]a[0]yNameOffsetx+5c+4a-24y-32Assumingtwobytesfo
4、rintegers,fourbytesforaddresses,onebyteforcharacterandeightbytesfordouble-precisionfloatingpoint,wewouldhavethefollowingoffsetvalues:Now,anaccessofa[i],wouldrequirethecomputationoftheaddress:(-24+2*i)(fp)Fortheexpression:(x=x+3)+4,thep-codeandthree-addresscode:LadxLodxLdc3Adit1=x+3Stnx=t
5、1Ldc4Adit2=t1+48.6.1TheBorland3.0CCompilerforthe80X86Considertheexamplesoftheoutputofthiscompilerwiththefollowingassignment(x=x+3)+4TheassemblycodeforthisexpressionasproducedbytheBorland3.0compilerfortheIntel80x86isasfollows:movax,wordptr[bp-2]addax,3movwordptr[bp-2],axaddax,4Notes:Thebp
6、isusedastheframepointer.Thestaticsimulationmethodisusedtoconverttheintermediatecodeintothetargetcode.Fortheexpression:(x=x+3)+4,Thep-codeandthree-addresscode:LadxLodxLdc3Adit1=x+3Stnx=t1Ldc4Adit2=t1+41)ArrayReferenceAnexample:(a[i+1]=2)+a[j]Assumethatij,andaarelocalvariablesdeclaredasint
7、i,j;inta[10];TheBorlandCcompilergeneratesthefollowingassemblycodefortheaboveexpression(innextpage)Expression:(a[i+1]=2)+a[j](1)movbx,wordptr[bp-2](2)shlbx,1(3)leaax,wordptr[bp-22](4)addbx,ax(5)movax,2(6)movwordptr[bx],ax(7)movbx,wordptr[bp-4](8)shlbx,1(9)leadx,wordptr[bp-