1. Macro Processors
and Compilers
Macros offer a powerful way to define reusable code blocks.
Compilers bridge the gap between high-level languages and
machine code, making programming easier and more efficient.
Prepared by : Prof. Neelam Jadhav
2. Introduction to Macro Processing
Macros are a powerful tool for code reusability and abstraction, allowing developers to define code snippets that can be expanded into
larger code blocks.
1 Macro Instruction Arguments
Arguments allow macros to be parameterized, making
them more flexible and adaptable to different situations.
2 Conditional Macro Expansion
Conditional expansion allows macros to behave differently
based on specific conditions, adding logic to code
generation.
3 Macro Calls Within Macros
Nested macro calls enable complex and hierarchical code
structures, further enhancing the power of macros.
4 Macro Definitions
Macros are defined with a name and a body, which contains
the code that will be expanded when the macro is called.
3. Designing Macro Processors
Macro processors are responsible for expanding macro definitions into actual code during the
compilation process, ensuring that the code is correct and efficient.
1 Pass 1
This pass reads the source program and builds a macro definition table, which
stores all the defined macros and their associated code.
2 Pass 2
This pass reads the source program again, expanding all macro calls based on the
definitions stored in the macro definition table.
3 Output
The output of the macro processor is a program with all the macro calls
expanded, ready for further compilation.
4. The Single Pass Macro
Processor
A single-pass macro processor aims to expand macros during a
single pass through the source program, improving efficiency and
reducing the overall compilation time.
Advantages
Simpler implementation,
faster execution, can handle
macros defined within other
macros.
Disadvantages
Limited functionality,
cannot handle recursive
macro definitions, may
require complex data
structures.
5. Introduction to Compilers
Compilers are essential software tools that translate high-level programming languages into machine code, allowing computers to
understand and execute programs written in various languages.
Lexical Analysis
This phase scans the source code and breaks it down into basic tokens, such as keywords, identifiers, and operators.
Syntax Analysis
This phase checks the syntactic correctness of the source code, ensuring it follows the grammatical rules of the
programming language.
Semantic Analysis
This phase analyzes the meaning of the source code, checking for type compatibility and other semantic errors.
Intermediate Code Generation
This phase translates the source code into an intermediate representation, which is closer to machine code but still platform-
independent.
Code Optimization
This phase aims to improve the efficiency of the generated code by removing redundant code, reducing the size, and
improving performance.
6. Benefits of Assembly Language
Assembly language offers low-level control over hardware, allowing developers to optimize programs for specific
architectures, but it comes at the cost of readability and portability.
Direct Hardware Access
Assembly language provides direct
access to memory locations,
registers, and other hardware
components, offering granular
control over system resources.
Efficiency
Assembly language allows
developers to write code that is
highly optimized for specific
hardware, leading to increased
speed and efficiency.
Debugging
Assembly language code can be
easily debugged and analyzed, as
each instruction directly
corresponds to a specific machine
operation.
7. Assembly Language:
Structure and Design
Assembly language programs consist of a set of instructions that
operate on data stored in memory locations, registers, and other
hardware components.
Label Instruction Operand
START MOV AX, 10
ADD AX, BX
END HLT
8. Two-Pass Assembler Design
A two-pass assembler processes the source program twice, building a symbol table in the first
pass and generating machine code in the second pass.
1 Pass 1
This pass scans the source program, identifying labels and their corresponding
addresses, and building a symbol table that maps labels to their memory
locations.
2 Pass 2
This pass reads the source program again, using the symbol table to resolve
labels and generate the final machine code, which can be executed by the
computer.
3 Output
The output of the assembler is an object code file, containing the machine code
generated from the assembly language source program.
9. Compilers vs. Interpreters
Both compilers and interpreters translate high-level code into
executable instructions. Compilers translate the entire program at
once, while interpreters execute code line by line.
Compilers
Fast execution, optimized code,
well-suited for large projects.
Interpreters
More flexible, easier
debugging, well-suited for
interactive development.