0% found this document useful (0 votes)
438 views23 pages

Assembler Module 1-1

The document describes the different phases of an assembler program and the processes involved in single-pass and two-pass assemblers. It discusses the analysis, synthesis, and backpatching phases of a single-pass assembler. It also outlines the two passes of a two-pass assembler, with the first pass building symbol tables and the second pass generating object codes by processing the intermediate code from pass 1. Key data structures like the opcode table and symbol table are used to map mnemonics to codes and resolve symbols in both assembler approaches.

Uploaded by

arunlalds
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
438 views23 pages

Assembler Module 1-1

The document describes the different phases of an assembler program and the processes involved in single-pass and two-pass assemblers. It discusses the analysis, synthesis, and backpatching phases of a single-pass assembler. It also outlines the two passes of a two-pass assembler, with the first pass building symbol tables and the second pass generating object codes by processing the intermediate code from pass 1. Key data structures like the opcode table and symbol table are used to map mnemonics to codes and resolve symbols in both assembler approaches.

Uploaded by

arunlalds
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 23

ASSEMBLER PHASES

ANALYSIS PHASE
1.Isolate the label, mnemonic opcode, operands
of the statement.
2.if a label is present,enter <symbol,LC content>
in the symbol table.
3.Check the validity of mnemonic opcode by
checking the mnemonic table.
4.Update LC by considering the opcode and the
operands.
Synthesis phase
1.Obtain the machine opcode corresponding to
mnemonic opcode from the mnemonic table.
2.Obtain the address of the symbols from the
symbol table.
3.Synthesize a machine instruction or the
machine form of a constant.
Single pass assembler

1. Analysis and synthesis done in one pass.


2. Pblm. Of forward reference.-a reference to
the entity which precedes its definition in the
program.

This can be tackled by ‘Backpatching’ (by using


TII).
1.The operand field of an instruction containing a
forward reference is left blank initially.
2.The entry <inst. Address, symbol> will be
entered into TII(Table of Incomplete Istructions)
3.By the time END stmt. Is encountered, symbol
table contains the address of every symbols in
the source code and TII.
The assembler would process each entry in TII
one by one .
• Single Pass Assembler
• A single pass assembler scans the program
only once and creates the equivalent binary
program. The assembler substitute all of the
symbolic instruction with machine code in one
pass.
• Advantages
Every source statement needs to be processed
once.
• Demerit
Pblm. Of forward reference , should be
tackled by ‘Backpatching’
• A two pass assembler does two passes over
the source file ( the second pass can be over a
file generated in the first pass ).
• In the first pass all it does is looks for label
definitions and introduces them in the symbol
table.
• In the second pass, after the symbol table is
complete, it does the actual assembly by
translating the operations and so on.
Two Pass Assembler
• Tasks performed by the passes of two-pass assembler are as
follows:
Pass I: -
• Separate the symbol, mnemonic opcode and operand fields.
• Determine the storage-required for every assembly language
statement and update the location counter.
• Build the symbol table and the literal table.
• Construct the intermediate code for every assembly language
statement.
Pass II: -
• Synthesize the target code by processing the intermediate
code generated during Pass 1
• Data structures required for pass I:
• 1. Source file containing assembly program.
• 2. OPTAB: A table of mnemonic op-codes and related
information. It has the following fields
• Mnemonic
• : Such as ADD, END, DC
• TYPE
• : IS for imperative, DL for declarative and AD for Assembler
directive
• OP- code
• : Operation code indicating the operation to be performed.
• Length
• : Length of instruction required for Location Counter
Processing
A Simple Two Pass Assembler
Implementation
Source READ (Label, opcode, operand)
program

Pass 1 Pass 2 Object


codes

OPTAB SYMTAB
SYMTAB

Mnemonic and Label and address Label and address


opcode mappings mappings enter mappings are referenced
are referenced from here from here
here
2pass assembler-Pass 1 algorithm
Continued…
Second pass-algorithm
Continued….
Intermediate code
Continued…

You might also like