SlideShare a Scribd company logo
2
Most read
3
Most read
19
Most read
System
Software
Chapter – 3
1. Macro expansion
2.nested macro calls
MACRO EXPANSION:
The use of a macro name with a set of actual parameters is
replaced by some code generated from its body.
This is called macro expansion .
Macro expansion can be performed by two kinds of language processor
 Macro assembler
 Macro pre-processor
MACRO ASSEMBLER:
Its performs expansion of a each macro call in a program into a sequence of assembly
language statements and also assembles the resultant assembly language program.
MACRO PRE-PROCESSOR:
It only processes the macro call. Other statements are processes with the help of assembler.
EXAMPLE FOR EXAPANSION
MACRO DEFINITION
EXPANSIONOF MACRO
Label field
 A ,B , AREG are an actual parameters.
 &MEM_VAL, &INC_VAL,&REG are formal
parameters.
Two key notions concerning macro expansion are
A. Expansion time control flow :
This determines the order in which model statements are visited during macro
expansion.
B. Lexical substitution:
Lexical substitution is used to generate an assembly statement from a model statement.
A. Flow of control during expansion
 The default flow of control during macro expansion is sequential.
 In the absence of preprocessor statements, the model statements
of a macro are visited sequentially starting with the statement
following the macro prototype statement and ending with the
statement preceding the MEND statement.
What can alter the flow of control during expansion?
o A pre-processor statement can alter the flow of control during expansion
such that
o Conditional Expansion: Some model statements are either never visited
during expansion, or Expansion Time Loops: are repeatedly visited
during expansion.
o The flow of control during macro expansion is implemented using a macro
expansion counter (MEC)
ALGORITHM (MACRO EXPANSION)
1. MEC:=statement number of first statement
following the prototype statement.
2. While statement pointed by MEC is not a MEND statement.
a. If a model statement then
i. Expand the statement
ii. MEC:=MEC+1;
b. Else (i.e. a preprocessor statement)
i. MEC:= new value specified in the statement.
3. Exit from macro expansion.
B. LEXICAL SUBSTITUTION
 A model statement consists of 3 types of strings.
 An ordinary string, which stands for itself.
 The name of a formal parameter which is preceded by the character
„&‟.
 The name of a pre-processor variable, which is also preceded by the
character „&‟.
 During lexical expansion, strings is retained in its original form .
 The name of Formal parameter is replaced by its value from the
actual parameter of a macro call.
 The name of pre-processor variable is replaced with its value. This
value is readily known to the pre-processor.
Rules for determining the value of a formal parameter depends on
the kind of parameter:
 Positional Parameter
 Keyword Parameter
 Default specification of parameters
 Macros with mixed parameter list
 Other uses of parameter
POSITIONAL PARAMETERS
A positional formal parameter is written as &<parameter name>
e.g. &SAMPLE where SAMPLE is the name of parameter.
<parameter kind> of syntax rule is omitted.
The value of a positional formal parameter XYZ is determined by the rule of
positional association as follows:
1. Find the ordinal position of XYZ in the list of formal parameters in the
macro prototype statement.
2. Find the actual parameter specification occupying the same ordinal position
in the list of actual parameters in the macro call statement.
Consider the call
INCR A,B,AREG
On macro INCR , following rule of positional association,
values of formal parameters are:
Formal parameter value
MEM_VAL A
INCR_VAL B
REG AREG
Lexical expansion of the model statements now leads to
the code
+ MOVER AREG, A
+ ADD AREG, B
+ MOVEM AREG, A
MACRO
INCR &MEM_VAL,&INCR_VAL
&REG
MOVER &REG, &MEM_VAL
ADD &REG, &INCR_VAL
MOVEM &REG, &MEM_VAL
MEND
Consider the macro
KEYWORD PARAMETER
For keyword parameter,
<parameter name> is an ordinary string and
<parameter kind> is the string „=‟ in syntax rule.
The <actual parameter spec> is written as<formal parameter name>=<ordinary
string>.
Note that the ordinal position of the specification XYZ=ABC in the list of actual
parameters is immaterial.
This is very useful in situations where long lists of parameters have to be used.
Let us see example for it.
Following are macro call statement:
INCR_M MEM_VAL=A, INCR_VAL=B, REG=AREG
------
INCR_M INCR_VAL=B, REG=AREG, MEM_VAL=A
Both are equivalent.
Following is macro definition using keyword parameter:
MACRO
INCR_M &MEM_VAL=, &INCR_VAL=,&REG=
MOVER &REG, &MEM_VAL
ADD &REG, &INCR_VAL
MOVEM &REG,&MEM_
DEFAULT SPECIFICATIONS OF PARAMETERS
A default value is a standard assumption in the absence of an explicit
specification by the programmer.
Default specification of parameters is useful in situations where a parameter
has the same value in most calls.
When the desired value is different from the default value, the desired value
can be specified explicitly in a macro call.
The syntax for formal parameter specification, as follows:
&<parameter name> [<parameter kind> [<default value>]]
EXAMPLE
MACRO
INCR_D &MEM_VAL=, &INCR_VAL=, &REG=AREG
MOVER &REG, &MEM_VAL
ADD &REG, &INCR_VAL
MOVEM &REG, &MEM_VAL
MEND
The macro can be redefined to use a default specification
for the parameter REG
INCR_D MEM_VAL=A, INCR_VAL=B
INCR_D INCR_VAL=B, MEM_VAL=A
INCR_D INCR_VAL=B, MEM_VAL=A, REG=BREG
First two calls are equivalent but third call overrides the default value for REG with the value BREG in next example.
MACROS WITH MIXED PARAMETER LISTS
A macro may be defined to use both positional and keyword parameters.
In such a case, all positional parameters must precede all keyword parameters.
example in the macro call
SUM A, B, G=20, H=X
A, B are positional parameters while G, H are keyword parameters.
Correspondence between actual and formal parameters is established by
applying the rules governing positional and keyword parameters separately.
OTHER USES OF PARAMETERS
The model statements have used formal parameters only in operand field.
However, use of parameters is not restricted to these fields.
Formal parameters can also appear in the label and opcode fields of model
statements.
NESTED MACRO CALLS
 A model statement in a macro may constitute a
call on another macro.
 Such calls are known as nested macro calls.
 Macro containing the nested call is the outer macro and, Macro called is
inner macro.
 They follow LIFO rule.
 Thus, in structure of nested macro calls, expansion of latest macro call (i.e
inner macro) is completed first.
THANK YOU

More Related Content

What's hot (20)

PPTX
Single pass assembler
Bansari Shah
 
PDF
Unit 2
pm_ghate
 
PPTX
Linking in MS-Dos System
Satyamevjayte Haxor
 
PPTX
Two pass Assembler
Satyamevjayte Haxor
 
PPTX
Ch 4 linker loader
Malek Sumaiya
 
PPTX
Assemblers
Dattatray Gandhmal
 
PPTX
Direct linking loaders
Satyamevjayte Haxor
 
PPTX
Introduction to loaders
Tech_MX
 
PPTX
Unit 3 sp assembler
Deepmala Sharma
 
PPT
Intermediate code generation (Compiler Design)
Tasif Tanzim
 
PPTX
source code metrics and other maintenance tools and techniques
Siva Priya
 
PPT
Assemblers: Ch03
desta_gebre
 
PDF
Macro-processor
Temesgen Molla
 
PPTX
System programming
jayashri kolekar
 
PPTX
System Programing Unit 1
Manoj Patil
 
PPTX
Decomposition using Functional Dependency
Raj Naik
 
PPTX
Design of a two pass assembler
Dhananjaysinh Jhala
 
PPTX
MACRO PROCESSOR
Bhavik Vashi
 
PPT
Software tools
ravindravekariya
 
PPTX
Principal Sources of Optimization in compiler design
LogsAk
 
Single pass assembler
Bansari Shah
 
Unit 2
pm_ghate
 
Linking in MS-Dos System
Satyamevjayte Haxor
 
Two pass Assembler
Satyamevjayte Haxor
 
Ch 4 linker loader
Malek Sumaiya
 
Assemblers
Dattatray Gandhmal
 
Direct linking loaders
Satyamevjayte Haxor
 
Introduction to loaders
Tech_MX
 
Unit 3 sp assembler
Deepmala Sharma
 
Intermediate code generation (Compiler Design)
Tasif Tanzim
 
source code metrics and other maintenance tools and techniques
Siva Priya
 
Assemblers: Ch03
desta_gebre
 
Macro-processor
Temesgen Molla
 
System programming
jayashri kolekar
 
System Programing Unit 1
Manoj Patil
 
Decomposition using Functional Dependency
Raj Naik
 
Design of a two pass assembler
Dhananjaysinh Jhala
 
MACRO PROCESSOR
Bhavik Vashi
 
Software tools
ravindravekariya
 
Principal Sources of Optimization in compiler design
LogsAk
 

Similar to System software - macro expansion,nested macro calls (20)

PDF
Handout#05
Sunita Milind Dol
 
PDF
Module 5.pdf
SE14Darshan
 
PDF
Handout#04
Sunita Milind Dol
 
PDF
handout6.pdf
ssuser700533
 
PDF
Task Perform addition subtraction division and multiplic.pdf
acsmadurai
 
PPT
Ss4
Jaya Chavan
 
PPTX
Unit ii-111206004636-phpapp01
riddhi viradiya
 
PPTX
C language 3
Arafat Bin Reza
 
PPTX
Writing command macro in stratus cobol
Srinimf-Slides
 
PPT
Preprocessors
Koganti Ravikumar
 
PPTX
Macro Processor
Saranya1702
 
PDF
N_Asm Assembly macros (sol)
Selomon birhane
 
PPT
Macros in system programing
Brijesh__patel
 
PPTX
LISP: Macros in lisp
LISP Content
 
PPTX
LISP: Macros in lisp
DataminingTools Inc
 
PPTX
Presentation on macros and macro processor
Kuldeep Pathak
 
PDF
33443223 system-software-unit-iv
Shaniya Fathimuthu
 
PPTX
SAS Macro
Sonal Shrivastav
 
PPTX
Inline functions & macros
Anand Kumar
 
PDF
Unit 5 Part 1 Macros
Arpana Awasthi
 
Handout#05
Sunita Milind Dol
 
Module 5.pdf
SE14Darshan
 
Handout#04
Sunita Milind Dol
 
handout6.pdf
ssuser700533
 
Task Perform addition subtraction division and multiplic.pdf
acsmadurai
 
Unit ii-111206004636-phpapp01
riddhi viradiya
 
C language 3
Arafat Bin Reza
 
Writing command macro in stratus cobol
Srinimf-Slides
 
Preprocessors
Koganti Ravikumar
 
Macro Processor
Saranya1702
 
N_Asm Assembly macros (sol)
Selomon birhane
 
Macros in system programing
Brijesh__patel
 
LISP: Macros in lisp
LISP Content
 
LISP: Macros in lisp
DataminingTools Inc
 
Presentation on macros and macro processor
Kuldeep Pathak
 
33443223 system-software-unit-iv
Shaniya Fathimuthu
 
SAS Macro
Sonal Shrivastav
 
Inline functions & macros
Anand Kumar
 
Unit 5 Part 1 Macros
Arpana Awasthi
 
Ad

Recently uploaded (20)

PDF
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
PPTX
Post Dated Cheque(PDC) Management in Odoo 18
Celine George
 
PPTX
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
PPTX
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
PPTX
GRADE-3-PPT-EVE-2025-ENG-Q1-LESSON-1.pptx
EveOdrapngimapNarido
 
PDF
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
PPTX
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
PPT
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
PPTX
MENINGITIS: NURSING MANAGEMENT, BACTERIAL MENINGITIS, VIRAL MENINGITIS.pptx
PRADEEP ABOTHU
 
PDF
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
PPTX
HUMAN RESOURCE MANAGEMENT: RECRUITMENT, SELECTION, PLACEMENT, DEPLOYMENT, TRA...
PRADEEP ABOTHU
 
PPTX
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
PDF
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
PPTX
PPT-Q1-WK-3-ENGLISH Revised Matatag Grade 3.pptx
reijhongidayawan02
 
PPT
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
PDF
The Different Types of Non-Experimental Research
Thelma Villaflores
 
PPTX
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
PPTX
How to Create Odoo JS Dialog_Popup in Odoo 18
Celine George
 
PDF
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
PPTX
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
Post Dated Cheque(PDC) Management in Odoo 18
Celine George
 
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
GRADE-3-PPT-EVE-2025-ENG-Q1-LESSON-1.pptx
EveOdrapngimapNarido
 
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
MENINGITIS: NURSING MANAGEMENT, BACTERIAL MENINGITIS, VIRAL MENINGITIS.pptx
PRADEEP ABOTHU
 
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
HUMAN RESOURCE MANAGEMENT: RECRUITMENT, SELECTION, PLACEMENT, DEPLOYMENT, TRA...
PRADEEP ABOTHU
 
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
PPT-Q1-WK-3-ENGLISH Revised Matatag Grade 3.pptx
reijhongidayawan02
 
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
The Different Types of Non-Experimental Research
Thelma Villaflores
 
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
How to Create Odoo JS Dialog_Popup in Odoo 18
Celine George
 
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
Ad

System software - macro expansion,nested macro calls

  • 1. System Software Chapter – 3 1. Macro expansion 2.nested macro calls
  • 2. MACRO EXPANSION: The use of a macro name with a set of actual parameters is replaced by some code generated from its body. This is called macro expansion .
  • 3. Macro expansion can be performed by two kinds of language processor  Macro assembler  Macro pre-processor MACRO ASSEMBLER: Its performs expansion of a each macro call in a program into a sequence of assembly language statements and also assembles the resultant assembly language program. MACRO PRE-PROCESSOR: It only processes the macro call. Other statements are processes with the help of assembler.
  • 4. EXAMPLE FOR EXAPANSION MACRO DEFINITION EXPANSIONOF MACRO Label field  A ,B , AREG are an actual parameters.  &MEM_VAL, &INC_VAL,&REG are formal parameters.
  • 5. Two key notions concerning macro expansion are A. Expansion time control flow : This determines the order in which model statements are visited during macro expansion. B. Lexical substitution: Lexical substitution is used to generate an assembly statement from a model statement.
  • 6. A. Flow of control during expansion  The default flow of control during macro expansion is sequential.  In the absence of preprocessor statements, the model statements of a macro are visited sequentially starting with the statement following the macro prototype statement and ending with the statement preceding the MEND statement.
  • 7. What can alter the flow of control during expansion? o A pre-processor statement can alter the flow of control during expansion such that o Conditional Expansion: Some model statements are either never visited during expansion, or Expansion Time Loops: are repeatedly visited during expansion. o The flow of control during macro expansion is implemented using a macro expansion counter (MEC)
  • 8. ALGORITHM (MACRO EXPANSION) 1. MEC:=statement number of first statement following the prototype statement. 2. While statement pointed by MEC is not a MEND statement. a. If a model statement then i. Expand the statement ii. MEC:=MEC+1; b. Else (i.e. a preprocessor statement) i. MEC:= new value specified in the statement. 3. Exit from macro expansion.
  • 9. B. LEXICAL SUBSTITUTION  A model statement consists of 3 types of strings.  An ordinary string, which stands for itself.  The name of a formal parameter which is preceded by the character „&‟.  The name of a pre-processor variable, which is also preceded by the character „&‟.  During lexical expansion, strings is retained in its original form .  The name of Formal parameter is replaced by its value from the actual parameter of a macro call.  The name of pre-processor variable is replaced with its value. This value is readily known to the pre-processor.
  • 10. Rules for determining the value of a formal parameter depends on the kind of parameter:  Positional Parameter  Keyword Parameter  Default specification of parameters  Macros with mixed parameter list  Other uses of parameter
  • 11. POSITIONAL PARAMETERS A positional formal parameter is written as &<parameter name> e.g. &SAMPLE where SAMPLE is the name of parameter. <parameter kind> of syntax rule is omitted. The value of a positional formal parameter XYZ is determined by the rule of positional association as follows: 1. Find the ordinal position of XYZ in the list of formal parameters in the macro prototype statement. 2. Find the actual parameter specification occupying the same ordinal position in the list of actual parameters in the macro call statement.
  • 12. Consider the call INCR A,B,AREG On macro INCR , following rule of positional association, values of formal parameters are: Formal parameter value MEM_VAL A INCR_VAL B REG AREG Lexical expansion of the model statements now leads to the code + MOVER AREG, A + ADD AREG, B + MOVEM AREG, A MACRO INCR &MEM_VAL,&INCR_VAL &REG MOVER &REG, &MEM_VAL ADD &REG, &INCR_VAL MOVEM &REG, &MEM_VAL MEND Consider the macro
  • 13. KEYWORD PARAMETER For keyword parameter, <parameter name> is an ordinary string and <parameter kind> is the string „=‟ in syntax rule. The <actual parameter spec> is written as<formal parameter name>=<ordinary string>. Note that the ordinal position of the specification XYZ=ABC in the list of actual parameters is immaterial. This is very useful in situations where long lists of parameters have to be used. Let us see example for it.
  • 14. Following are macro call statement: INCR_M MEM_VAL=A, INCR_VAL=B, REG=AREG ------ INCR_M INCR_VAL=B, REG=AREG, MEM_VAL=A Both are equivalent. Following is macro definition using keyword parameter: MACRO INCR_M &MEM_VAL=, &INCR_VAL=,&REG= MOVER &REG, &MEM_VAL ADD &REG, &INCR_VAL MOVEM &REG,&MEM_
  • 15. DEFAULT SPECIFICATIONS OF PARAMETERS A default value is a standard assumption in the absence of an explicit specification by the programmer. Default specification of parameters is useful in situations where a parameter has the same value in most calls. When the desired value is different from the default value, the desired value can be specified explicitly in a macro call. The syntax for formal parameter specification, as follows: &<parameter name> [<parameter kind> [<default value>]]
  • 16. EXAMPLE MACRO INCR_D &MEM_VAL=, &INCR_VAL=, &REG=AREG MOVER &REG, &MEM_VAL ADD &REG, &INCR_VAL MOVEM &REG, &MEM_VAL MEND The macro can be redefined to use a default specification for the parameter REG INCR_D MEM_VAL=A, INCR_VAL=B INCR_D INCR_VAL=B, MEM_VAL=A INCR_D INCR_VAL=B, MEM_VAL=A, REG=BREG First two calls are equivalent but third call overrides the default value for REG with the value BREG in next example.
  • 17. MACROS WITH MIXED PARAMETER LISTS A macro may be defined to use both positional and keyword parameters. In such a case, all positional parameters must precede all keyword parameters. example in the macro call SUM A, B, G=20, H=X A, B are positional parameters while G, H are keyword parameters. Correspondence between actual and formal parameters is established by applying the rules governing positional and keyword parameters separately.
  • 18. OTHER USES OF PARAMETERS The model statements have used formal parameters only in operand field. However, use of parameters is not restricted to these fields. Formal parameters can also appear in the label and opcode fields of model statements.
  • 19. NESTED MACRO CALLS  A model statement in a macro may constitute a call on another macro.  Such calls are known as nested macro calls.  Macro containing the nested call is the outer macro and, Macro called is inner macro.  They follow LIFO rule.  Thus, in structure of nested macro calls, expansion of latest macro call (i.e inner macro) is completed first.