One-pass structure definition must occur before any uses (that is, uses can have only backward references to definitions) examples: macro definition before.

Slides:



Advertisements
Similar presentations
Pointers.
Advertisements

Symbol Table.
Chapter 10 Linking and Loading. Separate assembly creates “.mob” files.
Introduction to Computing Systems from bits & gates to C & beyond Chapter 7 LC-2 Assembly Language.
The Assembly Language Level
Chapter 3 Loaders and Linkers
Chapter 3 Loaders and Linkers. Purpose and Function Places object program in memory Linking – Combines 2 or more obj programs Relocation – Allows loading.
Macro Processor.
Machine Independent Assembler Features
Assembler Design Options
Assembly Process. Machine Code Generation Assembling a program entails translating the assembly language into binary machine code This requires more than.
Chih-Hung Wang Chapter 2: Assembler (Part-1) 參考書目 Leland L. Beck, System Software: An Introduction to Systems Programming (3rd), Addison-Wesley, 1997.
Assembler – Assembler Design Options. One-Pass Assemblers (1/2) Main problem  Forward references Data items Labels on instructions Solution  Data items:
Tutorial 6 & 7 Symbol Table
CS2422 Assembly Language & System Programming December 22, 2005.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 17: Linked Lists.
Assemblers Dr. Monther Aldwairi 10/21/20071Dr. Monther Aldwairi.
Software Development Process Compiler Linker C File Asm. File Binary File Exec. File Assemble r Library Implementation Phase Debugger Profiler Verification.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 13 Disk Storage, Basic File Structures, and Hashing.
Chapter 3: Arrays, Linked Lists, and Recursion
Assembler When a source program is a assembly language and the target program is a numerical machine language then the translator is called as a assembler.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 17 Disk Storage, Basic File Structures, and Hashing.
A Simple Two-Pass Assembler
MIPS coding. SPIM Some links can be found such as:
Assembler Design Options
Assemblers.
Machine Independent Macro Processor Features Concatenation of Macro Parameters Generation of Unique Labels Conditional Macro Expansion Keyword Macro.
COMPILERS Symbol Tables hussein suleman uct csc3003s 2007.
CPS4200 System Programming 2007 Spring 1 Systems Programming Chapter 2 Assembler II.
One Pass with Fixup One-pass structure definition must occur before any uses (that is, uses can have only backward references to definitions) examples:
5-1 Chapter 5 - Languages and the Machine Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Principles.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Memory: Relocation.
Ass. Prof. Dr Masri Ayob TK 6123 Lecture 13: Assembly Language Level (Level 4)
Computer Science 210 Computer Organization More on Assembler.
Department of Computer Science Data Structures Using C++ 2E Chapter 5 Linked Lists.
2 : Assembler 1 Chapter II: Assembler Chapter goal: r Introduce the fundamental functions that any assembler must perform. m Assign machine address m Translate.
File Structures. 2 Chapter - Objectives Disk Storage Devices Files of Records Operations on Files Unordered Files Ordered Files Hashed Files Dynamic and.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide
3 Data. Software And Data Data Data element – a single, meaningful unit of data. Name Social Security Number Data structure – a set of related data elements.
Machine Independent Assembler Features
Data Structures Using C++1 Chapter 5 Linked Lists.
Loader and Linker.
Assembler Design Options One-Pass and Multi-Pass Assemblers.
Circular linked list A circular linked list is a linear linked list accept that last element points to the first element.
The Assembly Process Computer Organization and Assembly Language: Module 10.
Virtual Memory Pranav Shah CS147 - Sin Min Lee. Concept of Virtual Memory Purpose of Virtual Memory - to use hard disk as an extension of RAM. Personal.
Linked list: a list of items (nodes), in which the order of the nodes is determined by the address, called the link, stored in each node C++ Programming:
Linking Loader untuk SIC/XE Machine. Lebih Lanjut mengenai Absolute Loader Shortcoming of an absolute loader –Programmer needs to specify the actual address.
Chapter - 2 Data strucuters for Language processing.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 17: Linked Lists.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 18: Linked Lists.
LECTURE 3 Translation. PROCESS MEMORY There are four general areas of memory in a process. The text area contains the instructions for the application.
CC410: System Programming Dr. Manal Helal – Fall 2014 – Lecture 11–Macro-Processors.
CC410: System Programming Dr. Manal Helal – Fall 2014 – Lecture 9 - Assembler 4.
Lecture 3 Translation.
Computer Science 210 Computer Organization
Review Deleting an Element from a Linked List Deletion involves:
Intermediate code generation Jakub Yaghob
Chapter 9 : Assembler Design Options
Assembler Design Options
Assembler Design Options
Computer Science 210 Computer Organization
MACRO Processors CSCI/CMPE 3334 David Egle.
Chapter 7 LC-2 Assembly Language.
Disk Storage, Basic File Structures, and Hashing
Assembler Design Options
Chapter 7 LC-2 Assembly Language.
A Simple Two-Pass Assembler
Optional Assembler Features 2
Symbol Table 薛智文 (textbook ch#2.7 and 6.5) 薛智文 96 Spring.
Presentation transcript:

One-pass structure definition must occur before any uses (that is, uses can have only backward references to definitions) examples: macro definition before macro calls variable declarations before uses

Two-pass structure uses can have forward or backward references to definitions first pass collects the definitions into a table (e.g., symbol table) second pass accomplishes the translation by consulting the definition table whenever a use is encountered only the table is required to remain in memory; the source file can be read from disk twice example: traditional assembler

One-pass with fixup structure also known as back-patching the translated code as well as the definition table both need to be kept in memory algorithm for assembler label(x) // x defined at location blt0(y) // y used at location beq0(y) // y used at location label(y) // y defined at location 25

One-pass with fixup structure In one-pass-with-fixup, the symbol table needs a third field (in addition to the symbol name and address fields). The third field indicates whether the symbol is defined or undefined.

One-pass with fixup structure When you encounter the use of a symbol, perform a lookup in the symbol table: a)if the symbol is defined, use the address value from the entry

One-pass with fixup structure... xdef10... yundef... 15NULL use-location node b)if the symbol is not yet present, add an entry for this symbol and mark it as undefined; use the address field in the entry as a pointer to a linked list of use locations for this undefined symbol and add the address of the current word to the first node, e.g.

One-pass with fixup structure c)if the symbol is present but undefined, add another node to the linked list with the address of the current word in that node, e.g.,... yundef 20 15NULL... Note that you can extend the use-location nodes to contain an indicator for what type of fixup is needed, e.g., full-word value, high 22 bits, low 10 bits, etc.

One-pass with fixup When you encounter the definition of a symbol, perform a lookup in the symbol table: a)if the symbol is already defined, you have encountered a "multiple definition" error b)if the symbol is not yet present, add an entry for this symbol and mark it as defined; use the current value of the location counter as the address

One-pass with fixup... xdef10... ydef25... c)if the symbol is present but undefined, "fix up" or "back patch" all the undefined uses by traversing the linked list and storing the current value of the location counter into the memory words identified in the nodes of the list; then free the list and mark the symbol as defined using the current value of the location counter as the address, e.g., symbol type address

One-pass with fixup When you reach the end of the assembly language program, scan the symbol table for any remaining undefined entries. These are either errors or, absent a requirement to explicitly mark the use of external names, these are symbols that must be passed to the linker to be resolved. To visualize this, consider the actions of the assembler as it moves through a possible source program:

One-pass with fixup start translation use x... // forward reference - insert "x" into the // symbol table as an undefined symbol and // start a linked list of use locations use x... // forward reference - add this use location // to the linked list define x... // traverse the linked list and fixup all // forward references with the value of the // definition, then mark "x" as a defined // symbol and store the defining value use x... // backward reference - resolve by table lookup define x... // multiply-defined symbol error!... end translation // check for undefined symbols

Numeric local labels in a two-pass structure Numeric local labels in a two-pass structure (a relaxation of the prohibition on multiply-defined symbols) (adapted from the GNU description) Local labels help programmers use names temporarily. They are numeric symbols that can be redefined at various points in a program, but each valid use of a local label has a unique definition to which it refers. To define a local label for our chapter 1 assemblers, write a label with a number label( )

Numeric local labels in a two-pass structure label( ) To refer to the most recent previous definition of that symbol write b, using the same number as when you defined the label. To refer to the next definition of a local label, write f. The "b" stands for "backward", and the "f" stands for "forward". Prior to the first definition of label, the reference b is undefined; likewise, after the last definition of label, the reference f is undefined.

Numeric local labels in a two-pass structure Prior to the first definition of label, the reference b is undefined; likewise, After the last definition of label, the reference f is undefined. Local labels are useful in the bodies of macro definitions so that you do not need macro expansion counters to generate unique labels.

Numeric local labels in a two-pass structure Consider the following example code with two definitions of label "1": assembly code location generated code and data label(start) ba(1f) 70 2 label(1) ba(1f) 70 4 label(1) ba(x) 70 8 label(1) ba(start) 70 0 label(x) halt 0 end(1b) 6 Note that in the first branch the target address "1f" is resolved to 2, but in the second branch the target address "1f" is resolved to 4.

Numeric local labels in a two-pass structure For the above assembly code, the first pass of a two-pass assembler builds a symbol table with a local/global flag and a linked list of definitions from each local entry: 1local*undef*2* 4 *6 *undef* startglobal0= x 8 The three definitions of the local label "1" in the example code above are recorded in the linked list in the symbol table with the locations 2, 4, and 6, respectively, along with header and trailer nodes that specify that the location is undefined.

Numeric local labels in a two-pass structure During the second pass, the assembler removes the head node from a local label's list whenever a redefinition of that local label is encountered. Thus, because there are three definitions of "1" in the above code, by the end of the second pass only two nodes (the location-6 node and the undefined-trailer node) remain in the linked list for "1". With the removal of the head node when encountering a (re- )definition, the rules for resolving a local label "1b" of "1f" during the second pass are: "1b" - use the value from the first node in the linked list for "1" "1f" - use the value from the second node in the linked list for "1"

Numeric local labels in a two-pass structure To visualize this, consider how the linked list would be modified as the assembler moves through the example source code on the second pass: /* at beginning of second pass, "1" has list (undef,2,4,6,undef) */ 0: label(start) ba(1f) 70 2 // "1f" resolves to 2 2: label(1) // redefine "1", so "1" now // has list (2,4,6,undef) ba(1f) 70 4 // "1f" resolves to 4 4: label(1) // redefine "1", so "1" now // has list (4,6,undef) ba(x) : label(1) // redefine "1", so "1" now // has list (6,undef) ba(start) : label(x) halt 0 9: end(1b) 6 // "1b" resolves to 6