SlideShare une entreprise Scribd logo
1  sur  35
Macro Processors
              Chapter 4
        System Software
An introduction to systems programming
           Leland L. Beck




                                         1
Introduction

q   Concept
    » A macro instruction is a notational convenience for the
      programmer
    » It allows the programmer to write shorthand version of a
      program (module programming)
    » The macro processor replaces each macro invocation with
      the corresponding sequence of statements (expanding)




                                                                 2
Macro Processor

q   Recognize macro definitions
q   Save the macro definition
q   Recognize macro calls
q   Expand macro calls



    Source
                 Macro        Expanded   Compiler or   obj
     Code
(with macro)    Processor       Code     Assembler



                                                         3
Macro Definition

q   copy code
q   parameter substitution
q   conditional macro expansion
q   macro instruction defining macros




                                        4
Copy code -- Example

Source               Expanded source
STRG MACRO              .
       STA  DATA1       .
       STB  DATA2       .



                        {
       STX  DATA3           STA      DATA1
       MEND                 STB      DATA2
   .                        STX      DATA3
STRG                    .


                        {
   .                        STA      DATA1
STRG                        STB      DATA2
   .                        STX      DATA3
   .                    .


                                             5
Macro vs. Subroutine

q   Macro
    » the statement of expansion are generated each time the
      macro are invoked
q   Subroutine
    » the statement in a subroutine appears only once




                                                               6
Parameter Substitution -- Example

Source                     Expanded souce
STRG MACRO &a1, &a2, &a3      .
       STA  &a1               .
       STB  &a2               .



                              {
       STX  &a3                   STA       DATA1
       MEND                       STB       DATA2
   .                              STX       DATA3
STRG DATA1, DATA2, DATA3      .


                              {
   .                              STA       DATA4
STRG DATA4, DATA5, DATA6          STB       DATA5
   .                              STX       DATA6
   .                          .


                                                    7
Parameter Substitution

q   Dummy arguments
    » Positional argument
        STRG DATA1, DATA2, DATA3
        GENER ,,DIRECT,,,,,,3

    » Keyword argument
        STRG &a3=DATA1, &a2=DATA2, &a1=DATA3
        GENER TYPE=DIRECT, CHANNEL=3


q   Example: Fig. 4.1, Fig. 4.2
    » Labels are avoided in macro definition


                                               8
One-Pass Macro Processor

q   Prerequisite
    » every macro must be defined before it is called
q   Sub-procedures
    » macro definition: DEFINE
    » macro invocation: EXPAND
                                                        NAMTAB

                             MACRO       DEFINE         DEFTAB

          PROCESSLINE
                              CALL      EXPAND          ARGTAB



                                                                 9
Data Structures -- Global Variables

q   DEFTAB
q   NAMTAB
q   ARGTAB



    EXPANDING




                                          11
Nested Macros Definition
q   Macro definition within macros
    » process macro definition during expansion time
q   Example 4.3




                                                       12
Figure 4.3 (b)




                 13
One-Pass Macro Processor That Allows
          Nested Macro Definition

q   Sub-procedures
    » macro definition: DEFINE
    » macro invocation: EXPAND
q   EXPAND may invoke DEFINE when encounter
    macro definition
        NAMTAB
                                     MACRO        DEFINE
        DEFTAB       PROCESSLINE
                                       CALL
        ARGTAB
                                                  EXPAND

        Expanding                  MACRO Definition


                                                           14
1-Pass Macro Processor
                                                                           D E F IN E
     M ACR O
  PR O C ESSO R


                                                                                                  G E T L IN E
E X PA N D IN G = FA L SE

                                     P R O C E S S L IN E

G E T L IN E                                                               EXPAND
P R O C E S S L IN E


                                                                      E X PA N D IN G = T R U E



                                                                      G E T L IN E
                                G E T L IN E
                                                                      P R O C E S S L IN E



                              E X P A N D IN G              FA L SE


                                   TRUE

                            R EAD FRO M               R EAD FR O M
                            D EFTAB                   IN P U T
                                                                                                                 17
Comparison of Macro Processors Design

q   Single pass
    » every macro must be defined before it is called
    » one-pass processor can alternate between macro definition
      and macro expansion
    » nested macro definitions may be allowed but nested calls
      are not
q   Two pass algorithm
    » Pass1: Recognize macro definitions
    » Pass2: Recognize macro calls
    » nested macro definitions are not allowed



                                                                  18
Concatenation of Macro Parameters

q   Pre-concatenation
    » LDA     X&ID1
q   Post-concatenation
    » LDA     X&ID→1
q   Example: Figure 4.6




                                    19
Generation of Unique Labels

q   Example
    » JEQ      *-3
    » inconvenient, error-prone, difficult to read
q   Example Figure 4.7
        – $LOOP          TD      =X’&INDEV’
    » 1st call:
        – $AALOOP        TD      =X’F1’
    » 2nd call:
        – $ABLOOP        TD      =X’F1’




                                                     20
RDBUFF   F1, BUFFER, LENGTH
Conditional Macro Expansion

q   Macro-time conditional statements
    » Example: Figure 4.8
    » IF-ELSE-ENDIF


q   Macro-time variables
    » any symbol that begins with the character & and that is not a
      macro parameter
    » macro-time variables are initialized to 0
    » macro-time variables can be changed with their values using
      SET
        – &EORCK        SET     1


                                                                      23
RDBUFF   F3, BUF, RECL, 04, 2048




RDBUFF   0E, BUFFER, LENGTH, , 80
RDBUFF   F1, BUFF, RLENG, 04
Conditional Macro Expansion (Cont.)

q   Macro-time looping statement
    » Example: Figure 4.9
    » WHILE-ENDW
q   Macro processor function
    » %NITEMS: THE NUMBER OF MEMBERS IN AN
      ARGUMENT LIST




                                             27
Nested Macro Invocations

q   Macro invocations within macros
    » process macro invocation during expansion time
q   Recursive macro expansion
    » Example: Figure 4.11
    » Problems:
        – ARGTAB
        – EXPANDING
    » Solution
        – Recursive call
        – While loop with stack




                                                       28
ARGTAB

         DEFTAB        MACRO Definition
                                           DEFINE
         NAMTAB

                                           GETLINE
PROCESSLINE


                       Macro Invocation
                                          EXPAND
              ARGTAB




                                                     29
1-Pass Macro Processor
                                                                           D E F IN E
     M ACR O
  PR O C ESSO R


                                                                                                  G E T L IN E
E X PA N D IN G = FA L SE

                                     P R O C E S S L IN E

G E T L IN E                                                               EXPAND
P R O C E S S L IN E


                                                                      E X PA N D IN G = T R U E



                                                                      G E T L IN E
                                G E T L IN E
                                                                      P R O C E S S L IN E



                              E X P A N D IN G              FA L SE


                                   TRUE

                            R EAD FRO M               R EAD FR O M
                            D EFTAB                   IN P U T
                                                                                                                 30
Allowing Nested Macro Invocation
                                                                           D E F IN E (f)
       M ACR O
    PR O C ESSO R


                                                                                                  G E T L IN E (f)


                                 P R O C E S S L IN E (f)
 G E T L IN E (0 )
 P R O C E S S L IN E (0 )                                                   EXPAND




                                                                      G E T L IN E (1 )
                               G E T L IN E (f)
                                                                      P R O C E S S L IN E (1 )



                                     f                      FA L SE


                                   TRUE

                             R EAD FRO M              R EAD FR O M
                             D EFTAB                  IN P U T
                                                                                                                     31
Macro-Assembler

q   Advantage
    » reduce 1 pass
    » share same data structure
q   Disadvantage
    » more complex




                                  32
Pass 1       READ

              Search                       Pass 2
 R                             Type?
         (Pseudo-Op Table)


          Search NAMTAB       MACRO       Process
         (Macro Name Table)    Define   pseudo-ops


              Search            R           R
         (Machine Op Table)

                              MACRO
              Process         Expand
             machine
            instruction
                                R
                R
General Purpose Macro Processor

q   ELENA
    » Software: Practice and Experience, Vol. 14, pp. 519-531,
      Jun. 1984
q   Macro definition
    » header:
        – a sequence of keywords and parameter markers (%)
        – at least one of the first two tokens in a macro header must be a
          keyword, not a parameter marker
    » body:
        – the character & identifies a local label
        – macro time instruction (.SET, .IF .JUMP, .E)
        – macro time variables or labels (.)

                                                                             34
ELENA (cont.)

q   Macro invocation
    » There is no single token that constitutes the macro “name”
    » Constructing an index of all macro headers according to the
      keywords in the first two tokens of the header
    » Example
       – DEFINITION:
           q   ADD %1 TO %2
           q   ADD %1 TO THE FIRST ELEMENT OF %2
       – INVOCATION:                DISPLAY %1
           q   DISPLAY TABLE
                                    %1 TABLE




                                                                    35

Contenu connexe

Tendances

RailswayCon 2010 - Dynamic Language VMs
RailswayCon 2010 - Dynamic Language VMsRailswayCon 2010 - Dynamic Language VMs
RailswayCon 2010 - Dynamic Language VMs
Lourens Naudé
 

Tendances (20)

Unit 8
Unit 8Unit 8
Unit 8
 
Detecting Occurrences of Refactoring with Heuristic Search
Detecting Occurrences of Refactoring with Heuristic SearchDetecting Occurrences of Refactoring with Heuristic Search
Detecting Occurrences of Refactoring with Heuristic Search
 
Unit3 cspc
Unit3 cspcUnit3 cspc
Unit3 cspc
 
LLVM Register Allocation
LLVM Register AllocationLLVM Register Allocation
LLVM Register Allocation
 
C programming session10
C programming  session10C programming  session10
C programming session10
 
Recording Finer-Grained Software Evolution with IDE: An Annotation-Based Appr...
Recording Finer-Grained Software Evolution with IDE: An Annotation-Based Appr...Recording Finer-Grained Software Evolution with IDE: An Annotation-Based Appr...
Recording Finer-Grained Software Evolution with IDE: An Annotation-Based Appr...
 
Crash course in verilog
Crash course in verilogCrash course in verilog
Crash course in verilog
 
C Programming Unit-1
C Programming Unit-1C Programming Unit-1
C Programming Unit-1
 
DWARF Data Representation
DWARF Data RepresentationDWARF Data Representation
DWARF Data Representation
 
Alp 05
Alp 05Alp 05
Alp 05
 
GCC
GCCGCC
GCC
 
LLVM Register Allocation (2nd Version)
LLVM Register Allocation (2nd Version)LLVM Register Allocation (2nd Version)
LLVM Register Allocation (2nd Version)
 
SOLUTION MANUAL OF COMPUTER ORGANIZATION BY CARL HAMACHER, ZVONKO VRANESIC & ...
SOLUTION MANUAL OF COMPUTER ORGANIZATION BY CARL HAMACHER, ZVONKO VRANESIC & ...SOLUTION MANUAL OF COMPUTER ORGANIZATION BY CARL HAMACHER, ZVONKO VRANESIC & ...
SOLUTION MANUAL OF COMPUTER ORGANIZATION BY CARL HAMACHER, ZVONKO VRANESIC & ...
 
Code GPU with CUDA - Optimizing memory and control flow
Code GPU with CUDA - Optimizing memory and control flowCode GPU with CUDA - Optimizing memory and control flow
Code GPU with CUDA - Optimizing memory and control flow
 
'C' language notes (a.p)
'C' language notes (a.p)'C' language notes (a.p)
'C' language notes (a.p)
 
Code GPU with CUDA - Identifying performance limiters
Code GPU with CUDA - Identifying performance limitersCode GPU with CUDA - Identifying performance limiters
Code GPU with CUDA - Identifying performance limiters
 
Pl sql programme
Pl sql programmePl sql programme
Pl sql programme
 
Chtp414
Chtp414Chtp414
Chtp414
 
RailswayCon 2010 - Dynamic Language VMs
RailswayCon 2010 - Dynamic Language VMsRailswayCon 2010 - Dynamic Language VMs
RailswayCon 2010 - Dynamic Language VMs
 
Functions
FunctionsFunctions
Functions
 

En vedette

Lecture 4 assembly language
Lecture 4   assembly languageLecture 4   assembly language
Lecture 4 assembly language
Pradeep Kumar TS
 
Direct linking loader
Direct linking loaderDirect linking loader
Direct linking loader
babyparul
 
System Programming Unit II
System Programming Unit IISystem Programming Unit II
System Programming Unit II
Manoj Patil
 
System Programing Unit 1
System Programing Unit 1System Programing Unit 1
System Programing Unit 1
Manoj Patil
 

En vedette (20)

Ss4
Ss4Ss4
Ss4
 
Macro
MacroMacro
Macro
 
Pre processor directives in c
Pre processor directives in cPre processor directives in c
Pre processor directives in c
 
Lecture 4 assembly language
Lecture 4   assembly languageLecture 4   assembly language
Lecture 4 assembly language
 
Direct linking loaders
Direct linking loadersDirect linking loaders
Direct linking loaders
 
SAS Macros
SAS MacrosSAS Macros
SAS Macros
 
Lexical analysis - Compiler Design
Lexical analysis - Compiler DesignLexical analysis - Compiler Design
Lexical analysis - Compiler Design
 
System programming
System programmingSystem programming
System programming
 
Direct linking loader
Direct linking loaderDirect linking loader
Direct linking loader
 
Assembly Language Lecture 2
Assembly Language Lecture 2Assembly Language Lecture 2
Assembly Language Lecture 2
 
Introduction to systems programming
Introduction to systems programmingIntroduction to systems programming
Introduction to systems programming
 
Linkers
LinkersLinkers
Linkers
 
Loaders
LoadersLoaders
Loaders
 
Lexical analyzer
Lexical analyzerLexical analyzer
Lexical analyzer
 
Microprocessor chapter 9 - assembly language programming
Microprocessor  chapter 9 - assembly language programmingMicroprocessor  chapter 9 - assembly language programming
Microprocessor chapter 9 - assembly language programming
 
System Programming Unit II
System Programming Unit IISystem Programming Unit II
System Programming Unit II
 
System Programing Unit 1
System Programing Unit 1System Programing Unit 1
System Programing Unit 1
 
Phases of Compiler
Phases of CompilerPhases of Compiler
Phases of Compiler
 
Assembly language programming_fundamentals 8086
Assembly language programming_fundamentals 8086Assembly language programming_fundamentals 8086
Assembly language programming_fundamentals 8086
 
Lexical analyzer
Lexical analyzerLexical analyzer
Lexical analyzer
 

Similaire à Cp0675 03 may-2012-rm04

Designing Modern Streaming Data Applications
Designing Modern Streaming Data ApplicationsDesigning Modern Streaming Data Applications
Designing Modern Streaming Data Applications
Arun Kejariwal
 
Seeley yonik solr performance key innovations
Seeley yonik   solr performance key innovationsSeeley yonik   solr performance key innovations
Seeley yonik solr performance key innovations
Lucidworks (Archived)
 
MDSD with Eclipse @ JUG Hamburg
MDSD with Eclipse @ JUG HamburgMDSD with Eclipse @ JUG Hamburg
MDSD with Eclipse @ JUG Hamburg
Sebastian Zarnekow
 

Similaire à Cp0675 03 may-2012-rm04 (20)

handout6.pdf
handout6.pdfhandout6.pdf
handout6.pdf
 
Designing Modern Streaming Data Applications
Designing Modern Streaming Data ApplicationsDesigning Modern Streaming Data Applications
Designing Modern Streaming Data Applications
 
The caret package is a unified interface to a large number of predictive mode...
The caret package is a unified interface to a large number of predictive mode...The caret package is a unified interface to a large number of predictive mode...
The caret package is a unified interface to a large number of predictive mode...
 
Building a Scalable Distributed Stats Infrastructure with Storm and KairosDB
Building a Scalable Distributed Stats Infrastructure with Storm and KairosDBBuilding a Scalable Distributed Stats Infrastructure with Storm and KairosDB
Building a Scalable Distributed Stats Infrastructure with Storm and KairosDB
 
Wilmott Nyc Jul2012 Nag Talk John Holden
Wilmott Nyc Jul2012 Nag Talk John HoldenWilmott Nyc Jul2012 Nag Talk John Holden
Wilmott Nyc Jul2012 Nag Talk John Holden
 
Seeley yonik solr performance key innovations
Seeley yonik   solr performance key innovationsSeeley yonik   solr performance key innovations
Seeley yonik solr performance key innovations
 
Ridge-based Profiled Differential Power Analysis
Ridge-based Profiled Differential Power AnalysisRidge-based Profiled Differential Power Analysis
Ridge-based Profiled Differential Power Analysis
 
Achitecture Aware Algorithms and Software for Peta and Exascale
Achitecture Aware Algorithms and Software for Peta and ExascaleAchitecture Aware Algorithms and Software for Peta and Exascale
Achitecture Aware Algorithms and Software for Peta and Exascale
 
Presentation on macros and macro processor
Presentation on macros and macro processorPresentation on macros and macro processor
Presentation on macros and macro processor
 
Report
ReportReport
Report
 
Moving Toward Deep Learning Algorithms on HPCC Systems
Moving Toward Deep Learning Algorithms on HPCC SystemsMoving Toward Deep Learning Algorithms on HPCC Systems
Moving Toward Deep Learning Algorithms on HPCC Systems
 
JMI Techtalk: 한재근 - How to use GPU for developing AI
JMI Techtalk: 한재근 - How to use GPU for developing AIJMI Techtalk: 한재근 - How to use GPU for developing AI
JMI Techtalk: 한재근 - How to use GPU for developing AI
 
#OSSPARIS19 : Detecter des anomalies de séries temporelles à la volée avec Wa...
#OSSPARIS19 : Detecter des anomalies de séries temporelles à la volée avec Wa...#OSSPARIS19 : Detecter des anomalies de séries temporelles à la volée avec Wa...
#OSSPARIS19 : Detecter des anomalies de séries temporelles à la volée avec Wa...
 
Scala Macros
Scala MacrosScala Macros
Scala Macros
 
Cg in Two Pages
Cg in Two PagesCg in Two Pages
Cg in Two Pages
 
"Massive Parallel Decoding of Low-Density Parity-Check Codes Using Graphic Ca...
"Massive Parallel Decoding of Low-Density Parity-Check Codes Using Graphic Ca..."Massive Parallel Decoding of Low-Density Parity-Check Codes Using Graphic Ca...
"Massive Parallel Decoding of Low-Density Parity-Check Codes Using Graphic Ca...
 
Learn How to Master Solr1 4
Learn How to Master Solr1 4Learn How to Master Solr1 4
Learn How to Master Solr1 4
 
MDSD with Eclipse @ JUG Hamburg
MDSD with Eclipse @ JUG HamburgMDSD with Eclipse @ JUG Hamburg
MDSD with Eclipse @ JUG Hamburg
 
Dw24779784
Dw24779784Dw24779784
Dw24779784
 
Introduction of Feature Hashing
Introduction of Feature HashingIntroduction of Feature Hashing
Introduction of Feature Hashing
 

Dernier

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
fonyou31
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
SoniaTolstoy
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
PECB
 

Dernier (20)

APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 

Cp0675 03 may-2012-rm04

  • 1. Macro Processors Chapter 4 System Software An introduction to systems programming Leland L. Beck 1
  • 2. Introduction q Concept » A macro instruction is a notational convenience for the programmer » It allows the programmer to write shorthand version of a program (module programming) » The macro processor replaces each macro invocation with the corresponding sequence of statements (expanding) 2
  • 3. Macro Processor q Recognize macro definitions q Save the macro definition q Recognize macro calls q Expand macro calls Source Macro Expanded Compiler or obj Code (with macro) Processor Code Assembler 3
  • 4. Macro Definition q copy code q parameter substitution q conditional macro expansion q macro instruction defining macros 4
  • 5. Copy code -- Example Source Expanded source STRG MACRO . STA DATA1 . STB DATA2 . { STX DATA3 STA DATA1 MEND STB DATA2 . STX DATA3 STRG . { . STA DATA1 STRG STB DATA2 . STX DATA3 . . 5
  • 6. Macro vs. Subroutine q Macro » the statement of expansion are generated each time the macro are invoked q Subroutine » the statement in a subroutine appears only once 6
  • 7. Parameter Substitution -- Example Source Expanded souce STRG MACRO &a1, &a2, &a3 . STA &a1 . STB &a2 . { STX &a3 STA DATA1 MEND STB DATA2 . STX DATA3 STRG DATA1, DATA2, DATA3 . { . STA DATA4 STRG DATA4, DATA5, DATA6 STB DATA5 . STX DATA6 . . 7
  • 8. Parameter Substitution q Dummy arguments » Positional argument STRG DATA1, DATA2, DATA3 GENER ,,DIRECT,,,,,,3 » Keyword argument STRG &a3=DATA1, &a2=DATA2, &a1=DATA3 GENER TYPE=DIRECT, CHANNEL=3 q Example: Fig. 4.1, Fig. 4.2 » Labels are avoided in macro definition 8
  • 9. One-Pass Macro Processor q Prerequisite » every macro must be defined before it is called q Sub-procedures » macro definition: DEFINE » macro invocation: EXPAND NAMTAB MACRO DEFINE DEFTAB PROCESSLINE CALL EXPAND ARGTAB 9
  • 10.
  • 11. Data Structures -- Global Variables q DEFTAB q NAMTAB q ARGTAB EXPANDING 11
  • 12. Nested Macros Definition q Macro definition within macros » process macro definition during expansion time q Example 4.3 12
  • 14. One-Pass Macro Processor That Allows Nested Macro Definition q Sub-procedures » macro definition: DEFINE » macro invocation: EXPAND q EXPAND may invoke DEFINE when encounter macro definition NAMTAB MACRO DEFINE DEFTAB PROCESSLINE CALL ARGTAB EXPAND Expanding MACRO Definition 14
  • 15.
  • 16.
  • 17. 1-Pass Macro Processor D E F IN E M ACR O PR O C ESSO R G E T L IN E E X PA N D IN G = FA L SE P R O C E S S L IN E G E T L IN E EXPAND P R O C E S S L IN E E X PA N D IN G = T R U E G E T L IN E G E T L IN E P R O C E S S L IN E E X P A N D IN G FA L SE TRUE R EAD FRO M R EAD FR O M D EFTAB IN P U T 17
  • 18. Comparison of Macro Processors Design q Single pass » every macro must be defined before it is called » one-pass processor can alternate between macro definition and macro expansion » nested macro definitions may be allowed but nested calls are not q Two pass algorithm » Pass1: Recognize macro definitions » Pass2: Recognize macro calls » nested macro definitions are not allowed 18
  • 19. Concatenation of Macro Parameters q Pre-concatenation » LDA X&ID1 q Post-concatenation » LDA X&ID→1 q Example: Figure 4.6 19
  • 20. Generation of Unique Labels q Example » JEQ *-3 » inconvenient, error-prone, difficult to read q Example Figure 4.7 – $LOOP TD =X’&INDEV’ » 1st call: – $AALOOP TD =X’F1’ » 2nd call: – $ABLOOP TD =X’F1’ 20
  • 21.
  • 22. RDBUFF F1, BUFFER, LENGTH
  • 23. Conditional Macro Expansion q Macro-time conditional statements » Example: Figure 4.8 » IF-ELSE-ENDIF q Macro-time variables » any symbol that begins with the character & and that is not a macro parameter » macro-time variables are initialized to 0 » macro-time variables can be changed with their values using SET – &EORCK SET 1 23
  • 24.
  • 25. RDBUFF F3, BUF, RECL, 04, 2048 RDBUFF 0E, BUFFER, LENGTH, , 80
  • 26. RDBUFF F1, BUFF, RLENG, 04
  • 27. Conditional Macro Expansion (Cont.) q Macro-time looping statement » Example: Figure 4.9 » WHILE-ENDW q Macro processor function » %NITEMS: THE NUMBER OF MEMBERS IN AN ARGUMENT LIST 27
  • 28. Nested Macro Invocations q Macro invocations within macros » process macro invocation during expansion time q Recursive macro expansion » Example: Figure 4.11 » Problems: – ARGTAB – EXPANDING » Solution – Recursive call – While loop with stack 28
  • 29. ARGTAB DEFTAB MACRO Definition DEFINE NAMTAB GETLINE PROCESSLINE Macro Invocation EXPAND ARGTAB 29
  • 30. 1-Pass Macro Processor D E F IN E M ACR O PR O C ESSO R G E T L IN E E X PA N D IN G = FA L SE P R O C E S S L IN E G E T L IN E EXPAND P R O C E S S L IN E E X PA N D IN G = T R U E G E T L IN E G E T L IN E P R O C E S S L IN E E X P A N D IN G FA L SE TRUE R EAD FRO M R EAD FR O M D EFTAB IN P U T 30
  • 31. Allowing Nested Macro Invocation D E F IN E (f) M ACR O PR O C ESSO R G E T L IN E (f) P R O C E S S L IN E (f) G E T L IN E (0 ) P R O C E S S L IN E (0 ) EXPAND G E T L IN E (1 ) G E T L IN E (f) P R O C E S S L IN E (1 ) f FA L SE TRUE R EAD FRO M R EAD FR O M D EFTAB IN P U T 31
  • 32. Macro-Assembler q Advantage » reduce 1 pass » share same data structure q Disadvantage » more complex 32
  • 33. Pass 1 READ Search Pass 2 R Type? (Pseudo-Op Table) Search NAMTAB MACRO Process (Macro Name Table) Define pseudo-ops Search R R (Machine Op Table) MACRO Process Expand machine instruction R R
  • 34. General Purpose Macro Processor q ELENA » Software: Practice and Experience, Vol. 14, pp. 519-531, Jun. 1984 q Macro definition » header: – a sequence of keywords and parameter markers (%) – at least one of the first two tokens in a macro header must be a keyword, not a parameter marker » body: – the character & identifies a local label – macro time instruction (.SET, .IF .JUMP, .E) – macro time variables or labels (.) 34
  • 35. ELENA (cont.) q Macro invocation » There is no single token that constitutes the macro “name” » Constructing an index of all macro headers according to the keywords in the first two tokens of the header » Example – DEFINITION: q ADD %1 TO %2 q ADD %1 TO THE FIRST ELEMENT OF %2 – INVOCATION: DISPLAY %1 q DISPLAY TABLE %1 TABLE 35