Assembler Design Options

Slides:



Advertisements
Similar presentations
The 8051 Microcontroller and Embedded Systems
Advertisements

The Assembly Language Level
Chapter 3 Loaders and Linkers
Macro Processor.
Machine Independent Assembler Features
The assembler is the system program that translate source code written in assembly language to object code( Machine Language) and other information for.
Assembler Design Options
System Software Chih-Shun Hsu
Assembler design.
Chapter 6: Machine dependent Assembler Features
CPS4200 System Programming 2007 Spring 1 Systems Programming Chapter 2 Assembler I.
CS2422 Assembly Language and System Programming Linking Loader Department of Computer Science National Tsing Hua University.
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:
CS2422 Assembly Language & System Programming December 22, 2005.
Assemblers Dr. Monther Aldwairi 10/21/20071Dr. Monther Aldwairi.
Machine-Independent Assembler Features
Assembler (Basic Functions)
Assembler – Machine Independent Features. Literals Design idea  Let programmers to be able to write the value of a constant operand as a part of the.
CS2422 Assembly Language & System Programming December 14, 2006.
A Simple Two-Pass Assembler
Assemblers.
Chapter 4 System Programming and Operating Systems -DM Dhamdhere
Assembler Design Options
Assemblers.
Chapter 1 Computer architecture Languages: machine, assembly, high
CPS4200 System Programming 2007 Spring 1 Systems Programming Chapter 2 Assembler II.
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.
Ass. Prof. Dr Masri Ayob TK 6123 Lecture 13: Assembly Language Level (Level 4)
CS2422 Assembly Language and System Programming Assembler Design Options Department of Computer Science National Tsing Hua University.
1 Assemblers System Programming by Leland L. Beck Chapter 2.
Machine-Independent Assembler Features Literals, Symbol-Defining Statements, Expressions, Program Blocks, Control Sections and Program Linking.
2 : Assembler 1 Chapter II: Assembler Chapter goal: r Introduce the fundamental functions that any assembler must perform. m Assign machine address m Translate.
Machine Independent Assembler Features
Loader and Linker.
Assemblers Two functions: – Mnemonic opcode  Machine Code – Symbolic labels  machine addresses (in memory) Some features: – Depend on assembly language.
Assembler Design Options One-Pass and Multi-Pass Assemblers.
Macro Processors Basic Functions Machine-Independent Features Design Options Implementation Examples.
COMPILERS CLASS IV Er. Vikram Dhiman M.tech NIT jalandhar.
Linking Loader untuk SIC/XE Machine. Lebih Lanjut mengenai Absolute Loader Shortcoming of an absolute loader –Programmer needs to specify the actual address.
CC410: System Programming Dr. Manal Helal – Fall 2014 – Lecture 9 - Assembler 4.
CC410: System Programming
Machine dependent Assembler Features
CC410: System Programming
Machine Independent Assembler Features
System Programming and administration
Assembly Language Ms. V.Anitha AP/CSE SCT
System Software by Leland L. Beck Chapter 2
SYSTEM SOFTWARE - UNIT II
Chapter 3 Machine Language and Assembly Language.
Machine Independent Assembler Features
Chapter 3 Machine Language and Assembly Language.
Chapter 9 : Assembler Design Options
Assembler Design Options
MACRO Processors CSCI/CMPE 3334 David Egle.
Assemblers - 2 CSCI/CMPE 3334 David Egle.
Optional Assembler Features
Loaders and Linkers CSCI/CMPE 3334 David Egle.
Loaders and Linkers: Features
Assembler Design Options
Chapter 7 LC-2 Assembly Language.
A Simple Two-Pass Assembler
Optional Assembler Features 2
System Programming by Leland L. Beck Chapter 2
Assemblers CSCI/CMPE 3334 David Egle.
Machine Independent Assembler Features
Chapter 1 Computer architecture Languages: machine, assembly, high
Chapter 6 Programming the basic computer
Machine Independent Assembler Features
Location Counter (LC) = 0 while line of code <> END if ORG
Presentation transcript:

Assembler Design Options CSCI/CMPE 3334 David Egle

Design Options Have studied the two pass assembler One pass assemblers not the only design possible One pass assemblers useful when it is necessary or desirable to avoid a second pass Multi-pass assemblers an extension to the two pass assembler that allows the assembler to handle forward references in symbolic expressions

One Pass Assembler Does everything in one pass Problem: How do we handle forward references? Could eliminate forward references easy for data – just define the data areas before they are referenced not easy in code – how do we handle selection or loop statements which have forward jumps? Two types of one pass assemblers: produce object code directly in memory produce object file for later linking/loading/execution

Load and go assembler Generate object code in memory for immediate execution No loader is needed More efficient Avoids the overhead of writing the object program out and reading it and loading it back in Avoids overhead of an additional pass over the source Also, storage devices for the intermediate file might not be available, slow, or inconvenient

Operation of load and go Assembler generates object code instructions as it scans source program If an operand symbol has not yet been defined operand address is set to 0 in instruction symbol is entered into the symbol table (unless it is already present) entry is flagged to indicate the symbol is undefined address of instruction is added to list of forward references associated with this symbol When symbol definition is encountered forward reference list is scanned, and proper address is inserted in any instructions previously generated (in memory)

One pass assembler - Algorithm read first input line if OPCODE = ‘START’ then { save #{OPERAND} as starting address initialize LOCCTR to starting address read next input line else set LOCCTR=0 while OPCODE != ‘END’ do { if this is not a comment line then handle line } save (LOCCTR – starting address) as program length Put value of OPERAND on END directive in PC

Algorithm - 2 If there is a symbol in the LABEL field then search SYMTAB for LABEL if found then if undefined mark defined; go through reference list and fix up memory locations else set error flag (duplicate label) else insert (LABEL, LOCCTR) into SYMTAB verify mnemonic and get value if operand is present search SYMTAB for OPERAND if defined get the address set address to 0 and add current value of LOCCTR to reference list insert OPERAND in symbol table, marked undefined, and add LOCCTR to reference list Build machine code Handle directives as appropriate Insert code in memory

One pass assembler that produces object programs Use the same procedure When the definition of a symbol is encountered if instruction which made the forward reference is still in memory, then fix it if not, the instruction has already been written out in a Text record, so generate a new Text record with the correct operand address the loader will fix up the address field

Multi-pass assemblers Required if we remove the restriction that all the symbols on the right hand side of an EQU or ORG directive must be defined Note that removing this restriction is not really a convenience for the programmer as it leads to unreadable code! But, if removed, the multiple passes are use to gradually evaluate the expressions The number of passes will depend on the depth of forward referencing

Implementation examples MASM assembler SPARC assembler AIX assembler

Review problems – Chapter 2 Section 2.1 2, 7 Section 2.2 1, 2, 3 Section 2.3 4, 7, 8, 11, 16, 17, 20, 22 Section 2.4 6, 8, 9