0% found this document useful (0 votes)
19 views3 pages

Assembler

The document explains the design of a Two Pass Assembler, detailing its operations in two passes: the first pass constructs symbol and literal tables and generates intermediate code, while the second pass converts this intermediate code into machine code. It also addresses the forward reference problem, which occurs when a symbol is used before being defined, and how this is resolved using a two-pass approach. Additionally, the document outlines different types of assembly language statements, including imperative, declarative, assembler directives, and macro definition statements, with examples for each type.

Uploaded by

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

Assembler

The document explains the design of a Two Pass Assembler, detailing its operations in two passes: the first pass constructs symbol and literal tables and generates intermediate code, while the second pass converts this intermediate code into machine code. It also addresses the forward reference problem, which occurs when a symbol is used before being defined, and how this is resolved using a two-pass approach. Additionally, the document outlines different types of assembly language statements, including imperative, declarative, assembler directives, and macro definition statements, with examples for each type.

Uploaded by

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

Q.

1) Explain with flowchart design of Two Pass Assembler :

It is a type of assembler that scans the assembly program twice: Pass I: Constructs symbol
and literal tables, assigns memory addresses, and generates intermediate code. Pass II:
Converts the intermediate code into machine code using the tables created in Pass I. Pass I:
Operations Performed: 1.Initialize Location Counter (LC). 2.Read Source Line: Read each
instruction line by line. 3.Label Handling: If a label is present, add it with its LC to the symbol
table. 4.Process Assembler Directives (AD) like START, END, EQU, etc. 5.Update Literal Table
for constants and symbols. 6.Generate Intermediate Code (IC) for each instruction. 7.
Increment LC depending on the instruction format.8.Repeat the above steps until END
directive is encountered. Pass II: Operations Performed: 1.Read Intermediate Code
(IC).2.Use Symbol Table to resolve addresses of labels and variables.3.Use Literal Table to
find literal values. 4.Convert IC to Machine Code using mnemonic and operand
data.5.Evaluate Address Expressions if required.6.Handle Literals and update pools
needed.7.Generate Final Object Code. 8.Write the Object Code to Output Q.2)Explain
forward reference problem and how it is handled in assembler design:In assembly
language programming, a forward reference occurs when a symbol (label or variable) is used
in an instruction before it is defined later in the program. Since the assembler processes
instructions sequentially, it may encounter a symbol whose address value is not yet known.
This leads to the forward reference problem. Example:
START 100
MOVER AREG, B
ADD AREG, D

D EQU A + B
A DS 1
B DS 1

END
How it is Handled in Assembler Design: The forward reference problem is effectively solved
by using a two-pass assembler.Pass I (First Pass): •The assembler scans the entire source
program line by line.•It builds the symbol table, recording the addresses of all labels and
variables.•When a forward reference is found, it is noted in the symbol table, often with a
placeholder or undefined status.•Assembler directives like EQU, START, DS, DC, etc., are
processed.•Intermediate code is generated for each line for use in Pass II.Pass II (Second
Pass):•The assembler reprocesses the program using the intermediate code.•It resolves the
addresses of all symbols using the symbol table created in Pass I.•Forward-referenced
symbols now have defined addresses and can be used to generate the final object
code.•Literals and expressions are also handled and assigned memory if necessary. Q.3)
Different Types of Assembly Language statements with example: 1. Imperative
Statements: These are actual machine-level instructions that are executed during the
program run. They direct the machine to perform specific operations such as data transfer,
arithmetic, logic, etc.Ex: MOV A, B – This instruction moves the contents of register B into
register A. 2.Declarative Statements: These statements are used to define constants and
reserve memory locations. They are not converted into machine instructions but help the
assembler in allocating storage. Ex: DS 3 – This statement declares a storage space of 3
memory locations. 3.Assembler Directives:These are instructions to the assembler itself, not
to the CPU. They help in the organization of the program and control the assembly
process.Ex: START 100 – Tells the assembler to begin the program with the memory location
100.4.Macro Definition Statements: These statements are used to define a group of
instructions that can be reused multiple times throughout the program. Macros help in
reducing code repetition. Example: MACRO ADDXY A, B ADD A, B MEND

You might also like