SlideShare a Scribd company logo
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
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.
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.
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.
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.
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.
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
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.
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.

More Related Content

PDF
2 Programming Language.pdf
PPT
Introduction to compiler design and phases of compiler
PPTX
Lecture 1 introduction to language processors
PPTX
Introduction-to-Systems-Programming_Unit-I.pptx
PPT
Chapter One
PPTX
Phases of Compiler.pptx
PDF
Compiler Design Introduction
PDF
Compiler design
2 Programming Language.pdf
Introduction to compiler design and phases of compiler
Lecture 1 introduction to language processors
Introduction-to-Systems-Programming_Unit-I.pptx
Chapter One
Phases of Compiler.pptx
Compiler Design Introduction
Compiler design

Similar to Macro-Processors-and-Compilers_Unit-II.pptx (20)

PPTX
Define Computer language, Translator, Standard input out C
PPTX
Agro informatics centre up State of Lec 6.pptx
PDF
Macro-processor
PPTX
Pros and cons of c as a compiler language
DOCX
COMPILER DESIGN.docx
PDF
unit1pdf__2021_12_14_12_37_34.pdf
DOCX
WEBSITE DEVELOPMENT
PPTX
Introduction to Compilers
PPTX
Cd ch1 - introduction
PPTX
CD - CH1 - Introduction to compiler design.pptx
PPTX
4_5802928814682016556.pptx
PPTX
Unit1 111206003944-phpapp02
PPTX
Compiler Construction
PPT
EVOLUTION OF SYSTEM
PDF
COMPILER DESIGN.pdf
PPTX
Chapter 2 Program language translation.pptx
PPTX
Compiler Design sample PPt -An introduction to design compiler
PPTX
Computer-charecteristics,types of languages,translators
PPTX
Compiler Construction from very basic start
PPTX
System Programing Unit 1
Define Computer language, Translator, Standard input out C
Agro informatics centre up State of Lec 6.pptx
Macro-processor
Pros and cons of c as a compiler language
COMPILER DESIGN.docx
unit1pdf__2021_12_14_12_37_34.pdf
WEBSITE DEVELOPMENT
Introduction to Compilers
Cd ch1 - introduction
CD - CH1 - Introduction to compiler design.pptx
4_5802928814682016556.pptx
Unit1 111206003944-phpapp02
Compiler Construction
EVOLUTION OF SYSTEM
COMPILER DESIGN.pdf
Chapter 2 Program language translation.pptx
Compiler Design sample PPt -An introduction to design compiler
Computer-charecteristics,types of languages,translators
Compiler Construction from very basic start
System Programing Unit 1
Ad

Recently uploaded (20)

PPTX
6ME3A-Unit-II-Sensors and Actuators_Handouts.pptx
PPTX
communication and presentation skills 01
PPTX
introduction to high performance computing
PPTX
"Array and Linked List in Data Structures with Types, Operations, Implementat...
PDF
PREDICTION OF DIABETES FROM ELECTRONIC HEALTH RECORDS
PDF
August 2025 - Top 10 Read Articles in Network Security & Its Applications
PDF
Exploratory_Data_Analysis_Fundamentals.pdf
PDF
737-MAX_SRG.pdf student reference guides
PDF
null (2) bgfbg bfgb bfgb fbfg bfbgf b.pdf
PPTX
Information Storage and Retrieval Techniques Unit III
PDF
Accra-Kumasi Expressway - Prefeasibility Report Volume 1 of 7.11.2018.pdf
PPTX
CURRICULAM DESIGN engineering FOR CSE 2025.pptx
PDF
Improvement effect of pyrolyzed agro-food biochar on the properties of.pdf
PPTX
Sorting and Hashing in Data Structures with Algorithms, Techniques, Implement...
PDF
Influence of Green Infrastructure on Residents’ Endorsement of the New Ecolog...
PDF
Artificial Superintelligence (ASI) Alliance Vision Paper.pdf
PPTX
Module 8- Technological and Communication Skills.pptx
PDF
BIO-INSPIRED ARCHITECTURE FOR PARSIMONIOUS CONVERSATIONAL INTELLIGENCE : THE ...
PPTX
Management Information system : MIS-e-Business Systems.pptx
PPTX
Chemical Technological Processes, Feasibility Study and Chemical Process Indu...
6ME3A-Unit-II-Sensors and Actuators_Handouts.pptx
communication and presentation skills 01
introduction to high performance computing
"Array and Linked List in Data Structures with Types, Operations, Implementat...
PREDICTION OF DIABETES FROM ELECTRONIC HEALTH RECORDS
August 2025 - Top 10 Read Articles in Network Security & Its Applications
Exploratory_Data_Analysis_Fundamentals.pdf
737-MAX_SRG.pdf student reference guides
null (2) bgfbg bfgb bfgb fbfg bfbgf b.pdf
Information Storage and Retrieval Techniques Unit III
Accra-Kumasi Expressway - Prefeasibility Report Volume 1 of 7.11.2018.pdf
CURRICULAM DESIGN engineering FOR CSE 2025.pptx
Improvement effect of pyrolyzed agro-food biochar on the properties of.pdf
Sorting and Hashing in Data Structures with Algorithms, Techniques, Implement...
Influence of Green Infrastructure on Residents’ Endorsement of the New Ecolog...
Artificial Superintelligence (ASI) Alliance Vision Paper.pdf
Module 8- Technological and Communication Skills.pptx
BIO-INSPIRED ARCHITECTURE FOR PARSIMONIOUS CONVERSATIONAL INTELLIGENCE : THE ...
Management Information system : MIS-e-Business Systems.pptx
Chemical Technological Processes, Feasibility Study and Chemical Process Indu...
Ad

Macro-Processors-and-Compilers_Unit-II.pptx

  • 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.