Download presentation
Presentation is loading. Please wait.
Published byPranav Wittie Modified over 9 years ago
1
1 Lecture 25 (Assemblers)
2
2 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
3
3 * 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 Code Generator ScannerParser
4
4 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
5
5 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.
6
6 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
7
7 * 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)
8
8 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
9
9 - 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
10
10 Other Features Branch Tensioning - Eliminate jumps to jumps Bookkeeping - Directives -Data storage
11
11 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
12
12 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)
13
13 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
14
14 * 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
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.