140 likes | 336 Views
Lecture 25 (Assemblers). Assemblers,Linkers,and Debuggers. Assembler -Translates assembly to machine code. - Resolves symbolic address. - Extends virtual machine with additional instruction . Similar to compiler in structure
E N D
Assemblers,Linkers,and Debuggers • Assembler -Translates assembly to machine code. - Resolves symbolic address. - Extends virtual machine with additional instruction . • Similar to compiler in structure -Translation process simpler since it is usually one-to-one
* Each input instruction produces one output instruction - Generally make two passes over code * First pass finds the labels and counts instructions * Second pass actually produces code File.s File.o Scanner Parser Code Generator
Types of Addresses • Two types of addresses -Relative addresses * Distance from known point e.g. bneq s2,s3,44 - Absolute addresses * Complete memory address e.g. load s4,xxx
Assembler can fully resolve relative addresses by counting instructions - However ,doesn’t know where everything goes in memory * Linker resolves absolute addresses. * file.o contains of unresolved addresses for linker.
Extending the Virtual Machine • Assembler can provide instructions and not supported by hardware . • Delayed branches and loads . -Instructions take two cycles,but in next instruction started in second cycle * Cannot use result of load in second cycle lw s4,5(s7) add s3,s5,s6
* Instruction after branch executed beq s1,s2,foo add s3,s4,s5 - How does system present delayed instructions? * Inform programmers and compiler writers about it and let them handle it (SPARC) *Hide from programmers by letting assembler rearrange code to put useful instruction in slots (MIPS)
Extended VM, cont’d • Filling delay slot after load -Find Instruction from same basic block (executed under the same conditions) -Instruction can’t produce address for load or use its result -Cannot move instruction ahead of other one that uses its value • Pseudo instructions extend instructions provided by hardware
- Assembler produces short code sequences for pseudo instructions * e.g. blt s2,s3,label bge s2,s3,xxx j label xxx: * div s2,s3,s4 bneq s3,xxx trap xxx:divu s3,s4 mfhi s2
Other Features • Branch Tensioning - Eliminate jumps to jumps • Bookkeeping - Directives -Data storage
Linkers • Collect code from object files and produce executable program - Scan each object file to find list of unresolved addresses and lay out code and data in memory -can the libraries to find referenced routines - make another pass over the code to fix up unresolved addresses
Can be tricky - May not know instruction size in first pass - la s2,foo li s2,foo lui s2,%hi(foo) ori s2,s2,%lo(foo)
Debuggers • Simple debuggers only give view of assembly language (adb) -Don’t know about language satements,data types, or variables - e.g. SPIM debugger • Source level debuggers - Compiler and includes detailed information in object file * Which source files produced assembly file
* Where each statement begins and ends * Where local variables are stored * Where global variables are stored * Types of variables * Descriptions of stack frames -Information stored at end of executable file * Doesn’t make program larger - Compiler may not do as much optimization