0% found this document useful (0 votes)
12 views85 pages

System Software

The document explains the concept of macros in assembly language programming, detailing their definition, call, and expansion processes. It highlights the advantages and disadvantages of macro expansion, including nested macros and advanced macro facilities, such as parameterized macros and conditional macro expansion. Additionally, it covers specific macro instructions like AGO, AIF, and ANOP, and describes the design and functioning of a macro pre-processor.

Uploaded by

patelabhi0010
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)
12 views85 pages

System Software

The document explains the concept of macros in assembly language programming, detailing their definition, call, and expansion processes. It highlights the advantages and disadvantages of macro expansion, including nested macros and advanced macro facilities, such as parameterized macros and conditional macro expansion. Additionally, it covers specific macro instructions like AGO, AIF, and ANOP, and describes the design and functioning of a macro pre-processor.

Uploaded by

patelabhi0010
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

System Software

Ch:-4(20%)
➢ Introduction to Macro

In assembly language programming, many times the same group of instructions is used
repeatedly in different parts of a program. Writing the same instructions again and again
increases program length and also wastes programming time. To solve this problem, the
concept of a macro is used.

➢ Definition of Macro

A macro is a group of instructions that is given a name and can be used many times in a
program by simply calling its name. Whenever the macro name is called, the actual
instructions of the macro are automatically inserted into the program.

➢ Macro Call

When the programmer uses the macro name inside the program, it is called a macro call.
The macro processor identifies the macro call and replaces it with the actual macro
statements.

➢ Macro Expansion

In macro processing, a programmer writes a macro once and uses it many times in the
program. Whenever the macro name is used, the macro processor replaces the macro call
with the actual instructions of the macro. This process is called macro expansion.

• Working of Macro Expansion

The macro processor performs the following steps during macro expansion:

1. The macro processor reads the source program.

2. It identifies the macro call.

3. It searches the macro definition in the Macro Definition Table (MDT).

4. It matches formal parameters with actual arguments.

5. It replaces the parameters with actual values.

6. It inserts the expanded instructions into the program.

Thus, the macro call is converted into actual assembly instructions.


• Example of Macro Expansion

Macro Definition

MACRO
INCR X
ADD X,1
MEND

In this example:

• INCR is the macro name.

• X is the parameter.

• ADD X,1 is the macro instruction.

Macro Call

INCR NUM1

Here:

• NUM1 is the actual argument.

Expanded Code

After macro expansion, the macro call becomes:

ADD NUM1,1

The macro processor replaces:

• parameter X
with

• actual argument NUM1

• Advantages of Macro Expansion

1. Reduces repetitive coding.

2. Saves programming effort and time.

3. Makes the program easy to read.

4. Reduces chances of mistakes.

5. Improves program development speed.


• Disadvantages of Macro Expansion

1. Expanded code increases program size.

2. Debugging may become difficult.

3. Large number of macros may increase processing time.

• Applications of Macro Expansion

Macro expansion is mainly used in:

• Assembly language programming

• System software

• Compilers and assemblers

• Reusable program development

➢ Nested Macro Calls


A nested macro call occurs when one macro calls another macro inside its body.

• Example of Nested Macro Call

MACRO
DOUBLE Y
INCR Y
INCR Y
MEND

In the above example:

• INCR is one macro.

• DOUBLE is another macro.

• Inside DOUBLE, the macro INCR is called two times.

• Working of Nested Macro Calls

The following steps are performed in nested macro calls:

1. The macro processor identifies the outer macro call.

2. It expands the outer macro instructions.

3. During expansion, if another macro call is found, it expands that macro also.

4. This process continues until all macro calls are expanded completely.
• Advantages of Nested Macro Calls

1. Reduces repetitive coding.

2. Makes programs modular and organized.

3. Improves readability of the program.

4. Saves programming time.

5. Allows reuse of small macros inside larger macros.

• Disadvantages of Nested Macro Calls

1. Macro processing becomes more complex.

2. Debugging becomes difficult.

3. Too much nesting may increase processing time.

4. Expanded code may increase program size.

• Applications of Nested Macro Calls

Nested macro calls are used in:

• Assembly language programming

• System software

• Complex macro processing

• Reusable program development


➢ Advanced Macro Facilities
Advanced macro facilities are special features provided by a macro processor to make
macros more powerful, flexible, and easy to use. These facilities help programmers perform
complex tasks using macros in a simple way.

These facilities help in:

• handling complex macro operations,

• passing parameters,

• creating conditional processing,

• and generating repeated code automatically.

• Important Advanced Macro Facilities

The main advanced macro facilities are:

1. Parameterized Macros

2. Conditional Macro Expansion

3. Expansion Time Variables

4. Looping in Macros

5. Nested Macro Calls

6. Keyword Parameters

7. Default Parameters

1. Parameterized Macros

Parameterized macros are macros that accept parameters from the macro call. These
parameters allow the same macro to work with different values without changing the macro
definition. The macro processor replaces the formal parameters with actual arguments
during macro expansion. This facility increases code reusability and reduces repeated coding.

2. Conditional Macro Expansion

Conditional macro expansion allows the macro processor to expand instructions based on
certain conditions. The macro processor checks whether the condition is true or false and
then expands the required instructions only. This facility helps in creating decision-based
macros and improves flexibility.
3. Expansion Time Variables

Expansion time variables are temporary variables used during macro expansion. These
variables help the macro processor store intermediate values while processing macros. They
are mainly used for counting, generating labels, and controlling loops inside macros.

4. Looping in Macros

Looping in macros allows repeated expansion of instructions automatically. The macro


processor repeatedly generates the same set of instructions until a condition becomes false
or a fixed count is completed. This facility saves programming time and avoids writing the
same instructions many times.

5. Nested Macro Calls

Nested macro calls occur when one macro calls another macro inside its body. This facility
allows programmers to divide large tasks into smaller reusable macros. The macro processor
expands the outer macro first and then expands the inner macro calls.

6. Keyword Parameters

Keyword parameters allow arguments to be passed using parameter names instead of


positions. This makes macro calls easier to understand and reduces mistakes in parameter
passing. The programmer can pass parameters in any order because parameter names are
used explicitly. Keyword parameters improve readability and flexibility of macros.

7. Default Parameters

Default parameters are parameters that already have predefined values in the macro
definition. If the programmer does not provide any value during the macro call, the default
value is used automatically. This facility reduces the need to pass values every time and
simplifies macro usage.
➢ AGO, AIF and ANOP in Macro Processor

AGO, AIF, and ANOP are special macro expansion instructions used in advanced macro
facilities. These instructions help control the flow of macro expansion. They are mainly used
for decision making, branching, and controlling the execution of statements inside macros.

1. AGO (Assembler GO)

Definition

AGO stands for Assembler GO. It is an unconditional branch instruction used in macro
processors.

The AGO statement transfers the control directly to another label without checking any
condition. When the macro processor finds AGO, it immediately jumps to the specified label
and skips all instructions in between.

• Syntax of AGO

AGO .LABEL

Where:

• AGO = branch instruction

• .LABEL = destination label

• Working of AGO

The macro processor performs the following steps:

1. It reads the AGO instruction.

2. It does not check any condition.

3. It directly transfers control to the specified label.

4. The statements between AGO and the label are skipped.

• Advantages of AGO

1. Simple and fast branching.

2. Useful for skipping unnecessary instructions.

3. Helps control macro expansion sequence.

4. Makes macro programs more organized.


• Disadvantages of AGO

1. Difficult debugging if used too much.

2. Excessive branching may reduce readability.

3. Makes macro flow complex sometimes.

• Applications of AGO

AGO is used:

• to skip instructions,

• to control macro flow,

• and to jump directly to specific labels.

2. AIF (Assembler IF)

• Definition
• AIF stands for Assembler IF. It is a conditional branch instruction used in macro
processing.
• AIF checks a condition before transferring control. If the condition is true, control
jumps to the specified label. If the condition is false, the next instruction executes
normally.
• In simple words:
• AIF means “If condition is true, then go to this label.

• Syntax of AIF

AIF (condition) .LABEL

Where:

• condition = expression to check

• .LABEL = destination label


• Working of AIF

The macro processor performs these steps:

1. Reads the AIF instruction.

2. Evaluates the condition.

3. If condition is true:

o control jumps to the label.

4. If condition is false:

o next instruction executes normally.

• Advantages of AIF

1. Supports decision making.

2. Makes macros intelligent and flexible.

3. Allows conditional code generation.

4. Reduces unnecessary instructions.

• Disadvantages of AIF

1. Increases macro complexity.

2. Conditions may become difficult to understand.

3. Debugging becomes harder in large macros.

• Applications of AIF

AIF is used:

• for conditional expansion,

• for decision making,

• and for selecting different instructions based on conditions.


3. ANOP (Assembler No Operation)

• Definition

ANOP stands for Assembler No Operation. It is a dummy instruction that performs no


operation.

ANOP is mainly used to define labels in macro processing. It acts as a placeholder statement
where control can jump using AGO or AIF.

In simple words:

ANOP means “Do nothing.”

• Syntax of ANOP

.LABEL ANOP

Where:

• .LABEL = label name

• ANOP = no operation instruction

• Working of ANOP

ANOP does not perform any calculation or processing. It simply marks a position in the
macro program.

AGO and AIF use these labels for branching.

Thus, ANOP helps organize the flow of macro expansion.

• Advantages of ANOP

1. Helps define labels.

2. Makes branching easier.

3. Organizes macro programs properly.

4. Useful with AGO and AIF instructions.

• Disadvantages of ANOP

1. Does not perform actual processing.

2. Too many ANOP labels may reduce readability.


➢ Difference Between AGO, AIF and ANOP

ANOP (Assembler No
AGO (Assembler GO) AIF (Assembler IF)
Operation)

AGO is an unconditional AIF is a conditional


ANOP is a dummy instruction
branching instruction used in branching instruction used in
that performs no operation.
macro processing. macro processing.

AGO transfers control directly AIF transfers control to the ANOP does not transfer
to the specified label without specified label only if the control or execute any
checking any condition. given condition is true. instruction.

AGO works similarly to the AIF works similarly to the IF


ANOP works like an empty or
GOTO statement in condition statement in
placeholder statement.
programming languages. programming languages.

In AGO, condition checking is In AIF, condition checking is ANOP does not require any
not required. necessary before branching. condition checking.

AIF is mainly used for


AGO is mainly used to skip ANOP is mainly used for
decision making and
unnecessary instructions defining labels in macro
conditional macro
during macro expansion. programs.
expansion.

AIF changes the flow of ANOP only marks a position in


AGO directly changes the flow
execution only when the the macro program and does
of macro execution.
condition becomes true. not affect execution flow.

AGO may make the macro AIF increases the flexibility of ANOP helps organize
program difficult to macros by allowing branching labels properly in
understand if used excessively. conditional execution. the macro processor.

Example: AGO .LOOP Example: AIF (&X EQ 1) .YES Example: .YES ANOP
➢ Difference Between Macro and Nested Macro
Macro Nested Macro

A macro is a named group of instructions that


A nested macro is a macro in which one
can be expanded whenever it is called in a
macro calls another macro inside its body.
program.

A simple macro contains only normal A nested macro contains another macro call
instructions inside the macro definition. inside the macro definition.

In a nested macro, the macro processor


In a macro, the macro processor expands only
expands both outer and inner macros step
one macro at a time.
by step.

A simple macro is easier to understand and A nested macro is more complex because
process. multiple macros are involved.

Macros are mainly used for simple repetitive Nested macros are mainly used for complex
programming tasks. and modular programming tasks.

A nested macro may require more


A simple macro requires less processing time
processing time because multiple macro
during macro expansion.
calls are expanded.

Debugging nested macros is comparatively


Debugging a simple macro is easier.
more difficult.

A nested macro improves program


A simple macro improves code reusability for
organization by dividing large tasks into
small repeated instructions.
smaller macros.

The structure of a nested macro is more


The structure of a simple macro is
complicated due to multiple levels of
straightforward and easy to maintain.
expansion.

Example: A macro containing only arithmetic Example: A macro that calls another macro
instructions. inside its body.
➢ Design of a Macro Pre-Processor

A macro pre-processor is a software tool that processes macro definitions and expands macro
calls before the main translation process begins.

It works between the source program and the assembler.

• Basic Working of Macro Pre-Processor

The macro pre-processor performs the following tasks:

1. Reads the source program.


2. Identifies macro definitions.
3. Stores macro definitions in tables.
4. Detects macro calls.
5. Expands macro calls.
6. Generates expanded source code.

• Design of Macro Pre-Processor

The design of a macro pre-processor mainly consists of the following components:

1. Macro Name Table (MNT)


2. Macro Definition Table (MDT)
3. Argument List Array (ALA)
4. Input Source Program
5. Expanded Output Program

These components work together to process and expand macros properly.


1. Input Source Program

The source program written by the programmer is given as input to the macro pre-
processor.

This program may contain:

• macro definitions,
• macro calls,
• and normal assembly language instructions.

The macro pre-processor scans the source program line by line.

2. Macro Name Table (MNT)

The Macro Name Table stores the names of all macros defined in the program.

For every macro, the MNT stores:

• macro name,
• and a pointer to its definition in MDT.

The macro processor uses MNT to quickly search for macro definitions during macro
expansion.

3. Macro Definition Table (MDT)

The Macro Definition Table stores the actual instructions of the macros.

Whenever a macro definition is found, its instructions are stored sequentially in MDT.

During macro expansion, the macro processor copies instructions from MDT into the output
program.

4. Argument List Array (ALA)

The Argument List Array stores the actual arguments passed during macro calls.

ALA creates a relationship between:

• formal parameters,
and
• actual arguments.

During macro expansion, the macro processor replaces parameters using values stored in
ALA.
Working of Macro Pre-Processor

The working of a macro pre-processor is divided into two main phases:

1. Macro Definition Processing


2. Macro Expansion Processing

Phase 1: Macro Definition Processing

In this phase, the macro processor processes macro definitions.

The following steps are performed:

1. The macro processor reads the source program line by line.


2. When the keyword MACRO is found, macro definition processing starts.
3. The macro name is stored in MNT.
4. The macro instructions are stored in MDT.
5. Parameters are converted into positional notation.
6. Processing continues until MEND is found.

Thus, all macro definitions are stored properly in tables.

Phase 2: Macro Expansion Processing

In this phase, the macro processor expands macro calls.

The following steps are performed:

1. The macro processor scans the source program again.


2. It identifies macro calls.
3. The macro name is searched in MNT.
4. Corresponding macro instructions are copied from MDT.
5. Actual arguments are stored in ALA.
6. Parameters are replaced with actual values.
7. Expanded instructions are inserted into the output program.

Thus, macro calls are replaced by actual instructions [Link] of Macro


Pre-Processor

1. It reduces repetitive coding in programs.


2. It saves programming time and effort.
3. It improves readability and maintainability of programs.
4. It reduces chances of human errors.
5. It supports reusable programming techniques.
6. It makes program modification easier.
• Disadvantages of Macro Pre-Processor

1. Macro expansion increases the size of the final program.


2. Debugging becomes difficult after expansion.
3. Processing becomes more complex for nested macros.
4. Large number of macros may increase processing time.

• Applications of Macro Pre-Processor

Macro pre-processors are widely used in:

• Assembly language programming


• System software development
• Compilers and assemblers
• Automatic code generation systems
• Reusable software development

➢ Design of Macro Assembler

A Macro Assembler is a program that converts assembly language code into machine code.
It also supports macros — which are like shortcuts. You write a group of instructions once,
give it a name, and reuse it anywhere by just calling that name.

• Design of Macro Assembler

The design of a macro assembler mainly consists of the following components:

1. Input Source Program


2. Macro Processor
3. Macro Tables
4. Assembler
5. Symbol Table
6. Object Program

These components work together to process macros and generate machine code.
• A macro assembler works in two passes (two rounds of reading the code).

Pass 1 — Reading and Recording

In this pass, the assembler reads the source code and does two things:

1. Macro Processor

• Finds all macro definitions (between MACRO and MEND)


• Saves them in two tables:
o MNT (Macro Name Table) — stores the name of each macro and how many
parameters it takes
o MDT (Macro Definition Table) — stores the actual body (instructions) of each
macro

2. Symbol Collector

• Scans all labels (like LOOP:, START:) in the code


• Saves them in the Symbol Table (ST) with their memory addresses

Pass 2 — Expanding and Generating

In this pass, the assembler uses the tables built in Pass 1 and does two things:

1. Macro Expander

• Finds every macro call in the code


• Looks up the MDT to get the macro body
• Replaces the macro call with actual instructions
• Uses the ALA (Argument List Array) to substitute the actual values passed in the call

2. Code Generator

• Converts the expanded assembly instructions into machine code (binary/object


code)
• Uses the Symbol Table to replace labels with real memory addresses
• Important Tables (Data Structures)

Table Full Form Purpose


MNT Macro Name Table Stores macro names and parameter count
MDT Macro Definition Table Stores the body of each macro
ST Symbol Table Stores labels and their addresses
ALA Argument List Array Stores actual arguments used when calling a macro

• Final Output

After both passes, the assembler produces the Object Code — the final machine-readable
binary file that the CPU can execute.

➢ Basic Tasks of Macro Processor

A macro processor is a system software that processes macro definitions and expands macro
calls before the assembly or compilation process starts.

It automatically replaces macro calls with the actual instructions written inside the macro
definition.

• Basic Tasks of Macro Processor

The macro processor performs the following basic tasks:

1. Recognition of Macro Definitions

2. Storing Macro Definitions

3. Recognition of Macro Calls

4. Macro Expansion

5. Parameter Substitution

6. Generation of Expanded Source Program

All these tasks are necessary for proper macro processing.


1. Recognition of Macro Definitions

The first task of the macro processor is to identify macro definitions in the source program.

Whenever the macro processor encounters the keyword MACRO, it understands that the
macro definition has started. It continues reading the instructions until it finds the keyword
MEND, which indicates the end of the macro definition.

Thus, the macro processor recognizes the beginning and ending of macros properly.

2. Storing Macro Definitions

After identifying the macro definition, the macro processor stores the macro information in
special tables.

The important tables used are:

• Macro Name Table (MNT)

• Macro Definition Table (MDT)

• Argument List Array (ALA)

The macro name is stored in MNT, while the actual macro instructions are stored in MDT.

Thus, storing macro definitions helps the processor use them later during macro expansion.

3. Recognition of Macro Calls

The macro processor continuously scans the source program to identify macro calls.

Whenever the macro processor finds a statement whose name matches an entry in the
Macro Name Table (MNT), it recognizes it as a macro call.

After identifying the macro call, the processor starts the macro expansion process.

4. Macro Expansion

Macro expansion is one of the most important tasks of the macro processor.

In this task, the macro processor replaces the macro call with the actual instructions stored
in the macro definition.

The instructions are copied from MDT and inserted into the source program.

Thus, macro expansion automatically generates the required code.


5. Parameter Substitution

During macro expansion, the macro processor replaces formal parameters with actual
arguments.

Formal parameters are written inside the macro definition, while actual arguments are
passed during the macro call.

The processor uses the Argument List Array (ALA) for this substitution process.

Thus, parameter substitution helps make macros reusable and flexible.

6. Generation of Expanded Source Program

After macro expansion and parameter substitution, the macro processor generates the
expanded source program.

The expanded source program contains:

• actual assembly instructions,

• without any macro calls.

This expanded program is then given to the assembler for machine code generation.

Thus, the macro processor prepares the final assembly program for translation.
➢ Design Issues of Macro Processor

Design issues of a macro processor are the important factors and problems that must be
considered while designing and implementing a macro processor.

These issues help decide how the macro processor will store, process, and expand macros
efficiently.

• Important Design Issues of Macro Processor

The major design issues of a macro processor are:

1. Macro Definition Processing

2. Macro Expansion

3. Parameter Handling

4. Nested Macro Calls

5. Storage Management

6. Conditional Macro Expansion

7. Error Handling

8. Choice of One-Pass or Two-Pass Processing

1. Macro Definition Processing

One important design issue is how the macro processor will recognize and store macro
definitions.

The processor must correctly identify the beginning of a macro using the MACRO statement
and the end using the MEND statement. After identification, the macro definition must be
stored properly in tables such as Macro Name Table (MNT) and Macro Definition Table
(MDT).

Efficient storage of macro definitions helps the processor expand macros quickly and
correctly.
2. Macro Expansion

Macro expansion is another important design issue in macro processors.

The processor must correctly replace the macro call with the actual macro instructions.
During expansion, the processor should insert the expanded instructions at the correct
location in the program.

The processor must also ensure that the expanded code is error-free and properly
formatted.

Thus, efficient macro expansion improves processing speed and program correctness.

3. Parameter Handling

Handling parameters correctly is one of the most important design issues.

The macro processor must manage:

• formal parameters,

• actual arguments,

• keyword parameters,

• and default parameters.

During macro expansion, the processor replaces formal parameters with actual arguments
using Argument List Array (ALA).

Incorrect parameter handling may produce wrong program output.

4. Nested Macro Calls

Nested macro calls occur when one macro calls another macro inside its body.

The macro processor must properly handle multiple levels of macro expansion without
confusion. It should maintain proper control and sequence during nested macro processing.

Handling nested macros increases the complexity of the macro processor design.

Therefore, special mechanisms are required to manage nested macro calls efficiently.
5. Storage Management

The macro processor uses memory tables like:

• MNT,

• MDT,

• and ALA.

Efficient memory management is an important design issue because a large number of


macros may require large storage space.

The processor should store macro information efficiently to reduce memory usage and
improve processing speed.

6. Conditional Macro Expansion

Advanced macro processors support conditional macro expansion using instructions like:

• AIF,

• AGO,

• and ANOP.

The processor must evaluate conditions properly and decide which statements should be
expanded.

Conditional macro expansion increases flexibility but also increases processing complexity.

Thus, proper handling of conditions is an important design issue.

7. Error Handling

The macro processor must detect and report errors during macro processing.

Some common errors are:

• undefined macros,

• wrong number of parameters,

• missing MEND,

• and invalid macro calls.

Proper error handling helps programmers identify and correct mistakes easily.

Therefore, good error detection and reporting mechanisms are essential in macro processor
design.
8. Choice of One-Pass or Two-Pass Processing

The designer must decide whether the macro processor should use:

• one-pass processing,
or

• two-pass processing.

In one-pass processing:

• macro definition and expansion are done together.

In two-pass processing:

• the first pass stores macro definitions,

• and the second pass performs macro expansion.

One-pass processing is faster, while two-pass processing is easier to implement and supports
complex macro features.

Thus, selecting the proper processing method is an important design issue

➢ Features of Macro Processor


• Introduction

A macro processor is a system software that processes macro definitions and expands macro
calls in a source program. It helps reduce repetitive coding and simplifies program
development. To perform macro processing efficiently, the macro processor provides several
important features.

These features make macros more flexible, reusable, and easy to use in assembly language
programming and system software.

• Definition of Features of Macro Processor

Features of a macro processor are the special capabilities provided by the macro processor
to process and expand macros efficiently.

These features help improve program readability, flexibility, and code reusability.
• Important Features of Macro Processor

The important features of a macro processor are:

1. Macro Definition Facility

2. Macro Expansion Facility

3. Parameterized Macros

4. Conditional Macro Expansion

5. Nested Macro Calls

6. Keyword and Default Parameters

7. Expansion Time Variables

8. Looping Facility

9. Error Detection Facility

1. Macro Definition Facility

The macro processor allows programmers to define a group of instructions using the MACRO
and MEND statements.

The programmer can write the macro once and use it many times in the program. This
feature reduces repetitive coding and saves programming effort.

Thus, macro definition improves program organization and reusability.

2. Macro Expansion Facility

The macro processor automatically replaces the macro call with the actual instructions
written inside the macro definition.

This process is called macro expansion. The expanded code is inserted into the program
before assembly or compilation.

Thus, macro expansion simplifies programming and reduces manual coding.


3. Parameterized Macros

The macro processor supports parameterized macros in which parameters can be passed
during the macro call.

The same macro can work with different values by changing the arguments. During
expansion, the processor replaces formal parameters with actual arguments.

This feature increases flexibility and code reusability.

4. Conditional Macro Expansion

The macro processor supports conditional expansion using instructions like:

• AIF,

• AGO,

• and ANOP.

Conditional expansion allows the processor to expand instructions only when specific
conditions are satisfied.

This feature helps in decision making and improves flexibility in macro processing.

5. Nested Macro Calls

The macro processor supports nested macros in which one macro can call another macro
inside its body.

This feature allows programmers to divide large tasks into smaller reusable macros.

Nested macro calls improve program organization and modularity.

6. Keyword and Default Parameters

The macro processor allows the use of keyword parameters and default parameters.

Keyword parameters allow arguments to be passed using parameter names, while default
parameters provide predefined values if no value is passed during the macro call.

These features improve readability and simplify macro usage.


7. Expansion Time Variables

Expansion time variables are temporary variables used during macro expansion.

They help the macro processor perform counting, label generation, and loop control during
macro processing.

This feature supports advanced macro operations.

8. Looping Facility

The macro processor supports looping during macro expansion.

Using looping instructions, the processor can repeatedly generate instructions automatically.

This feature reduces repetitive coding and simplifies large repetitive tasks.

9. Error Detection Facility

The macro processor detects errors during macro processing.

It can identify:

• undefined macros,

• missing MEND,

• wrong parameters,

• and invalid macro calls.

This feature helps programmers correct mistakes easily.

• Advantages of Macro Processor Features

1. Reduces repetitive coding.

2. Saves programming time.

3. Improves program readability.

4. Supports reusable programming.

5. Simplifies program maintenance.

6. Makes macros more flexible and powerful.


➢ Macro Processor Design Options
• Definition of Macro Processor Design Options
Macro processor design options are the different approaches used for processing
macro definitions and macro calls in a macro processor.
These options determine the internal working method of the macro processor.

• Types of Macro Processor Design Options


The main design options of a macro processor are:
1. One-Pass Macro Processor
2. Two-Pass Macro Processor

1. One-Pass Macro Processor


Introduction
In a one-pass macro processor, macro definition processing and macro expansion are
performed together in a single scan of the source program.
The processor reads the source program only once. During this scan, it
simultaneously:
• identifies macro definitions,
• stores macro information,
• and expands macro calls.
Thus, all macro processing work is completed in one pass.

• Working of One-Pass Macro Processor


The one-pass macro processor works in the following steps:
1. The processor reads the source program line by line.
2. When it encounters the MACRO statement, it starts storing the macro definition.
3. Macro information is stored in tables such as MNT and MDT.
4. The processor continues scanning the source program.
5. Whenever a macro call is found, it immediately expands the macro.
6. The expanded instructions are inserted into the output program.
Thus, both definition processing and macro expansion are performed together.

• Advantages of One-Pass Macro Processor


1. The processing speed is fast because the source program is scanned only once.
2. Less scanning time is required.
3. It reduces overall processing overhead.
4. The output program is generated quickly.
• Disadvantages of One-Pass Macro Processor
1. The design of the processor becomes more complicated.
2. Handling nested macros becomes difficult.
3. Forward references are difficult to manage properly.
4. Error handling becomes more complex.
5. Complex macro facilities are difficult to implement

2. Two-Pass Macro Processor


Introduction
In a two-pass macro processor, macro processing is completed in two separate passes
over the source program.
The first pass is used for processing and storing macro definitions, while the second
pass is used for macro expansion.
This design is more organized and easier to implement compared to the one-pass
macro processor.

Working of Two-Pass Macro Processor


The working of the two-pass macro processor is divided into two passes.

Pass 1: Macro Definition Processing


During the first pass, the processor performs the following tasks:
1. It scans the source program line by line.
2. It identifies macro definitions using the MACRO statement.
3. Macro names are stored in the Macro Name Table (MNT).
4. Macro instructions are stored in the Macro Definition Table (MDT).
5. Parameters are stored in the Argument List Array (ALA).
6. Processing continues until the MEND statement is found.
At the end of Pass 1, all macro definitions are completely stored in memory tables.

Pass 2: Macro Expansion Processing


During the second pass, the processor performs the following tasks:
1. The source program is scanned again.
2. Macro calls are identified.
3. The processor searches macro definitions in MNT and MDT.
4. Actual arguments are substituted for formal parameters using ALA.
5. Macro instructions are expanded and inserted into the output program.
Thus, all macro calls are replaced by actual instructions during Pass 2.
• Advantages of Two-Pass Macro Processor

1. The design is simpler and easier to understand.

2. Nested macro calls can be handled efficiently.

3. Forward references are managed properly.

4. Error detection and debugging become easier.

5. Complex macro facilities can be implemented easily.

• Disadvantages of Two-Pass Macro Processor

1. Processing speed is slower because two scans are required.

2. More processing time is needed.

3. Additional memory may be required for storing tables.

➢ Difference Between One-Pass and Two-Pass Macro Processor

One-Pass Macro Processor Two-Pass Macro Processor

In a one-pass macro processor, the source In a two-pass macro processor, the source
program is scanned only one time. program is scanned two times.

In a one-pass macro processor, macro In a two-pass macro processor, macro


definition processing and macro expansion definition processing and macro expansion are
are performed together in the same pass. performed separately in two different passes.

The one-pass macro processor reads the The two-pass macro processor first stores
source program and immediately expands macro definitions and later expands macro
the macro calls. calls in the second pass.

The processing speed of a one-pass macro The processing speed of a two-pass macro
processor is faster because only one scan is processor is slower because two scans are
required. required.

The design of a one-pass macro processor is


The design of a two-pass macro processor is
more complicated and difficult to
simpler and easier to understand.
implement.

In a two-pass macro processor, nested macro


In a one-pass macro processor, handling
calls can be handled more easily and
nested macro calls becomes difficult.
efficiently.
One-Pass Macro Processor Two-Pass Macro Processor

Forward references are difficult to manage Forward references can be handled properly in
in a one-pass macro processor. a two-pass macro processor.

Error handling and debugging are more Error handling and debugging are easier in a
difficult in a one-pass macro processor. two-pass macro processor.

A one-pass macro processor is suitable for A two-pass macro processor is suitable for
simple macro processing systems. complex macro processing systems.

A one-pass macro processor requires less A two-pass macro processor requires more
scanning time. scanning time.

The memory management of a one-pass The memory management of a two-pass


macro processor is more difficult because all macro processor is easier because tasks are
operations happen together. divided into two passes.

Two-pass macro processors are mainly used in


One-pass macro processors are mainly used
advanced assemblers and complex system
where faster processing is needed.
software.
Ch:-5(20%)
➢ Relocation and Linking Concept
• Relocation
Relocation is the process of modifying the address used in a program during loading
or execution.
When a program is loaded into memory, the actual memory location may be different
from the location assumed during compilation. Therefore, the addresses inside the
program must be adjusted. This process is called relocation.
In simple words, relocation means changing the address references of a program
according to the actual memory location where the program is loaded.
• Need of Relocation
Relocation is needed because:
1. A program may not always be loaded into the same memory location.
2. Multiple programs may run at the same time in memory.
3. The operating system allocates available memory dynamically.
4. Address references inside the program must match the actual memory addresses.
• Types of Relocation
1. Static Relocation
In static relocation, address modification is done before the execution of the
program.
The loader changes all address values at loading time.
2. Dynamic Relocation
In dynamic relocation, address translation is done during the execution of the
program with the help of hardware support.
Example of Relocation
Suppose a program is originally designed to start from address 1000.
But the loader places it at address 5000 in memory.
Then all address references are increased by 4000. This adjustment process is called
relocation.

➢ Linking
Linking is the process of combining different object modules and library files into a
single executable program.
A large program is generally divided into many small modules. These modules are
compiled separately. The linker combines all these modules and resolves external
references.
In simple words, linking connects different program modules together to create one
complete executable file.
• Need of Linking
Linking is required because:
1. Large programs are divided into multiple modules.
2. Functions and variables may be defined in different files.
3. Library routines are needed during execution.
4. External references must be resolved.
• Functions of Linker
The main functions of linker are:
1. Combining object modules.
2. Resolving external symbol references.
3. Allocating memory addresses.
4. Producing executable files.
• Types of Linking
1. Static Linking
Static linking is the process in which all required library functions and modules are
copied directly into the executable program before execution.
In static linking, the linker combines the object file of the user program with all
necessary library routines and creates one complete executable file. After linking, the
program becomes independent and does not require external library files during
execution.
In simple words, all required code is permanently attached to the program at compile
time or link time.
• Working of Static Linking
1. The source program is compiled into object code.
2. The linker searches the required library functions.
3. Required library modules are copied into the executable file.
4. A final executable program is generated.
When the user runs the program, all required code is already present inside the
executable file.
• Advantages of Static Linking
1. Faster Execution
The program executes faster because all library code is already available inside the
executable file.
2. No Dependency on External Libraries
The executable program does not depend on external shared libraries during
execution.
3. Easy Program Distribution
The program can run on another system without installing additional library files.
4. Better Reliability
Even if the library file is deleted or updated in the system, the program still works
properly because its own copy of the library is present.
• Disadvantages of Static Linking
1. Large Executable Size
Since library routines are copied into the executable file, the size of the program
becomes large.
2. Memory Wastage
If multiple programs use the same library, each program stores its own copy, causing
unnecessary memory usage.
3. Difficult Library Updates
If a library function is updated, all programs must be recompiled and relinked.
Example of Static Linking
Suppose a C program uses mathematical functions from a math library.
In static linking, the linker copies all required math functions into the executable file
itself.

2. Dynamic Linking
Dynamic linking is the process in which library routines are linked to the program
during execution time instead of before execution.
In this method, the executable file contains only references to shared libraries. The
actual library code is loaded into memory when the program runs.
In simple words, the required library is connected to the program at run time.
• Working of Dynamic Linking
1. The source program is compiled into object code.
2. The linker creates references to shared libraries instead of copying library code.
3. During execution, the operating system loads the required shared libraries into
memory.
4. The program uses the shared library functions dynamically.
• Advantages of Dynamic Linking
1. Smaller Executable Size
The executable file remains small because library code is not copied into it.
2. Efficient Memory Usage
Multiple programs can share the same library in memory, reducing memory
consumption.
3. Easy Library Updates
If a shared library is updated, all programs automatically use the updated version
without recompilation.
4. Better Storage Utilization
Only one copy of the shared library is stored in the system.
• Disadvantages of Dynamic Linking
1. Slower Execution
The program may execute slightly slower because libraries are loaded during run
time.
2. Dependency on Shared Libraries
If the required library is missing from the system, the program may fail to execute.
3. Version Compatibility Problems
Sometimes programs may not work properly if the library version changes.
Example of Dynamic Linking
In Windows operating systems, DLL (Dynamic Link Library) files are used for dynamic
linking.
In Linux operating systems, shared object (.so) files are commonly used.
➢ Difference Between Static Linking and Dynamic Linking

Static Linking Dynamic Linking

In static linking, all required library functions are In dynamic linking, library functions are
copied into the executable program before loaded into the program during execution
execution. time.

The executable file size becomes large because The executable file size remains small
all library code is included in the program. because library code is stored separately.

Static linking does not require external library Dynamic linking requires shared library
files at run time. files during program execution.

The execution speed may be slightly


The execution speed is faster because all
slower because libraries are loaded at
required code is already available in memory.
run time.

In static linking, each program contains its own In dynamic linking, multiple programs can
copy of library functions. share the same library file.

Static linking uses more memory and storage Dynamic linking uses memory and
space. storage more efficiently.

If the library is updated, the program must be Library updates can be used directly
recompiled and relinked. without recompiling the program.

Static linking provides better portability because Dynamic linking may fail if the required
the program can run independently. shared library is missing in the system.
➢ Design Of Linker:-

A linker is an important system software program that combines multiple object modules and
library files into a single executable program.
The main purpose of the linker is to resolve external references and generate a final
executable file that can be loaded into memory for execution.

• Working of a Linker

The linker works in multiple steps.

Step 1: Collect Object Modules

The linker first collects all object files and library files required for the program.

Step 2: Build External Symbol Table

The linker creates a global symbol table containing all symbols defined in different modules.

Step 3: Resolve External References

The linker matches undefined symbols with their correct definitions from other modules.

For example, if Module A calls a function present in Module B, the linker connects them
properly.

Step 4: Perform Relocation

The linker adjusts memory addresses according to the final memory allocation.

All address-dependent instructions are modified correctly.


Step 5: Generate Executable File

Finally, the linker generates a complete executable program that can be executed by the
operating system.

• Components in the Design of a Linker

The design of a linker mainly contains the following components:

1. Input Modules

Input modules are the object files generated by the assembler or compiler.
These modules contain machine instructions, symbol definitions, and unresolved references.

Each module may contain:

• Program code

• Data section

• Symbol table

• Relocation information

The linker takes these object modules as input.

2. Symbol Table

The symbol table is an important data structure used by the linker.

It stores information about all symbols such as:

• Variable names

• Function names

• Memory addresses

• External references

The linker uses the symbol table to resolve references between different modules.

Example

If one module calls a function defined in another module, the linker uses the symbol table to
find the correct address of that function.

3. Relocation Information

Relocation information helps the linker modify addresses when the program is loaded into
memory.
Since modules may be loaded at different memory locations, address references must be
adjusted accordingly.

The linker checks relocation records and updates address values properly.

4. Library Search Module

Many programs use predefined library functions such as mathematical functions or input-
output routines.

The linker searches system libraries to find required routines and includes them in the
executable program.

Example:

• printf()

• scanf()

• sqrt()

5. Address Binding

Address binding is the process of assigning actual memory addresses to program instructions
and data.

The linker calculates the final addresses after combining all modules together.

➢ Linking in MS-DOS

Linking in MS-DOS is the process of combining different object modules and library files to
create a single executable program that can run in the MS-DOS operating system.

• Working of Linking in MS - DOS


The linking process in MS -DOS is performed in several steps.

1. Creation of Object Modules

The source program is first translated by an assembler or compiler into object modules.

These object files contain:

• Machine instructions
• Symbol definitions
• External references
• Relocation information
Example:

• .OBJ files are commonly generated object modules.

2. Collecting Object Files

The linker collects all object files and required library files that are part of the program.

For example, if a program is divided into multiple modules, all .OBJ files are given to the linker.

3. Resolving External References

Many modules use functions or variables defined in other modules.

The linker searches the symbol table and connects unresolved references with their correct
definitions.

Example:

If Module A calls a function defined in Module B, the linker finds the address of that function and
connects both modules.

4. Relocation of Addresses

The linker adjusts address references according to the final memory layout.

Since the program may be loaded at different memory locations, relocation information is used
to modify addresses properly.

5. Generating Executable File

After resolving references and relocation, the linker generates an executable file.

In MS -DOS, executable files are generally:

• .EXE files
• .COM files

These files can then be executed by the operating system.


➢ Loaders

A loader is an important system software program that is responsible for loading an


executable program from secondary storage into main memory for execution. After a
program is translated by a compiler or assembler and linked by the linker, the loader places
that executable program into RAM and prepares it for execution by the CPU.

• Basic Functions of Loader


The loader performs several important functions during the execution of a program.

1. Allocation
Allocation means assigning memory space to the program in main memory.
Before execution, the loader checks the availability of memory and allocates separate
memory locations for:
• Program instructions
• Data section
• Stack
• Variables
The loader ensures that the program gets sufficient memory space for proper
execution.

2. Linking
Some programs use functions and variables that are defined in other modules or
library files.
The loader resolves these external references by connecting the required modules
and library routines.
For example, if a C program uses the printf() function, the loader connects the
program with the required library routine.

3. Relocation
Sometimes the program cannot be loaded into the memory location assumed during
compilation.
In such situations, the loader changes address references according to the actual
memory location assigned to the program. This process is known as relocation.
Relocation Formula
New Address = Original Address + Relocation Factor
Relocation helps the operating system load programs into any available memory area.
4. Loading
The loader copies the executable instructions and data from secondary storage into
main memory.
After loading, the program becomes ready for execution.

5. Transfer of Control
After all loading operations are completed, the loader transfers the control of the
CPU to the starting instruction of the program.
Then the actual execution of the program begins.

• Types of Loaders
Different types of loaders are used according to the requirements of the system.

1. Compile-and-Go Loader
The compile-and-go loader is the simplest type of loader.
In this method, the source program is compiled and immediately loaded into memory for
execution without creating a separate object file.
The compiler itself performs the loading operation.

• Working of Compile-and-Go Loader


1. The programmer writes the source program.
2. The compiler translates the source code into machine code.
3. The machine code is directly placed into memory.
4. The program immediately starts execution.

• Advantages of Compile-and-Go Loader


1. Simple Method
The design and operation are simple and easy to understand.
2. Faster for Small Programs
Small programs can execute quickly because there is no separate loading step.
3. No Need for Object File
The program executes directly after compilation.

• Disadvantages of Compile-and-Go Loader


1. Recompilation Required
The program must be compiled every time before execution.
2. Wastage of Memory
The compiler remains in memory during execution, which wastes memory space.
3. Not Suitable for Large Programs
Large programs require too much memory and compilation time.
2. Absolute Loader
An absolute loader loads the program into a fixed memory location specified by the
programmer.
The addresses are fixed during compilation or assembly.

• Working of Absolute Loader


1. The object program contains fixed memory addresses.
2. The loader places the program into those exact addresses.
3. The loader transfers control to the program.
No address modification is performed.

• Advantages of Absolute Loader


1. Simple Design
The loader logic is simple because relocation is not required.
2. Fast Loading
Programs load quickly because addresses are already fixed.
3. Less Processing Overhead
No additional calculations are needed.

• Disadvantages of Absolute Loader


1. Fixed Memory Requirement
The program must always load into the same memory location.
2. Poor Memory Utilization
Free memory areas cannot be used efficiently.
3. No Flexibility
Multiple programs are difficult to manage.

3. Relocating Loader
A relocating loader can load programs into different memory locations according to memory
availability.
It adjusts address references dynamically before execution.

• Working of Relocating Loader


1. The loader calculates the relocation factor.
2. It modifies all address-dependent instructions.
3. The program is loaded into available memory.
4. Execution starts after relocation.

• Advantages of Relocating Loader


1. Better Memory Utilization
Programs can load into any available memory location.
2. Supports Multiprogramming
Multiple programs can execute simultaneously.
3. Flexible Program Loading
Programs are not restricted to fixed addresses.

• Disadvantages of Relocating Loader


1. Complex Design
Additional relocation logic is required.
2. Extra Processing Time
Address modification increases loading time.

4. Linking Loader

A linking loader performs both linking and loading operations [Link] combines object
modules, resolves external references, performs relocation, and loads the program into
memory.

• Working of Linking Loader


1. The loader collects all object modules.
2. It creates a global symbol table.
3. External references are resolved.
4. Relocation is performed.
5. The final program is loaded into memory.

• Advantages of Linking Loader


1. Supports Modular Programming
Large programs can be divided into smaller modules.
2. Automatic Linking
External references are resolved automatically.
3. Reduces Programmer Work
The programmer does not manually combine modules.

• Disadvantages of Linking Loader


1. More Complex Operation
The loader performs multiple tasks simultaneously.
2. Increased Loading Time
Linking and relocation require extra time.
5. Dynamic Loader
A dynamic loader loads library routines only when they are needed during execution.
Unused routines are not loaded into memory.

• Working of Dynamic Loader


1. The main program starts execution.
2. When a library function is needed, the loader loads it dynamically.
3. Shared libraries may be used by many programs.

• Advantages of Dynamic Loader


1. Efficient Memory Usage
Only required routines are loaded.
2. Smaller Executable File
Library code is not copied into the executable file.
3. Shared Libraries Support
Multiple programs can use the same library.

• Disadvantages of Dynamic Loader


1. Slower Execution
Loading libraries during run time takes extra time.
2. Dependency Problems
Programs may fail if the required library is missing.

➢ Sequential Loader and Direct Loader

• Sequential Loader
A sequential loader is a type of loader in which the object program is loaded into memory in
a sequential manner, one instruction after another, starting from the beginning of the
program.
The sequential loader reads the object file continuously from start to end and loads the
instructions into memory in the same sequence in which they are stored in the object file.

• Working of Sequential Loader


The working of a sequential loader involves the following steps:
1. Reading the Object Program
The loader reads the object program from secondary storage such as a hard disk.
The object program is read record by record from the beginning.
2. Allocation of Memory
The loader allocates memory space for the program.
Generally, the program is loaded into consecutive memory locations.
3. Loading Instructions Sequentially
The loader places instructions and data into memory one after another in sequence.
The instructions are loaded according to the order present in the object file.

4. Address Processing
If relocation is required, the loader modifies address values during loading.

5. Transfer of Control
After all instructions are loaded, the loader transfers CPU control to the starting
address of the program.
The program execution then begins.

➢ Direct Loader
A direct loader is a type of loader that loads the program directly into the required memory
locations without processing the entire object file sequentially.
In a direct loader, the loader can directly access specific records or instructions using address
information.
• Working of Direct Loader
The working of a direct loader includes the following steps:
1. Reading Address Information
The loader first reads the address information present in the object program.

2. Direct Memory Allocation


The loader identifies the target memory location where each instruction or data item
should be placed.

3. Direct Loading of Instructions


Instructions are directly loaded into their corresponding memory locations.
The loader does not need to process the entire program sequentially.

4. Relocation if Required
If relocation is needed, the loader modifies addresses before placing instructions into
memory.

5. Start Execution
After loading all required parts, the loader transfers control to the program for
execution.
➢ Difference Between Linkers and Loaders
Linker Loader

A linker is a system software program A loader is a system software


that combines different object modules program that loads the executable
and library files into a single executable program into main memory for
program. execution.

The main function of the linker is to The main function of the loader is
resolve external references between to place the program into memory
different program modules. and start its execution.

The linker works after compilation or The loader works after the linking
assembly and before loading. process is completed.

The loader does not create


The linker generates an executable file executable files; it only loads them
such as .EXE or .COM. into memory.

The linker combines separately compiled The loader transfers the


program modules into one complete executable program from
program. secondary storage into RAM.

The loader performs memory


The linker performs symbol resolution allocation, relocation, and loading
and address binding between modules. operations.

The linker may search library files to The loader may load shared
include required functions into the libraries into memory during
executable file. execution.

The linker mainly works with object files The loader mainly works with
and library files. executable files.

The linker helps in modular programming The loader helps in executing the
by connecting multiple modules program by preparing memory and
together. transferring control to the CPU.

The linker resolves unresolved external The loader adjusts memory


symbols between different modules. addresses if relocation is required.

Examples of loaders are absolute


Examples of linkers are GNU Linker and loader, relocating loader, and
MS-DOS LINK utility. dynamic loader.
Ch:-3(15%)
➢ Elements of Assembly Language Programming
Assembly language programming is a low-level programming language that is closely related
to machine language. It uses mnemonic codes and symbolic names instead of binary
instructions, making programming easier for programmers.

• Main Elements of Assembly Language Programming


The following are the important elements of assembly language programming:
1. Machine Instructions
2. Mnemonic Operation Codes
3. Operands
4. Labels
5. Comments
6. Assembler Directives
7. Symbolic Addresses
8. Data Definition Statements
9. Constants and Variables
10. Program Structure

1. Machine Instructions
Machine instructions are binary instructions that are directly understood by the CPU.
In assembly language programming, machine instructions are represented using
mnemonic codes. Each instruction performs a specific operation such as addition,
subtraction, data transfer, or branching.
Every instruction generally contains:
• Operation code (Opcode)
• Operand
Example
MOV A, B
ADD A, C
Here, MOV and ADD are instructions.

2. Mnemonic Operation Codes


Mnemonic operation codes are symbolic abbreviations used instead of binary
machine codes.
These mnemonics make programs easier to read, write, and remember.
Examples of Mnemonics
Mnemonic Meaning

MOV Move data


Mnemonic Meaning

ADD Addition

SUB Subtraction

JMP Jump

MUL Multiplication

Instead of writing binary instructions, programmers use these simple words.

3. Operands
Operands are the data items or memory locations on which operations are
performed.
Operands may represent:
• Registers
• Memory addresses
• Constants
• Variables
Example
ADD A, B
In this instruction:
• ADD is the operation code.
• A and B are operands.
The instruction adds the contents of operand B to operand A.

4. Labels
Labels are symbolic names used to identify memory locations or instructions.
Labels make programs easier to understand and help in branching and looping
operations.
A label is generally written at the beginning of a line.
Example
LOOP: ADD A, B
Here, LOOP is a label.
The program can jump directly to this labeled instruction when required.

5. Comments
Comments are explanatory statements written inside the program to improve
readability and understanding.
Comments are ignored by the assembler and do not affect program execution.
They help programmers understand the purpose of instructions.
Example
MOV A, B ; Move value of B into A
The text after ; is a comment.

6. Assembler Directives
Assembler directives are special instructions given to the assembler.
These directives do not generate machine code but guide the assembler during
translation.
They help in defining memory areas, constants, and program organization.
Common Directives
Directive Purpose

START Indicates beginning of program

END Indicates end of program

DB Define byte

DW Define word

EQU Define constant

Example
START 100
This directive tells the assembler the starting address of the program.

7. Symbolic Addresses
Symbolic addresses are names used instead of actual memory addresses.
Using symbolic names improves program readability and simplifies modification.
Example
COUNT DB 10
Here, COUNT is a symbolic address.
Instead of remembering memory locations, programmers use meaningful names.

8. Data Definition Statements


Data definition statements are used to define and reserve memory space for
variables and constants.
These statements specify the type and size of data.
Examples
NUM DB 25
VALUE DW 1000
• DB defines a byte.
• DW defines a word.
9. Constants and Variables
Constants are fixed values that do not change during program execution.
Variables are memory locations whose values can change during execution.
Example
MAX EQU 100
COUNT DB 0
• MAX is a constant.
• COUNT is a variable.

10. Program Structure


An assembly language program follows a structured format.
A typical assembly program contains:
1. Program initialization
2. Data section
3. Instruction section
4. Program termination
Basic Format
START
Instructions
END
This structure helps the assembler understand the organization of the program.
➢ Design of the Assembler.

An assembler is an important system software program that translates an assembly


language program into machine language program. Assembly language uses mnemonic
instructions and symbolic addresses, while the computer can understand only binary
machine instructions. Therefore, the assembler converts assembly language into
machine code so that the CPU can execute the program.
• Basic Functions of an Assembler

The assembler performs several important functions during program translation.

1. Translation of Instructions

The assembler converts mnemonic operation codes into machine language opcodes.

Example:

ADD A, B

is converted into its binary machine instruction.

2. Address Assignment

The assembler assigns memory addresses to instructions, variables, labels, and data items.

3. Symbol Table Management

The assembler creates and maintains a symbol table that stores labels, variable names, and
their addresses.

4. Error Detection

The assembler checks for syntax errors, undefined symbols, invalid instructions, and
duplicate labels.

5. Object Code Generation

The assembler generates object code or machine code after successful translation.
• Main Components in the Design of Assembler

The design of an assembler contains several important components.

1. Input Program

The input program is the assembly language source program written by the programmer.

It contains:

• Mnemonic instructions

• Labels

• Operands

• Directives

• Comments

Example:

START 100
MOV A, B
ADD A, C
END

2. Opcode Table (OPTAB)

The opcode table stores mnemonic operation codes and their corresponding machine codes.

The assembler uses this table during instruction translation.

Example of OPTAB

Mnemonic Machine Code

ADD 01

SUB 02

MOV 03

JMP 04

When the assembler reads an instruction, it searches OPTAB to find the correct machine
opcode.
3. Symbol Table (SYMTAB)

The symbol table stores symbolic names and their corresponding memory addresses.

It helps the assembler resolve labels and variables.

Example of SYMTAB

Symbol Address

LOOP 205

COUNT 300

The assembler updates this table whenever a new symbol is encountered.

4. Location Counter (LC)

The location counter keeps track of the current memory address during assembly.

Whenever an instruction or data item is processed, the location counter is updated.

Example

If the current address is 200 and the instruction size is 2 bytes, the next address becomes
202.

5. Intermediate File

During translation, the assembler may create an intermediate file.

This file stores partially processed information such as:

• Instruction details

• Addresses

• Symbol references

The intermediate file is mainly used in two-pass assemblers.

6. Error Handler

The error handling module detects errors in the source program.

Common errors include:

1. Invalid opcode

2. Undefined symbol

3. Duplicate label

4. Syntax error
5. Missing operand

The assembler displays appropriate error messages for correction.

7. Object Code Generator

This component generates the final machine code or object program after successful
translation.

The object code is stored in an object file that can later be linked and loaded.

• Working of Assembler

The assembler generally works in multiple phases or passes.

Pass 1 of Assembler

During Pass 1, the assembler mainly performs address assignment and symbol table
creation.

Activities Performed in Pass 1

1. Read source program line by line.

2. Assign addresses using the location counter.

3. Create the symbol table.

4. Process assembler directives.

5. Detect basic syntax errors.

6. Generate intermediate file.

Example

If a label named LOOP appears in the program, its address is stored in SYMTAB.

Pass 2 of Assembler

During Pass 2, the assembler generates the final object code.

Activities Performed in Pass 2

1. Read the intermediate file.

2. Translate mnemonics using OPTAB.

3. Replace symbols using SYMTAB.

4. Generate machine code.

5. Produce object program.


• Types of Assemblers

1. Single Pass Assembler

A single pass assembler processes the source program only once.

It performs symbol table generation and code generation together.

• Advantages

1. Faster assembly process.

2. Less processing time.

• Disadvantages

1. Forward references are difficult to handle.

2. More complex design.

2. Two Pass Assembler

A two pass assembler processes the program in two separate passes.

• Pass 1 creates the symbol table.

• Pass 2 generates machine code.

• Advantages

1. Easy handling of forward references.

2. Better error detection.

• Disadvantages

1. More processing time.

2. Requires intermediate storage.


• Advantages of Assembler Design

1. Simplifies machine language programming.

2. Makes programs easier to read and maintain.

3. Supports symbolic programming.

4. Detects syntax and logical errors.

5. Generates efficient machine code.

• Disadvantages of Assembler

1. Assembly language is machine dependent.

2. Programming is more difficult than high-level languages.

3. Large programs are difficult to manage.

4. Requires hardware knowledge.

• Applications of Assembler

Assemblers are mainly used in:

1. System software development.

2. Embedded systems.

3. Operating system programming.

4. Device driver development.

5. Real-time systems.

➢ Assembler Design Criteria

Assembler design criteria are the important rules, principles, and factors that must be
considered while designing an assembler. An assembler is a system software program that
converts assembly language instructions into machine language instructions.
• Important Assembler Design Criteria

The following are the major criteria considered while designing an assembler:

1. Efficiency

2. Simplicity

3. Speed of Translation

4. Memory Management

5. Error Detection and Error Handling

6. Symbol Table Management

7. Handling of Forward References

8. Machine Dependency Support

9. Object Code Generation

10. Flexibility and Expandability

11. Relocation Support

12. Modular Programming Support

13. Support for Different Addressing Modes

14. Macro Processing Support

1. Efficiency

Efficiency is one of the most important design criteria of an assembler.

The assembler should generate machine code that executes efficiently on the target
machine. The generated code should use minimum memory and CPU time.

The assembler itself should also consume minimum system resources during translation.

An efficient assembler reduces unnecessary processing and generates optimized object


code.

For example, the assembler should avoid generating extra instructions that waste execution
time.

Efficient assemblers improve overall system performance and reduce program execution
cost.
2. Simplicity

The design of the assembler should be simple and easy to understand.

A simple assembler is easier to implement, maintain, test, and debug. Complex assembler
designs increase development difficulty and may introduce errors.

The internal structure of the assembler should be organized clearly with separate modules
for:

• Instruction translation

• Symbol handling

• Error checking

• Object code generation

Simple design also helps programmers learn assembly language programming more easily.

3. Speed of Translation

The assembler should translate assembly language programs into machine code quickly.

Fast translation reduces program development time and improves productivity.

Translation speed becomes very important for large assembly language programs containing
thousands of instructions.

The assembler should use efficient searching and processing algorithms for:

• Opcode lookup

• Symbol table access

• Address calculations

Efficient data structures such as hash tables may improve translation speed.

4. Memory Management

The assembler should use memory efficiently during the assembly process.

During translation, the assembler stores many types of information such as:

• Symbol tables

• Opcode tables

• Intermediate files
• Object code

• Temporary variables

Improper memory management may waste system resources and reduce performance.

A good assembler allocates and releases memory properly to avoid unnecessary memory
consumption.

Efficient memory management is especially important for large assembly language


programs.

5. Error Detection and Error Handling

The assembler should detect program errors accurately and provide meaningful error
messages.

Good error handling helps programmers identify and correct mistakes easily.

The assembler should detect different types of errors such as:

Syntax Errors

These occur when assembly language rules are violated.

Example:

MOV ,A

Undefined Symbols

These occur when symbols are used without definition.

Example:

JMP LOOP

If LOOP is not defined, an error occurs.

Duplicate Labels

These occur when the same label is defined multiple times.


Invalid Opcodes

These occur when unknown instructions are used.

Example:

ADDD A,B

Operand Errors

These occur when incorrect operands are provided.

The assembler should display proper line numbers and descriptive messages for easy
debugging.

6. Symbol Table Management

The assembler must maintain a proper symbol table.

The symbol table stores information about:

• Labels

• Variables

• Constants

• Addresses

The symbol table is very important because assembly language programs use symbolic
names instead of actual memory addresses.

Example of Symbol Table

Symbol Address

LOOP 205

COUNT 300

Efficient symbol table management helps the assembler quickly search, insert, and update
symbols.

The assembler should prevent duplicate symbol definitions and support fast symbol lookup.
7. Handling of Forward References

A forward reference occurs when a symbol is used before it is defined later in the program.

Example

JMP LOOP
...
LOOP: ADD A,B

Here, the label LOOP is referenced before its actual definition.

The assembler design should properly support forward references.

Two-pass assemblers are commonly used because they can easily resolve forward
references.

During Pass 1, the assembler records symbols and addresses. During Pass 2, it resolves the
references correctly.

Proper forward reference handling is an important criterion for assembler design.

8. Machine Dependency Support

Assembly language is machine dependent because each processor architecture has its own:

• Instruction set

• Registers

• Addressing modes

• Memory organization

Therefore, the assembler must support all hardware features of the target machine.

The assembler design should correctly handle:

1. Instruction formats

2. Register structures

3. Opcode encoding

4. Address calculations

The assembler should generate machine code according to the architecture of the processor.
9. Object Code Generation

The assembler should generate correct and efficient object code.

The generated object program generally contains:

• Machine instructions

• Relocation information

• Symbol information

• External reference details

The object code should be compatible with linkers and loaders.

Incorrect object code generation may prevent successful program execution.

10. Flexibility and Expandability

A good assembler should be flexible and expandable.

New instructions, directives, or processor features should be added easily without


redesigning the entire assembler.

Modern computer systems evolve continuously, so the assembler should support future
expansion.

Flexible assembler design improves long-term usability and maintenance.

➢ Single pass assembler for intel x86.


1. Introduction
• A single pass assembler scans the source program only once and generates object
code during that single scan itself.
• It does not make a second scan of the source code, making it faster and memory-
efficient.
• The fundamental challenge it introduces is known as the forward reference problem.
• Intel x86 assembler is a well-known practical case where single pass assembly
concepts are studied and applied.

2. Concept of Single Pass Assembly


• The entire source code is processed from top to bottom exactly one time.
• As each instruction is encountered, the assembler immediately attempts to translate
it into machine code.
• The Location Counter (LC), also called the Program Counter, is updated after
processing each instruction.
• Directives such as DB, DW, DD, and SEGMENT are processed as they are encountered.
• The key data structures used are:
o Symbol Table
o Mnemonic Opcode Table (MOT)
o Table of Incomplete Instructions (TII)

3. Forward Reference Problem


• A forward reference occurs when a symbol (label) is used in an instruction before it is
defined in the source code.
• Example: JMP LOOP appears before the label LOOP: is defined further down in the
program.
• Since the assembler has not yet encountered LOOP, it does not know the address to
place in the machine instruction.
• In a two-pass assembler, this is easily resolved in the first pass; a single pass
assembler must use a different mechanism.
• The assembler generates an incomplete instruction (leaving the address field
blank/placeholder) and records it in the Table of Incomplete Instructions (TII).
• When the symbol is eventually defined later, the assembler goes back and patches all
incomplete instructions that referenced that symbol.

4. Data Structures Used


a) Symbol Table
• Stores each label along with its assigned memory address.
• If a label is a forward reference (used but not yet defined), it is entered with an
undefined flag.
• A list of incomplete instruction locations is maintained for each undefined symbol.
b) Mnemonic Opcode Table (MOT)
• Contains all Intel x86 mnemonics like MOV, ADD, SUB, JMP, CALL, etc.
• Stores corresponding opcodes, instruction length, and operand format information.
• Allows the assembler to immediately determine the binary encoding for each
instruction.
c) Table of Incomplete Instructions (TII)
• Stores the memory address of each instruction whose operand address could not be
determined due to a forward reference.
• Once the forward-referenced symbol gets defined, the assembler uses the TII to
patch all those addresses in the output buffer.
5. Working of Single Pass Assembler
• The assembler initializes the Location Counter (LC) to the starting address of the code
segment.
• It then reads each statement of the source program one at a time and performs the
following:
When a Label is encountered:
• If already present in the symbol table (previously referenced as forward reference),
the current LC value is assigned to it and all TII entries for that symbol are patched.
• If the label is new, it is simply added to the symbol table with the current LC value.
When an Instruction is encountered:
• The assembler looks up the MOT to find the opcode and instruction size.
• If the operand symbol is already defined → complete machine instruction is
generated immediately.
• If the operand symbol is not yet defined (forward reference) → an incomplete
instruction with a placeholder is generated and its location is recorded in the TII.
• The LC is incremented by the instruction size.
When an Assembler Directive is encountered:
• Directives like DB, DW, SEGMENT, ASSUME are processed accordingly.
• The END directive signals end of source program.
• At END, if any symbols still remain unresolved in TII → assembler reports them as
undefined symbol errors.

6. Algorithm of Single Pass Assembler


• Step 1: Set LC = 0 (or the defined starting address).
• Step 2: Read the next source line.
• Step 3: If the line has a label:
o If found in symbol table as undefined → set symbol value = LC, patch all TII
entries.
o If not found → add the symbol to the symbol table with value = LC.
• Step 4: If the statement is an instruction:
o Look up the MOT for opcode.
o If operand is a defined symbol → generate complete object code.
o If operand is undefined (forward reference) → generate incomplete
instruction, add to TII.
• Step 5: If the statement is a directive (DB, DW, etc.) → allocate memory, update LC.
• Step 6: Increment LC by size of instruction or data.
• Step 7: If END directive is not reached → go to Step 2.
• Step 8: If TII still contains unresolved entries → report errors for undefined symbols.
• Step 9: Stop.
7. Intel x86 Specific Features
• Intel x86 instructions have variable-length encoding, ranging from 1 byte to 15 bytes
per instruction.
• This makes single pass assembly for x86 more complex compared to fixed-length
architectures.
• The assembler must know the exact size of each instruction when first processed so
that LC can be correctly updated, even if the operand address is unknown.
• For jump instructions with forward references, the assembler may assume a short
jump (2 bytes); if the target is too far, a near jump (5 bytes) is needed — requiring
additional backpatching.
• Intel x86 programs are organized into segments using SEGMENT and ENDS directives.
• The ASSUME directive tells the assembler which segment registers correspond to
which segments — handled as encountered during the single pass.

8. Advantages of Single Pass Assembler


• Reads the source code only once, making it significantly faster than a two-pass
assembler.
• Requires less time for assembly — important in older computing environments with
limited memory and storage.
• Requires a simpler file I/O mechanism since the source file does not need to be re-
read.
• Suitable for real-time or embedded environments where assembly speed is critical.

9. Disadvantages of Single Pass Assembler


• Cannot efficiently handle all forward references, especially in complex cases.
• The TII and backpatching mechanism adds internal complexity to the assembler
design.
• For Intel x86 with variable-length instructions, optimizing jump instruction sizes
becomes difficult in a single pass.
• May lead to suboptimal or larger object code due to the conservative size
assumptions made during forward references.

➢ Multi-Pass Assemblers

A Multi-Pass Assembler is an assembler that processes the source program more than one
time in order to translate assembly language into machine language correctly.

In a multi-pass assembler, the assembly process is divided into multiple passes.


• Working of Multi-Pass Assembler

The multi-pass assembler processes the source program multiple times.

Different operations are performed during each pass.

Pass 1 of Multi-Pass Assembler

The first pass mainly performs address assignment and symbol table creation.

During this pass, the assembler scans the source program line by line.

Functions Performed in Pass 1

1. Reading Source Program

The assembler reads each instruction and directive from the source program.

2. Assigning Addresses

The assembler uses a location counter to assign addresses to instructions and data items.

The location counter increases according to instruction size.

3. Creating Symbol Table

Whenever labels or symbols are found, their addresses are stored in the symbol table.

Example

LOOP: ADD A,B

The symbol LOOP and its address are stored in SYMTAB.

4. Processing Assembler Directives

Assembler directives such as START, END, DB, and DW are processed.

5. Detecting Basic Errors

The assembler checks for syntax errors and duplicate labels.


6. Generating Intermediate File

An intermediate file is generated for use in the next pass.

This file contains partially processed program information.

Pass 2 of Multi-Pass Assembler

The second pass mainly performs machine code generation.

During this pass, the assembler uses the symbol table and opcode table created during Pass
1.

Functions Performed in Pass 2

1. Reading Intermediate File

The assembler reads the intermediate file generated during Pass 1.

2. Opcode Translation

Mnemonic operation codes are translated into machine opcodes using OPTAB.

Example

Mnemonic Opcode

ADD 01

MOV 02

3. Resolving Symbols

The assembler replaces symbolic addresses using the symbol table.

4. Generating Machine Code

Final machine instructions are generated.

5. Generating Object Program

The assembler creates the object file containing executable machine code.
6. Reporting Remaining Errors

Any unresolved symbols or operand errors are reported.

• Structure of Multi-Pass Assembler

The basic structure of a multi-pass assembler contains the following components:

1. Source Program

2. Opcode Table (OPTAB)

3. Symbol Table (SYMTAB)

4. Location Counter

5. Intermediate File

6. Object Code Generator

• Block Diagram of Multi-Pass Assembler

Source Program

Pass 1
(Symbol Table Creation)

Intermediate File

Pass 2
(Object Code Generation)

Object Program

• Advantages of Multi-Pass Assembler

1. Easy Handling of Forward References

The biggest advantage of multi-pass assemblers is that they can easily resolve forward
references.

Symbols are collected during Pass 1 and resolved during Pass 2.


2. Better Error Detection

Errors can be detected more accurately because the assembler has complete symbol
information before generating code.

3. Simplified Design

The assembler logic becomes simpler because different tasks are separated into different
passes.

4. Accurate Object Code Generation

Machine code generation becomes more reliable and accurate.

5. Suitable for Large Programs

Multi-pass assemblers are suitable for large and complex assembly language programs.

• Disadvantages of Multi-Pass Assembler

1. More Processing Time

Since the source program is processed multiple times, assembly takes more time.

2. Increased Disk Usage

Intermediate files require additional storage space.

3. More Input/Output Operations

Reading the source program multiple times increases I/O operations.

4. Slower than Single Pass Assembler

A multi-pass assembler is generally slower than a single pass assembler.


➢ Difference Between Single Pass Assembler and Multi-Pass Assembler

Single Pass Assembler Multi-Pass Assembler

A single pass assembler processes the


A multi-pass assembler processes the source
source program only one time during
program more than one time during assembly.
assembly.

In a single pass assembler, symbol table In a multi-pass assembler, different tasks are
generation and machine code generation divided into separate passes such as symbol
are performed together in one pass. table creation and object code generation.

A single pass assembler generates object A multi-pass assembler first collects symbol
code immediately while reading the source information and then generates object code in
program. later passes.

The assembly process is faster because the The assembly process is slower because the
program is scanned only once. program is scanned multiple times.

The design of a single pass assembler is The design of a multi-pass assembler is


more complex because multiple tasks are simpler and more organized because tasks are
performed simultaneously. separated into different passes.

A multi-pass assembler requires more input


A single pass assembler requires less input
and output operations because of repeated
and output operations.
scanning.

Error detection capability is limited in a Better and more accurate error detection is
single pass assembler. possible in a multi-pass assembler.

A single pass assembler is more suitable for A multi-pass assembler is more suitable for
small programs and simple systems. large and complex programs.

The memory requirement is generally higher


The memory requirement is generally lower
in a multi-pass assembler because additional
in a single pass assembler.
tables and files are maintained.

A multi-pass assembler can easily support


A single pass assembler is difficult to
complex instruction sets and advanced
implement for complex instruction sets.
features.

Multi-pass assemblers are commonly used in


Single pass assemblers are commonly used
system software and modern assembly
in simple and fast assembly systems.
systems.
➢ Advanced Assembly Process

The advanced assembly process is the detailed and improved procedure used by modern
assemblers to translate assembly language programs into machine language programs. In
modern computer systems, assembly language programs may be large and complex, so the
assembler must perform many advanced operations such as symbol management, address
resolution, relocation handling, macro expansion, error checking, and object code
generation.

• Main Phases of Advanced Assembly Process

The advanced assembly process is generally divided into several phases. Each phase
performs a specific task during assembly.

The important phases are:

1. Lexical Analysis

2. Syntax Analysis

3. Symbol Table Generation

4. Location Counter Processing

5. Macro Processing

6. Intermediate Code Generation

7. Address Resolution

8. Object Code Generation

9. Relocation and Linking Information Generation

10. Error Detection and Reporting

1. Lexical Analysis

Lexical analysis is the first phase of the advanced assembly process.

In this phase, the assembler reads the source program line by line and divides each
statement into smaller units called tokens.

These tokens may include:

• Mnemonic operation codes

• Labels

• Operands
• Constants

• Directives

The assembler identifies the different parts of each instruction and prepares them for
further processing.

Example

ADD A,B

The assembler separates this statement into:

• ADD → Opcode

• A and B → Operands

Lexical analysis helps the assembler understand the structure of the source program.

Without lexical analysis, the assembler cannot correctly interpret assembly language
instructions.

2. Syntax Analysis

Syntax analysis is the process of checking whether the instructions follow the correct
assembly language grammar and rules.

The assembler verifies:

1. Correct instruction format

2. Proper operand usage

3. Valid opcode structure

4. Correct placement of labels and directives

If the instruction format is incorrect, the assembler reports syntax errors.

Example of Correct Instruction

MOV A,B

Example of Incorrect Instruction

MOV ,A

In the second instruction, the operand is missing before the comma, so the assembler
reports a syntax error.

Syntax analysis improves program correctness and helps programmers identify mistakes
easily.
3. Symbol Table Generation

During assembly, the assembler creates a symbol table called SYMTAB.

The symbol table stores important information about symbols used in the program.

The symbol table generally contains:

• Labels

• Variables

• Constants

• Memory addresses

Example of Symbol Table

Symbol Address

LOOP 205

COUNT 300

Whenever the assembler encounters a label or variable, it stores the symbol and its address
in the symbol table.

The symbol table is very important because assembly language programs use symbolic
names instead of actual memory addresses.

Later, the assembler uses the symbol table to replace symbolic references with actual
addresses.

4. Location Counter Processing

The assembler uses a location counter to assign memory addresses to instructions and data
items.

The location counter keeps track of the current memory location during the assembly
process.

Whenever an instruction or data item is processed, the location counter is updated


according to the size of that instruction.
Example

Suppose the current memory address is 200 and the instruction occupies 2 bytes.

Then:

Next Address = 200 + 2 = 202

The location counter helps the assembler allocate memory addresses correctly.

Proper address assignment is necessary for accurate machine code generation and
relocation support.

5. Macro Processing

Modern assemblers support macro instructions.

A macro is a predefined block of instructions that can be reused multiple times by writing
only the macro name.

Macro processing reduces repetitive coding and improves programming efficiency.

Example

INCR MACRO
ADD A,1
ENDM

Whenever the programmer writes:

INCR

the assembler automatically replaces it with:

ADD A,1

Macro processing saves programming time and improves program readability.

It also reduces coding errors because the same instructions do not need to be written
repeatedly.
6. Intermediate Code Generation

In advanced assembly systems, the assembler may generate an intermediate file after the
first pass.

This intermediate file stores partially processed program information such as:

• Instruction details

• Symbol references

• Assigned addresses

• Opcode information

The intermediate file is later used during object code generation.

Intermediate code generation simplifies multi-pass assembly operations and improves


processing efficiency.

7. Address Resolution

Address resolution is the process of replacing symbolic addresses with actual memory
addresses.

The assembler uses the symbol table to resolve all labels and variables.

Example

JMP LOOP

If the symbol LOOP has address 250, the assembler replaces LOOP with 250.

Address resolution is especially important for handling forward references.

Without proper address resolution, the generated machine code would be incorrect.

8. Object Code Generation

Object code generation is one of the most important phases of the advanced assembly
process.

During this phase, the assembler converts assembly language instructions into machine
language instructions.

The assembler performs the following operations:

1. Converts mnemonics into machine opcodes.

2. Replaces symbols with actual addresses.


3. Generates binary machine instructions.

4. Creates object program records.

Example

Mnemonic Machine Opcode

ADD 01

MOV 02

The generated object code is stored in an object file for linking and loading.

9. Relocation and Linking Information Generation

Modern assemblers generate relocation and linking information for loaders and linkers.

Relocation information helps programs load into different memory locations.

Linking information helps combine multiple program modules together.

This feature supports:

• Multiprogramming

• Modular programming

• Dynamic memory allocation

Relocation support increases program flexibility and improves memory utilization.

10. Error Detection and Reporting

The assembler continuously checks the source program for errors during assembly.

The assembler detects various types of errors such as:

1. Invalid opcode errors

2. Syntax errors

3. Undefined symbols

4. Duplicate labels

5. Missing operands

6. Addressing errors
The assembler generates proper error messages with line numbers to help programmers
debug the program easily.

Good error reporting improves software reliability and reduces development time.

• Features of Advanced Assembly Process

The advanced assembly process provides many important features.

1. It supports multi-pass assembly.

2. It handles forward references efficiently.

3. It supports modular programming.

4. It generates relocatable object code.

5. It provides better error handling.

6. It supports macros and reusable instructions.

7. It supports large and complex assembly programs.

8. It improves machine code efficiency.

• Advantages of Advanced Assembly Process

1. Efficient Machine Code Generation

The assembler generates optimized machine instructions for better performance.

2. Better Program Organization

Programs can be divided into modules for easier management.

3. Improved Error Detection

Errors are detected accurately during assembly.

4. Simplified Programming

Macros and symbolic programming simplify coding.

5. Support for Modern Systems

Advanced assemblers support modern processors and operating systems.


• Disadvantages of Advanced Assembly Process

1. Increased Complexity

The assembler design becomes more complex because of advanced features.

2. More Memory Requirement

Intermediate files and tables require additional memory.

3. Increased Processing Time

Multiple passes and advanced processing increase assembly time.

➢ Variants of Assemblers

Different assemblers are designed according to system requirements, processing methods,


and programming features. These different types are known as variants of assemblers.

Each variant of assembler uses a different method for translating assembly language
programs into machine language programs.

In simple words, assembler variants are different types of assemblers developed for different
assembly requirements and system architectures.

The main variants of assemblers are:

1. Single Pass Assembler

2. Two Pass Assembler

3. Multi-Pass Assembler

4. Load-and-Go Assembler

5. Macro Assembler

6. Cross Assembler

1. Single Pass Assembler

A single pass assembler processes the source program only one time.

During this single pass, the assembler performs:

• Symbol table generation

• Address assignment

• Machine code generation

all together.
The main advantage of a single pass assembler is faster assembly because the source
program is scanned only once.

However, handling forward references becomes difficult because symbols may be used
before their definitions appear.

Single pass assemblers are mainly suitable for small programs and simple systems.

2. Two Pass Assembler

A two pass assembler processes the source program in two separate passes.

During Pass 1, the assembler creates the symbol table and assigns addresses.

During Pass 2, the assembler generates machine code using the information collected during
Pass 1.

Two pass assemblers can easily handle forward references and provide better error
detection.

These assemblers are widely used in modern systems because of their simplicity and
reliability.

3. Multi-Pass Assembler

A multi-pass assembler processes the source program more than two times.

Additional passes may be used for:

• Code optimization

• Macro expansion

• Relocation handling

• Advanced error checking

Multi-pass assemblers are mainly used for large and complex assembly systems.

They provide better flexibility but require more processing time.

4. Load-and-Go Assembler

A load-and-go assembler directly loads the generated machine code into memory after
assembly.

Separate object files are not created.

The program can execute immediately after assembly.

This method is simple and useful for small programs and educational systems.

However, recompilation is required every time before execution.


5. Macro Assembler

A macro assembler supports macro instructions.

Macros are predefined groups of instructions that can be reused multiple times.

The assembler automatically expands macros during assembly.

Macro assemblers reduce repetitive coding and improve programmer productivity.

They are commonly used in system programming and large assembly language projects.

6. Cross Assembler

A cross assembler runs on one computer system but generates machine code for another
computer system.

For example, a program may run on a Windows computer but generate machine code for an
embedded processor.

Cross assemblers are mainly used in embedded systems and microcontroller programming.

• Design of Two Pass Assembler

A two pass assembler is one of the most commonly used assemblers in system software.

It processes the assembly language program in two separate passes to generate machine
code efficiently and accurately.

The main objective of the two pass assembler is to handle forward references easily and
generate correct object code.

In simple words, the first pass collects information about the program, and the second pass
uses that information to generate machine code.

• Need of Two Pass Assembler

The two pass assembler is needed because assembly language programs may contain
forward references where symbols are used before their definitions.
Example

JMP LOOP
...
LOOP: ADD A,B

Here, the symbol LOOP is referenced before it is defined.

A two pass assembler solves this problem efficiently.

The following are the main reasons for using a two pass assembler:

1. To handle forward references.

2. To improve symbol management.

3. To generate accurate object code.

4. To simplify assembler design.

5. To provide better error handling.

• Structure of Two Pass Assembler

The design of a two pass assembler mainly contains the following components:

1. Source Program

2. Opcode Table (OPTAB)

3. Symbol Table (SYMTAB)

4. Location Counter (LC)

5. Intermediate File

6. Object Code Generator

1. Source Program

The source program is the assembly language program written by the programmer.

It contains:

• Instructions

• Labels

• Operands

• Directives

• Comments
2. Opcode Table (OPTAB)

The opcode table stores mnemonic instructions and their corresponding machine opcodes.

Example

Mnemonic Opcode

ADD 01

MOV 02

JMP 03

The assembler searches this table during machine code generation.

3. Symbol Table (SYMTAB)

The symbol table stores labels and their addresses.

Example

Symbol Address

LOOP 205

COUNT 300

The symbol table helps resolve symbolic references during Pass 2.

4. Location Counter (LC)

The location counter keeps track of memory addresses during assembly.

Whenever an instruction or data item is processed, the location counter increases according
to instruction size.

5. Intermediate File

The intermediate file stores partially processed program information generated during Pass
1.

This file is later used during Pass 2 for object code generation.

6. Object Code Generator

The object code generator converts assembly instructions into machine language
instructions.

It generates the final object program.

You might also like