2.2.pptx

Module 2: Advanced Macro Facilities

Overview of Macros
  • Flow of control during macro expansion
  • Advanced Macro Facilities
  • Expansion time variables: Local (LCL) & Global (GBL)
  • Advanced directives: REMOVE, IRP, REPT
  • Macro processor vs. Macro assembler
  • Design and features of macro processor
  • Two-pass macro processor: Structure, Algorithms, and Flowcharts

Flow of Control During Macro Expansion

  • Default flow: Starts with statement following macro prototype and ends with statement before MEND.
  • Conditional Expansion: Alters flow to skip certain statements.
  • Loop Expansion: Allows for repeated visits to the same statement during expansion.

Macro Expansion Algorithm

  • Implemented using a Macro Expansion Counter (MEC).
  • Algorithm Overview:
    1. Set MEC to the statement number of the first statement after the prototype.
    2. Repeat until MEC points to MEND:
    • If statement is a model statement:
      • Expand the statement
      • Increment MEC
    • If statement is a pre-processor statement:
      • Set MEC to the new value specified.
    1. Exit macro expansion.

Advanced Macro Facilities

Change of Control Flow
  • Expansion Time Sequencing Symbol (SS): Defined in the label field of a macro statement.
  • Expansion Time Statements:
    • AIF: Conditional transfer to SS based on an expression.
    • AGO: Unconditional transfer to SS.
    • ANOP: Defines Sequencing Symbol.

Example of Control Flow

.ONLY
.LAST
MACRO TEST &X, &Y, &Z
AIF (&Y EQ &X) .ONLY
MOVER AREG, &Y
AGO .LAST
MOVER AREG, &Z
MEND
  • Control transfers to .ONLY if condition Y=X is true.

Expansion Time Variables (EV)

  • Definition: Variables usable only during macro expansion.
  • Types:
    1. Local EV (LCL): Scoped within a specific macro.
    2. Global EV (GBL): Usable across multiple macros.
  • Syntax:
    • LCL <EV specification>
    • GBL <EV specification>
  • Change Values: SET <EV specification> SET <SET expression>

Attributes of Parameters

  • Definition: Attributes defined with syntax:
    • <attribute name>' <formal parameter specification>
  • Types:
    • T: Type
    • L: Length
    • S: Size
  • Example:
MACRO ME &A
AIF (L'&A EQ 1) .NEXT

Advanced Directives

  • Remove Directive: Deletes a macro from the Macro Definition Table (MDT).
  • IRP Directive: Indefinite repeat for custom macro assembly sequence.
    • Example:
  MACRO MAC_X&P, &Q
  IRP &P
  ADD REG1, &P
  MEND
&nbsp;&nbsp;```
- **REPEAT Directive (REPT)**: Duplicates a sequence multiple times during macro expansion.
  - **Syntax**: `REPT <expression>`
- **Example**:

plaintext MACRO DEF_R LCL &P &P SET 5 REPT 5 DC '&P' &P SET &P + 1 MEND   ```

  • Outputs: 5,6,7,8,9,10 on execution.

Macro Processor and Assembler

  • Macro Processor: Accepts an assembly language program, translating macros into the final assembly program without definitions.
  • Macro Assembler: Performs macro expansion and assembly simultaneously.
  • Design Steps:
    • Identify functions of macro processor and conventional assembler for merging.

Design Issues of Macro Processor

  • Data structures and databases flexibility.
  • Handling of macro arguments and parameters.
  • Management of default arguments and values.
  • Incorporation of comments within macros.

Features of Macro Processor

  • Linking macro parameters with arguments.
  • Delimiting parameters effectively.
  • Directives related to arguments handling.
  • Automatic label generation.
  • Machine-independent features integrated.

Two-Pass Macro Processor

General Design Steps
  1. Specification of Problem
  2. Specification of Databases
  3. Specification of Database Formats
  4. Algorithm development

Pass 1 Procedure
  • Functionality: Stores macro definitions in an MDT and entries in MNT.
  • Input Handling: Marks and processes macro definitions and calls accordingly.

Pass 2 Procedure
  • Reads input, searches MNT for macro calls to expand them accordingly by substituting arguments for dummy parameters.
  • Continues until encountering the END pseudo-op, finalizing the assembly for the assembler.

Pass Structure of Macro Assembler

  • Pass 1: Macro definition processing and symbol table construction.
  • Pass 2: Macro expansion, memory allocation, and processing literals.
  • Pass 3: Generating target code based on expanded macros.

  

Flow Chart of Macro Assembler

  • Illustrates decision-making process for pseudo-ops, macro calls, and merging functions of the macro processor with traditional assembly operations.