System Software
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.
The macro processor performs the following steps during macro expansion:
Macro Definition
MACRO
INCR X
ADD X,1
MEND
In this example:
• X is the parameter.
Macro Call
INCR NUM1
Here:
Expanded Code
ADD NUM1,1
• parameter X
with
• System software
MACRO
DOUBLE Y
INCR Y
INCR Y
MEND
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
• System software
• passing parameters,
1. Parameterized Macros
4. Looping in Macros
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.
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
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
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.
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:
• Working of AGO
• Advantages of AGO
• Applications of AGO
AGO is used:
• to skip instructions,
• 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
Where:
3. If condition is true:
4. If condition is false:
• Advantages of AIF
• Disadvantages of AIF
• Applications of AIF
AIF is used:
• Definition
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:
• Syntax of ANOP
.LABEL ANOP
Where:
• Working of ANOP
ANOP does not perform any calculation or processing. It simply marks a position in the
macro program.
• Advantages of ANOP
• Disadvantages of ANOP
ANOP (Assembler No
AGO (Assembler GO) AIF (Assembler IF)
Operation)
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.
In AGO, condition checking is In AIF, condition checking is ANOP does not require any
not required. necessary before branching. condition checking.
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 simple macro contains only normal A nested macro contains another macro call
instructions inside the macro definition. inside the macro definition.
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.
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.
The source program written by the programmer is given as input to the macro pre-
processor.
• macro definitions,
• macro calls,
• and normal assembly language instructions.
The Macro Name Table stores the names of all macros defined in the program.
• macro name,
• and a pointer to its definition in MDT.
The macro processor uses MNT to quickly search for macro definitions during macro
expansion.
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.
The Argument List Array stores the actual arguments passed during macro calls.
• formal parameters,
and
• actual arguments.
During macro expansion, the macro processor replaces parameters using values stored in
ALA.
Working of Macro Pre-Processor
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.
These components work together to process macros and generate machine code.
• A macro assembler works in two passes (two rounds of reading the code).
In this pass, the assembler reads the source code and does two things:
1. Macro Processor
2. Symbol Collector
In this pass, the assembler uses the tables built in Pass 1 and does two things:
1. Macro Expander
2. Code Generator
• Final Output
After both passes, the assembler produces the Object Code — the final machine-readable
binary file that the CPU can execute.
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.
4. Macro Expansion
5. Parameter Substitution
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.
After identifying the macro definition, the macro processor stores the macro information in
special tables.
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.
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.
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.
After macro expansion and parameter substitution, the macro processor generates the
expanded source program.
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.
2. Macro Expansion
3. Parameter Handling
5. Storage Management
7. Error Handling
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
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
• formal parameters,
• actual arguments,
• keyword parameters,
During macro expansion, the processor replaces formal parameters with actual arguments
using Argument List Array (ALA).
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
• MNT,
• MDT,
• and ALA.
The processor should store macro information efficiently to reduce memory usage and
improve processing speed.
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.
7. Error Handling
The macro processor must detect and report errors during macro processing.
• undefined macros,
• missing MEND,
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:
In two-pass processing:
One-pass processing is faster, while two-pass processing is easier to implement and supports
complex macro features.
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.
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
3. Parameterized Macros
8. Looping 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.
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.
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.
• 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.
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.
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.
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.
8. Looping Facility
Using looping instructions, the processor can repeatedly generate instructions automatically.
This feature reduces repetitive coding and simplifies large repetitive tasks.
It can identify:
• undefined macros,
• missing MEND,
• wrong parameters,
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.
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.
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.
➢ 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
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.
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 first collects all object files and library files required for the program.
The linker creates a global symbol table containing all symbols defined in different modules.
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.
The linker adjusts memory addresses according to the final memory allocation.
Finally, the linker generates a complete executable program that can be executed by the
operating system.
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.
• Program code
• Data section
• Symbol table
• Relocation information
2. Symbol Table
• 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.
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.
The source program is first translated by an assembler or compiler into object modules.
• Machine instructions
• Symbol definitions
• External references
• Relocation information
Example:
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.
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.
After resolving references and relocation, the linker generates an executable file.
• .EXE files
• .COM files
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.
3. Relocating Loader
A relocating loader can load programs into different memory locations according to memory
availability.
It adjusts address references dynamically before execution.
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.
• 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.
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.
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
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 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.
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.
ADD Addition
SUB Subtraction
JMP Jump
MUL Multiplication
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
DB Define byte
DW Define word
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.
1. Translation of Instructions
The assembler converts mnemonic operation codes into machine language opcodes.
Example:
ADD A, B
2. Address Assignment
The assembler assigns memory addresses to instructions, variables, labels, and data items.
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.
The assembler generates object code or machine code after successful translation.
• Main Components in the Design of Assembler
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
The opcode table stores mnemonic operation codes and their corresponding machine codes.
Example of OPTAB
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.
Example of SYMTAB
Symbol Address
LOOP 205
COUNT 300
The location counter keeps track of the current memory address during assembly.
Example
If the current address is 200 and the instruction size is 2 bytes, the next address becomes
202.
5. Intermediate File
• Instruction details
• Addresses
• Symbol references
6. Error Handler
1. Invalid opcode
2. Undefined symbol
3. Duplicate label
4. Syntax error
5. Missing operand
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
Pass 1 of Assembler
During Pass 1, the assembler mainly performs address assignment and symbol table
creation.
Example
If a label named LOOP appears in the program, its address is stored in SYMTAB.
Pass 2 of Assembler
• Advantages
• Disadvantages
• Advantages
• Disadvantages
• Disadvantages of Assembler
• Applications of Assembler
2. Embedded systems.
5. Real-time systems.
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
1. Efficiency
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.
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
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
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.
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
• 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.
The assembler should detect program errors accurately and provide meaningful error
messages.
Good error handling helps programmers identify and correct mistakes easily.
Syntax Errors
Example:
MOV ,A
Undefined Symbols
Example:
JMP LOOP
Duplicate Labels
Example:
ADDD A,B
Operand Errors
The assembler should display proper line numbers and descriptive messages for easy
debugging.
• Labels
• Variables
• Constants
• Addresses
The symbol table is very important because assembly language programs use symbolic
names instead of actual memory addresses.
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
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.
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.
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
• Machine instructions
• Relocation information
• Symbol information
Modern computer systems evolve continuously, so the assembler should support future
expansion.
➢ 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.
The first pass mainly performs address assignment and symbol table creation.
During this pass, the assembler scans the source program line by line.
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.
Whenever labels or symbols are found, their addresses are stored in the symbol table.
Example
During this pass, the assembler uses the symbol table and opcode table created 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 creates the object file containing executable machine code.
6. Reporting Remaining Errors
1. Source Program
4. Location Counter
5. Intermediate File
Source Program
↓
Pass 1
(Symbol Table Creation)
↓
Intermediate File
↓
Pass 2
(Object Code Generation)
↓
Object Program
The biggest advantage of multi-pass assemblers is that they can easily resolve forward
references.
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.
Multi-pass assemblers are suitable for large and complex assembly language programs.
Since the source program is processed multiple times, assembly takes more time.
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.
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 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.
The advanced assembly process is generally divided into several phases. Each phase
performs a specific task during assembly.
1. Lexical Analysis
2. Syntax Analysis
5. Macro Processing
7. Address Resolution
1. Lexical Analysis
In this phase, the assembler reads the source program line by line and divides each
statement into smaller units called tokens.
• Labels
• Operands
• Constants
• Directives
The assembler identifies the different parts of each instruction and prepares them for
further processing.
Example
ADD A,B
• 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.
MOV A,B
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
The symbol table stores important information about symbols used in the program.
• Labels
• Variables
• Constants
• Memory addresses
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.
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.
Suppose the current memory address is 200 and the instruction occupies 2 bytes.
Then:
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
A macro is a predefined block of instructions that can be reused multiple times by writing
only the macro name.
Example
INCR MACRO
ADD A,1
ENDM
INCR
ADD A,1
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
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.
Without proper address resolution, the generated machine code would be incorrect.
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.
Example
ADD 01
MOV 02
The generated object code is stored in an object file for linking and loading.
Modern assemblers generate relocation and linking information for loaders and linkers.
• Multiprogramming
• Modular programming
The assembler continuously checks the source program for errors during assembly.
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.
4. Simplified Programming
1. Increased Complexity
➢ 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.
3. Multi-Pass Assembler
4. Load-and-Go Assembler
5. Macro Assembler
6. Cross Assembler
A single pass assembler processes the source program only one time.
• Address assignment
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.
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.
• Code optimization
• Macro expansion
• Relocation handling
Multi-pass assemblers are mainly used for large and complex assembly systems.
4. Load-and-Go Assembler
A load-and-go assembler directly loads the generated machine code into memory after
assembly.
This method is simple and useful for small programs and educational systems.
Macros are predefined groups of instructions that can be reused multiple times.
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.
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.
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
The following are the main reasons for using a two pass assembler:
The design of a two pass assembler mainly contains the following components:
1. Source Program
5. Intermediate File
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
Example
Symbol Address
LOOP 205
COUNT 300
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.
The object code generator converts assembly instructions into machine language
instructions.