DOC PREVIEW
Princeton COS 217 - Assembler

This preview shows page 1-2-3-4-5 out of 16 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 16 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 16 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 16 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 16 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 16 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 16 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

1AssemblerCS217CompilationPipeline• Compiler(gcc):.c  .stranslateshigh-levellanguagetoassemblylanguage• Assembler(as):.s  .otranslatesassemblylanguagetomachinelanguage• Archiver(ar):.o  .acollectsobjectfilesintoasinglelibrary• Linker(ld):.o + .a  a.outbuildsanexecutablefilefromacollectionofobjectfiles• Execution(execlp)loadsanexecutablefileintomemoryandstartsit2CompilationPipelineCompilerAssemblerArchiverLinker/LoaderExecution.c.s.o.aa.outAssembler• PurposeTranslatesassemblylanguageintomachinelanguageStoreresultinobjectfile(.o)• AssemblylanguageAsymbolicrepresentationofmachineinstructions• MachinelanguageContainseverythingneededtolink,load,andexecute theprogram3Translatingtomachinecode• Assemblylanguage: addcc %r3,%r7,%r2• addcc %r3,1000,%r2• Machinelanguage:0 unused(0) rs2rd op3 rs11031 29 24 18 13 12 4 01 simm13rd op3 rs11031 29 24 18 13 12 0000000000 0011100010010000000111031 29 24 18 13 12 4 01000111110100000010010000000111031 29 24 18 13 12 0AssemblyLanguage• Assemblylanguagestatements…declarativestatements specifyassemblytimeactions;e.g.,reservespace,definesymbols,identifysegments,andinitializedata(theydonotyieldmachineinstructionsbuttheymayaddinformationtotheobjectfilethatisusedbythelinker)imperativestatements specifyinstructions;typicallymap1imperativestatementto1machineinstructionsyntheticinstructions aremappedtooneormoremachineinstructions4MainTask• Mostimportantfunction:symbolmanipulationCreatelabelsandremembertheiraddresses• Forwardreferenceproblemloop:cmpi,n .section“.text”bgedone setcount,%l0nop ...... .section“.data”inci count:.word0done:Dealingwithforwardreferences• MostassemblershavetwopassesPass1:symboldefinitionPass2:instructionassembly• Or,alternatively,Pass1:instructionassemblyPass2:patchthecross-reference5Dealingwithforwardreferences• MostassemblershavetwopassesPass1:symboldefinitionPass2:instructionassembly• Or,alternatively,Pass1:instructionassemblyPass2:patchthecross-referencePass1• Stateloc(locationcounter);initially0symtab (symboltable);initiallyempty• Foreachlineofinput.../*Updatesymboltable*/iflinecontainsalabelenter<label,loc>intosymtab/*Updatelocationcounter*/iflinecontainsadirectiveadjustlocaccordingtodirectiveelseloc+=length_of_instruction6Pass2• Statelc (locationcounter);resetto0symtab (symboltable);filledfrompreviouspass• Foreachlineofinput/*Outputmachinelanguagecode*/iflinecontainsadirectiveprocess/outputdirectiveelseassemble/outputinstructionusingsymtab/*Updatelocationcounter*/iflinecontainsadirectiveadjustlocaccordingtodirectiveelseloc+=length_of_instructionExampleassembly.globallooploop:cmp%r16,%r24bge donenopcallfnopba loopinc%r16done:opdisp30:?......0≥≥≥≥010 disp22:?000always010 disp22:?004:8:12:16:20:24:0:28:.........7ExamplePass1.globallooploop:cmp%r16,%r24bge donenopcallfnopba loopinc%r16done:loop0defdone4disp22loop20disp22done28deff12disp30loopdoneExamplePass2.globallooploop:cmp%r16,%r24bge donenopcallfnopba loopinc%r16done:4:8:12:16:20:24:0:28:loop0defdone4disp22loop20disp22done28deff12disp30loopdoneopdisp30:?......0≥≥≥≥010 +24000always010 -2000.........8Relocationrecords.globallooploop:cmp%r16,%r24bge donenopcallfnopba loopinc%r16done:opdisp30:?......0≥≥≥≥010 +24000always010 -20004:8:12:16:20:24:0:28:.........loop0deff12disp30Dealingwithforwardreferences• MostassemblershavetwopassesPass1:symboldefinitionPass2:instructionassembly• Or,alternatively,Pass1:instructionassemblyPass2:patchthecross-reference9InstructionAssembly.globallooploop:cmp%r16,%r24bge donenopcallfnopba loopinc%r16done:opdisp30:?......0≥≥≥≥010 disp22:?000always010 disp22:?004:8:12:16:20:24:0:28:.........PatchingCross-References.globallooploop:cmp%r16,%r24bge donenopcallfnopba loopinc%r16done:4:8:12:16:20:24:0:28:loop0defdone4disp22loop20disp22done28deff12disp30loopdoneopdisp30:?......0≥≥≥≥010 +24000always010 -2000.........10ImplementinganAssembler.s fileinstructioninstructioninstructioninstruction.o fileinputassemble outputsymboltabledatasectiontextsectionbsssectiondisk inmemorystructurediskinmemorystructureInputFunctions• ReadassemblylanguageandproducelistofinstructionsThesefunctionsareprovided.s fileinstructioninstructioninstructioninstruction.o fileinputassemble outputsymboltabledatasectiontextsectionbsssection11InputFunctions• LexicalanalyzerGroupastreamofcharactersintotokensadd%g1,10,%g2• SyntacticanalyzerCheckthesyntaxoftheprogram<MNEMONIC><REG><COMMA><REG><COMMA><REG>• InstructionlistproducerProduceanin-memorylistofinstructiondatastructuresinstructioninstructionYourTaskinAssignment5• ImplementtwopassassemblerProcesslistofinstructionstoproduceobjectfileoutputstructures.s fileinstructioninstructioninstructioninstruction.o fileinputassemble outputsymboltabledatasectiontextsectionbsssection12PackingfieldsusingC• Assemblylanguage: addcc %r3,%r7,%r2•• Formatofarithmeticinstructions:0 unused(0) rs2rd op3 rs11031 29 24 18 13 12 4 0000000000


View Full Document

Princeton COS 217 - Assembler

Documents in this Course
Summary

Summary

4 pages

Lecture

Lecture

4 pages

Generics

Generics

14 pages

Generics

Generics

16 pages

Lecture

Lecture

20 pages

Debugging

Debugging

35 pages

Types

Types

7 pages

Lecture

Lecture

21 pages

Lecture

Lecture

20 pages

Lecture

Lecture

39 pages

Testing

Testing

44 pages

Pipeline

Pipeline

19 pages

Lecture

Lecture

6 pages

Signals

Signals

67 pages

Building

Building

17 pages

Lecture

Lecture

7 pages

Modules

Modules

12 pages

Generics

Generics

16 pages

Testing

Testing

22 pages

Signals

Signals

34 pages

Lecture

Lecture

19 pages

Load more
Download Assembler
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Assembler and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Assembler 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?