SlideShare a Scribd company logo
System Programming Sunita M. Dol, CSE Dept
Walchand Institute of Technology, Solapur Page 1
HANDOUT#05
Aim:
Implementation of nested macro
Theory:
A macro is a unit of specification for program generation through expansion.
Macro Definition
A macro definition is enclosed between a macro header statement and a macro end
statement. Macro definitions are typically located at the start of a program. Macro
definition consists of:
1. Macro prototype statements
2. One or more model statements
3. Macro preprocessor statements
1. Macro prototype statements.
The macro prototype statement declares the name of the macro and the names and
kinds of its parameters. The macro prototype statement has the following syntax:
<macro name> [<formal parameter specification>[ …..]]
where <macro name> appears in the mnemonic field of assembly Statement and
<formal parameter specification> is of the form
&<parameter name> [<parameter kind>]
2. Model statements.
A model statement is a statement from which assembly language statements may
be generated during macro expansion.
3. Macro preprocessor statements.
A preprocessor statement is used to perform auxiliary functions during macro
expansion.
System Programming Sunita M. Dol, CSE Dept
Walchand Institute of Technology, Solapur Page 2
Macro call
A macro is called by writing the macro name in the mnemonic field of an
assembly statement. The macro call has syntax
<macro name> [<actual parameter specification>[,….]]
where actual parameter resembles an operand specification in assembly statement.
Example
The definition of macro INCR is given below
MACRO
INCR &MEM_VAL, &INCR_VAL, &REG
MOVER &REG, &MEM_VAL
ADD &REG, &INCR-VAL
MOVEM &REG, &MEM_VAL
MEND
Macro Expansion
A macro leads to macro expansion. During macro expansion, the use of a macro
name with a set of actual parameters i.e. the macro call statement is replaced by a
sequence of assembly code. To differentiate between the original statement of a
program and the statements resulting from macro expansion, each expanded
statement is marked with a ‘+’ preceding its label field.
There are two kinds of expansions
1. Lexical expansion.
2. Semantic expansion
1. Lexical expansion.
Lexical expansion implies replacement of a character string by another character
string during program generation. It replaces the occurrences of formal parameter
by corresponding actual parameters.
Example
Consider the following macro definition
MACRO
INCR &MEM_VAL, &INCR_VAL, &REG
MOVER &REG, &MEM_VAL
ADD &REG, &INCR-VAL
MOVEM &REG, &MEM_VAL
System Programming Sunita M. Dol, CSE Dept
Walchand Institute of Technology, Solapur Page 3
MEND
Consider macro call statement on INCR
INCR A, B, AREG
The values of formal parameters are:
Formal parameter value
MEM_VAL A
INCR_VAL B
REG AREG
Lexical expansion of the model statement leads to the code
+ MOVER AREG, A
+ ADD AREG, B
+ MOVEM AREG, A
2. Semantic expansion
Semantic expansion implies generation of instructions tailored to the requirements
of a specific usage e.g. generation of type specific instruction for manipulation of
byte and word operands. It is characterized by the fact that different use of macro
can lead to codes which differ in the number, sequence and opcodes of
instructions.
Example
Consider the macro definition
MACRO
CLEAR &X, &N
LCL &M
&M SET 0
MOVER AREG, =’0’
.MORE MOVEM AREG, &X+&M
&M SET &M+1
AIF (&M NE N) .MORE
MEND
Consider the macro call CLEAR B, 3
System Programming Sunita M. Dol, CSE Dept
Walchand Institute of Technology, Solapur Page 4
This macro call leads to generation of statements:
+ MOVER AREG, =’0’
+ MOVEM AREG, B
+ MOVEM AREG, B+1
+ MOVEM AREG, B+2
Nested Macro Calls
A model statement in a macro may constitute a call on another macro. Such calls
are known as nested macro calls. Expansion of nested macro calls follows the last-
in-first-out (LIFO) rule. Thus, in a structure of nested macro calls, expansion of the
latest macro call (I.e. the innermost macro call in the structure) is completed first.
Example
Consider an example
MACRO
COMPUTE &FRIST, &SECOND
MOVEM BREG, TMP
INCR &FIRST, &SECOND, AREG
MOVER BREG, TMP
MEND
and macro definition
MACRO
INCR &MEM_VAL, &INCR_VAL, &REG=
MOVER &REG, &MEM_VAL
ADD &REG, &INCR-VAL
MOVEM &REG, &MEM_VAL
MEND
System Programming
Walchand Institute of Technology
Input:
#include<stdio.h>
#define as 20+asd
#define xyz 5
#define asd 10+xyz
#define pf printf
#define sf scanf
void main(void)
{
pf("Enter a no:");
sf("%d",&a);
b=as+asd+xyz;
pf("xyz=%d",b);
}
Sunita M. Dol, CSE Dept
Walchand Institute of Technology, Solapur
#define asd 10+xyz
pf("Enter a no:");
sf("%d",&a);
b=as+asd+xyz;
pf("xyz=%d",b);
Sunita M. Dol, CSE Dept
Page 5
System Programming Sunita M. Dol, CSE Dept
Walchand Institute of Technology, Solapur Page 6
Output:
The old file
#include<stdio.h>
#define as 20+asd
#define xyz 5
#define asd 10+xyz
#define pf printf
#define sf scanf
void main(void)
{
pf("Enter a no:");
sf("%d",&a);
b=as+asd+xyz;
pf("xyz=%d",b);
}
MACRO EXPANSION
as 20+asd
xyz 5
asd 10+xyz
pf printf
sf scanf
The new file
#include<stdio.h>
void main(void)
{
printf("Enter a no:");
scanf("%d",&a);
b=20+10+5+10+5+5;
printf("xyz=%d",b);
}
System Programming Sunita M. Dol, CSE Dept
Walchand Institute of Technology, Solapur Page 7
Conclusion:
A macro is a unit of specification for program generation through expansion.
A model statement in a macro may constitute a call on another macro. Such
calls are known as nested macro calls.
Expansion of nested macro calls follows the last-in-first-out (LIFO) rule.
Nested macro is implemented in C-language.

More Related Content

What's hot

Handout#08
Handout#08Handout#08
Handout#08
Sunita Milind Dol
 
Assignment4
Assignment4Assignment4
Assignment4
Sunita Milind Dol
 
Handout#06
Handout#06Handout#06
Handout#06
Sunita Milind Dol
 
Handout#09
Handout#09Handout#09
Handout#09
Sunita Milind Dol
 
Handout#01
Handout#01Handout#01
Handout#01
Sunita Milind Dol
 
Handout#12
Handout#12Handout#12
Handout#12
Sunita Milind Dol
 
Introduction of C++ By Pawan Thakur
Introduction of C++ By Pawan ThakurIntroduction of C++ By Pawan Thakur
Introduction of C++ By Pawan Thakur
Govt. P.G. College Dharamshala
 
Oops
OopsOops
Solutions manual for c++ programming from problem analysis to program design ...
Solutions manual for c++ programming from problem analysis to program design ...Solutions manual for c++ programming from problem analysis to program design ...
Solutions manual for c++ programming from problem analysis to program design ...
Warren0989
 
The smartpath information systems c plus plus
The smartpath information systems  c plus plusThe smartpath information systems  c plus plus
The smartpath information systems c plus plus
The Smartpath Information Systems,Bhilai,Durg,Chhattisgarh.
 
Java conceptual learning material
Java conceptual learning materialJava conceptual learning material
Java conceptual learning material
ArthyR3
 
C language
C languageC language
C language
spatidar0
 
C programming notes
C programming notesC programming notes
C programming notes
Prof. Dr. K. Adisesha
 
OOP Poster Presentation
OOP Poster PresentationOOP Poster Presentation
OOP Poster Presentation
Md Mofijul Haque
 
C programming course material
C programming course materialC programming course material
C programming course material
Ranjitha Murthy
 

What's hot (20)

Handout#08
Handout#08Handout#08
Handout#08
 
Assignment4
Assignment4Assignment4
Assignment4
 
Handout#06
Handout#06Handout#06
Handout#06
 
Handout#09
Handout#09Handout#09
Handout#09
 
Handout#01
Handout#01Handout#01
Handout#01
 
Handout#12
Handout#12Handout#12
Handout#12
 
Chapter2
Chapter2Chapter2
Chapter2
 
Introduction of C++ By Pawan Thakur
Introduction of C++ By Pawan ThakurIntroduction of C++ By Pawan Thakur
Introduction of C++ By Pawan Thakur
 
Chap02
Chap02Chap02
Chap02
 
C notes
C notesC notes
C notes
 
Oops
OopsOops
Oops
 
C LANGUAGE NOTES
C LANGUAGE NOTESC LANGUAGE NOTES
C LANGUAGE NOTES
 
Solutions manual for c++ programming from problem analysis to program design ...
Solutions manual for c++ programming from problem analysis to program design ...Solutions manual for c++ programming from problem analysis to program design ...
Solutions manual for c++ programming from problem analysis to program design ...
 
The smartpath information systems c plus plus
The smartpath information systems  c plus plusThe smartpath information systems  c plus plus
The smartpath information systems c plus plus
 
Java conceptual learning material
Java conceptual learning materialJava conceptual learning material
Java conceptual learning material
 
C language
C languageC language
C language
 
C tutorial
C tutorialC tutorial
C tutorial
 
C programming notes
C programming notesC programming notes
C programming notes
 
OOP Poster Presentation
OOP Poster PresentationOOP Poster Presentation
OOP Poster Presentation
 
C programming course material
C programming course materialC programming course material
C programming course material
 

Similar to Handout#05

Unit 2
Unit 2Unit 2
Unit 2
pm_ghate
 
System software - macro expansion,nested macro calls
System software - macro expansion,nested macro callsSystem software - macro expansion,nested macro calls
System software - macro expansion,nested macro calls
SARASWATHI S
 
Module 5.pdf
Module 5.pdfModule 5.pdf
Module 5.pdf
SE14Darshan
 
handout6.pdf
handout6.pdfhandout6.pdf
handout6.pdf
ssuser700533
 
Unit 4 sp macro
Unit 4 sp macroUnit 4 sp macro
Unit 4 sp macro
Deepmala Sharma
 
Ss4
Ss4Ss4
Task Perform addition subtraction division and multiplic.pdf
Task Perform addition subtraction division and multiplic.pdfTask Perform addition subtraction division and multiplic.pdf
Task Perform addition subtraction division and multiplic.pdf
acsmadurai
 
Preprocessor directives in c language
Preprocessor directives in c languagePreprocessor directives in c language
Preprocessor directives in c language
tanmaymodi4
 
Preprocessor directives in c laguage
Preprocessor directives in c laguagePreprocessor directives in c laguage
Preprocessor directives in c laguage
Tanmay Modi
 
33443223 system-software-unit-iv
33443223 system-software-unit-iv33443223 system-software-unit-iv
33443223 system-software-unit-ivShaniya Fathimuthu
 
Inline functions & macros
Inline functions & macrosInline functions & macros
Inline functions & macros
Anand Kumar
 
MIGHTY MACROS AND POWERFUL PARAMETERS: MAXIMIZING EFFICIENCY AND FLEXIBILITY ...
MIGHTY MACROS AND POWERFUL PARAMETERS: MAXIMIZING EFFICIENCY AND FLEXIBILITY ...MIGHTY MACROS AND POWERFUL PARAMETERS: MAXIMIZING EFFICIENCY AND FLEXIBILITY ...
MIGHTY MACROS AND POWERFUL PARAMETERS: MAXIMIZING EFFICIENCY AND FLEXIBILITY ...
VLSICS Design
 
Macro-processor
Macro-processorMacro-processor
Macro-processor
Temesgen Molla
 
Macro Processor
Macro ProcessorMacro Processor
Macro Processor
Saranya1702
 
N_Asm Assembly macros (sol)
N_Asm Assembly macros (sol)N_Asm Assembly macros (sol)
N_Asm Assembly macros (sol)
Selomon birhane
 
Computer fundamentals
Computer fundamentalsComputer fundamentals
Computer fundamentals
sameer sheikh
 
SAS Macros part 1
SAS Macros part 1SAS Macros part 1
SAS Macros part 1venkatam
 
What's New In C# 5.0 - Programar 2013
What's New In C# 5.0 - Programar 2013What's New In C# 5.0 - Programar 2013
What's New In C# 5.0 - Programar 2013
Paulo Morgado
 

Similar to Handout#05 (20)

Unit 2
Unit 2Unit 2
Unit 2
 
System software - macro expansion,nested macro calls
System software - macro expansion,nested macro callsSystem software - macro expansion,nested macro calls
System software - macro expansion,nested macro calls
 
Module 5.pdf
Module 5.pdfModule 5.pdf
Module 5.pdf
 
handout6.pdf
handout6.pdfhandout6.pdf
handout6.pdf
 
Unit 4 sp macro
Unit 4 sp macroUnit 4 sp macro
Unit 4 sp macro
 
Ss4
Ss4Ss4
Ss4
 
Task Perform addition subtraction division and multiplic.pdf
Task Perform addition subtraction division and multiplic.pdfTask Perform addition subtraction division and multiplic.pdf
Task Perform addition subtraction division and multiplic.pdf
 
Preprocessor directives in c language
Preprocessor directives in c languagePreprocessor directives in c language
Preprocessor directives in c language
 
Preprocessor directives in c laguage
Preprocessor directives in c laguagePreprocessor directives in c laguage
Preprocessor directives in c laguage
 
33443223 system-software-unit-iv
33443223 system-software-unit-iv33443223 system-software-unit-iv
33443223 system-software-unit-iv
 
Inline functions & macros
Inline functions & macrosInline functions & macros
Inline functions & macros
 
MIGHTY MACROS AND POWERFUL PARAMETERS: MAXIMIZING EFFICIENCY AND FLEXIBILITY ...
MIGHTY MACROS AND POWERFUL PARAMETERS: MAXIMIZING EFFICIENCY AND FLEXIBILITY ...MIGHTY MACROS AND POWERFUL PARAMETERS: MAXIMIZING EFFICIENCY AND FLEXIBILITY ...
MIGHTY MACROS AND POWERFUL PARAMETERS: MAXIMIZING EFFICIENCY AND FLEXIBILITY ...
 
Preprocessors
PreprocessorsPreprocessors
Preprocessors
 
Pre processor directives in c
Pre processor directives in cPre processor directives in c
Pre processor directives in c
 
Macro-processor
Macro-processorMacro-processor
Macro-processor
 
Macro Processor
Macro ProcessorMacro Processor
Macro Processor
 
N_Asm Assembly macros (sol)
N_Asm Assembly macros (sol)N_Asm Assembly macros (sol)
N_Asm Assembly macros (sol)
 
Computer fundamentals
Computer fundamentalsComputer fundamentals
Computer fundamentals
 
SAS Macros part 1
SAS Macros part 1SAS Macros part 1
SAS Macros part 1
 
What's New In C# 5.0 - Programar 2013
What's New In C# 5.0 - Programar 2013What's New In C# 5.0 - Programar 2013
What's New In C# 5.0 - Programar 2013
 

More from Sunita Milind Dol

Unit Number 5 - Research Ethics, IPR and Publishing
Unit Number 5 - Research Ethics, IPR and PublishingUnit Number 5 - Research Ethics, IPR and Publishing
Unit Number 5 - Research Ethics, IPR and Publishing
Sunita Milind Dol
 
Unit Number 4 - Research reports and Thesis writing
Unit Number 4 - Research reports and Thesis writingUnit Number 4 - Research reports and Thesis writing
Unit Number 4 - Research reports and Thesis writing
Sunita Milind Dol
 
Unit Number 3 - Data collection and Statistical Analysis
Unit Number 3 - Data collection and Statistical AnalysisUnit Number 3 - Data collection and Statistical Analysis
Unit Number 3 - Data collection and Statistical Analysis
Sunita Milind Dol
 
Unit Number 2 - Research Problem Formulation and Methods
Unit Number 2 - Research Problem Formulation and MethodsUnit Number 2 - Research Problem Formulation and Methods
Unit Number 2 - Research Problem Formulation and Methods
Sunita Milind Dol
 
Unit Number 1 - Introduction to Research
Unit Number 1 - Introduction to ResearchUnit Number 1 - Introduction to Research
Unit Number 1 - Introduction to Research
Sunita Milind Dol
 
Unit Number 5 - Research Ethics, IPR and Publishing
Unit Number 5 - Research Ethics, IPR and PublishingUnit Number 5 - Research Ethics, IPR and Publishing
Unit Number 5 - Research Ethics, IPR and Publishing
Sunita Milind Dol
 
Unit Number 5 - Research reports and Thesis writing
Unit Number 5 - Research reports and Thesis writingUnit Number 5 - Research reports and Thesis writing
Unit Number 5 - Research reports and Thesis writing
Sunita Milind Dol
 
Unit Number 3 - Data collection and Statistical Analysis
Unit Number 3 - Data collection and Statistical AnalysisUnit Number 3 - Data collection and Statistical Analysis
Unit Number 3 - Data collection and Statistical Analysis
Sunita Milind Dol
 
Unit Number 2 - Research Problem Formulation and Methods
Unit Number 2 - Research Problem Formulation and MethodsUnit Number 2 - Research Problem Formulation and Methods
Unit Number 2 - Research Problem Formulation and Methods
Sunita Milind Dol
 
Unit Number 1 : Introduction to Research
Unit Number 1 : Introduction to ResearchUnit Number 1 : Introduction to Research
Unit Number 1 : Introduction to Research
Sunita Milind Dol
 
7. Nested Subqueries.pdf
7. Nested Subqueries.pdf7. Nested Subqueries.pdf
7. Nested Subqueries.pdf
Sunita Milind Dol
 
6. Aggregate Functions.pdf
6. Aggregate Functions.pdf6. Aggregate Functions.pdf
6. Aggregate Functions.pdf
Sunita Milind Dol
 
5. Basic Structure of SQL Queries.pdf
5. Basic Structure of SQL Queries.pdf5. Basic Structure of SQL Queries.pdf
5. Basic Structure of SQL Queries.pdf
Sunita Milind Dol
 
4. DML.pdf
4. DML.pdf4. DML.pdf
4. DML.pdf
Sunita Milind Dol
 
3. DDL.pdf
3. DDL.pdf3. DDL.pdf
3. DDL.pdf
Sunita Milind Dol
 
2. SQL Introduction.pdf
2. SQL Introduction.pdf2. SQL Introduction.pdf
2. SQL Introduction.pdf
Sunita Milind Dol
 
1. University Example.pdf
1. University Example.pdf1. University Example.pdf
1. University Example.pdf
Sunita Milind Dol
 
Assignment12
Assignment12Assignment12
Assignment12
Sunita Milind Dol
 

More from Sunita Milind Dol (20)

Unit Number 5 - Research Ethics, IPR and Publishing
Unit Number 5 - Research Ethics, IPR and PublishingUnit Number 5 - Research Ethics, IPR and Publishing
Unit Number 5 - Research Ethics, IPR and Publishing
 
Unit Number 4 - Research reports and Thesis writing
Unit Number 4 - Research reports and Thesis writingUnit Number 4 - Research reports and Thesis writing
Unit Number 4 - Research reports and Thesis writing
 
Unit Number 3 - Data collection and Statistical Analysis
Unit Number 3 - Data collection and Statistical AnalysisUnit Number 3 - Data collection and Statistical Analysis
Unit Number 3 - Data collection and Statistical Analysis
 
Unit Number 2 - Research Problem Formulation and Methods
Unit Number 2 - Research Problem Formulation and MethodsUnit Number 2 - Research Problem Formulation and Methods
Unit Number 2 - Research Problem Formulation and Methods
 
Unit Number 1 - Introduction to Research
Unit Number 1 - Introduction to ResearchUnit Number 1 - Introduction to Research
Unit Number 1 - Introduction to Research
 
Unit Number 5 - Research Ethics, IPR and Publishing
Unit Number 5 - Research Ethics, IPR and PublishingUnit Number 5 - Research Ethics, IPR and Publishing
Unit Number 5 - Research Ethics, IPR and Publishing
 
Unit Number 5 - Research reports and Thesis writing
Unit Number 5 - Research reports and Thesis writingUnit Number 5 - Research reports and Thesis writing
Unit Number 5 - Research reports and Thesis writing
 
Unit Number 3 - Data collection and Statistical Analysis
Unit Number 3 - Data collection and Statistical AnalysisUnit Number 3 - Data collection and Statistical Analysis
Unit Number 3 - Data collection and Statistical Analysis
 
Unit Number 2 - Research Problem Formulation and Methods
Unit Number 2 - Research Problem Formulation and MethodsUnit Number 2 - Research Problem Formulation and Methods
Unit Number 2 - Research Problem Formulation and Methods
 
Unit Number 1 : Introduction to Research
Unit Number 1 : Introduction to ResearchUnit Number 1 : Introduction to Research
Unit Number 1 : Introduction to Research
 
9.Joins.pdf
9.Joins.pdf9.Joins.pdf
9.Joins.pdf
 
8.Views.pdf
8.Views.pdf8.Views.pdf
8.Views.pdf
 
7. Nested Subqueries.pdf
7. Nested Subqueries.pdf7. Nested Subqueries.pdf
7. Nested Subqueries.pdf
 
6. Aggregate Functions.pdf
6. Aggregate Functions.pdf6. Aggregate Functions.pdf
6. Aggregate Functions.pdf
 
5. Basic Structure of SQL Queries.pdf
5. Basic Structure of SQL Queries.pdf5. Basic Structure of SQL Queries.pdf
5. Basic Structure of SQL Queries.pdf
 
4. DML.pdf
4. DML.pdf4. DML.pdf
4. DML.pdf
 
3. DDL.pdf
3. DDL.pdf3. DDL.pdf
3. DDL.pdf
 
2. SQL Introduction.pdf
2. SQL Introduction.pdf2. SQL Introduction.pdf
2. SQL Introduction.pdf
 
1. University Example.pdf
1. University Example.pdf1. University Example.pdf
1. University Example.pdf
 
Assignment12
Assignment12Assignment12
Assignment12
 

Recently uploaded

Self-Control of Emotions by Slidesgo.pptx
Self-Control of Emotions by Slidesgo.pptxSelf-Control of Emotions by Slidesgo.pptx
Self-Control of Emotions by Slidesgo.pptx
iemerc2024
 
basic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdfbasic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdf
NidhalKahouli2
 
A review on techniques and modelling methodologies used for checking electrom...
A review on techniques and modelling methodologies used for checking electrom...A review on techniques and modelling methodologies used for checking electrom...
A review on techniques and modelling methodologies used for checking electrom...
nooriasukmaningtyas
 
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
ydteq
 
Building Electrical System Design & Installation
Building Electrical System Design & InstallationBuilding Electrical System Design & Installation
Building Electrical System Design & Installation
symbo111
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
JoytuBarua2
 
Literature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptxLiterature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptx
Dr Ramhari Poudyal
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
bakpo1
 
Hierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power SystemHierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power System
Kerry Sado
 
PROJECT FORMAT FOR EVS AMITY UNIVERSITY GWALIOR.ppt
PROJECT FORMAT FOR EVS AMITY UNIVERSITY GWALIOR.pptPROJECT FORMAT FOR EVS AMITY UNIVERSITY GWALIOR.ppt
PROJECT FORMAT FOR EVS AMITY UNIVERSITY GWALIOR.ppt
bhadouriyakaku
 
digital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdfdigital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdf
drwaing
 
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
Mukeshwaran Balu
 
ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024
Rahul
 
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressionsKuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
Victor Morales
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
thanhdowork
 
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
insn4465
 
Water billing management system project report.pdf
Water billing management system project report.pdfWater billing management system project report.pdf
Water billing management system project report.pdf
Kamal Acharya
 
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming PipelinesHarnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Christina Lin
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
obonagu
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
Massimo Talia
 

Recently uploaded (20)

Self-Control of Emotions by Slidesgo.pptx
Self-Control of Emotions by Slidesgo.pptxSelf-Control of Emotions by Slidesgo.pptx
Self-Control of Emotions by Slidesgo.pptx
 
basic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdfbasic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdf
 
A review on techniques and modelling methodologies used for checking electrom...
A review on techniques and modelling methodologies used for checking electrom...A review on techniques and modelling methodologies used for checking electrom...
A review on techniques and modelling methodologies used for checking electrom...
 
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
 
Building Electrical System Design & Installation
Building Electrical System Design & InstallationBuilding Electrical System Design & Installation
Building Electrical System Design & Installation
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
 
Literature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptxLiterature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptx
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
 
Hierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power SystemHierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power System
 
PROJECT FORMAT FOR EVS AMITY UNIVERSITY GWALIOR.ppt
PROJECT FORMAT FOR EVS AMITY UNIVERSITY GWALIOR.pptPROJECT FORMAT FOR EVS AMITY UNIVERSITY GWALIOR.ppt
PROJECT FORMAT FOR EVS AMITY UNIVERSITY GWALIOR.ppt
 
digital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdfdigital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdf
 
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
 
ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024
 
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressionsKuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
 
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
 
Water billing management system project report.pdf
Water billing management system project report.pdfWater billing management system project report.pdf
Water billing management system project report.pdf
 
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming PipelinesHarnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
 

Handout#05

  • 1. System Programming Sunita M. Dol, CSE Dept Walchand Institute of Technology, Solapur Page 1 HANDOUT#05 Aim: Implementation of nested macro Theory: A macro is a unit of specification for program generation through expansion. Macro Definition A macro definition is enclosed between a macro header statement and a macro end statement. Macro definitions are typically located at the start of a program. Macro definition consists of: 1. Macro prototype statements 2. One or more model statements 3. Macro preprocessor statements 1. Macro prototype statements. The macro prototype statement declares the name of the macro and the names and kinds of its parameters. The macro prototype statement has the following syntax: <macro name> [<formal parameter specification>[ …..]] where <macro name> appears in the mnemonic field of assembly Statement and <formal parameter specification> is of the form &<parameter name> [<parameter kind>] 2. Model statements. A model statement is a statement from which assembly language statements may be generated during macro expansion. 3. Macro preprocessor statements. A preprocessor statement is used to perform auxiliary functions during macro expansion.
  • 2. System Programming Sunita M. Dol, CSE Dept Walchand Institute of Technology, Solapur Page 2 Macro call A macro is called by writing the macro name in the mnemonic field of an assembly statement. The macro call has syntax <macro name> [<actual parameter specification>[,….]] where actual parameter resembles an operand specification in assembly statement. Example The definition of macro INCR is given below MACRO INCR &MEM_VAL, &INCR_VAL, &REG MOVER &REG, &MEM_VAL ADD &REG, &INCR-VAL MOVEM &REG, &MEM_VAL MEND Macro Expansion A macro leads to macro expansion. During macro expansion, the use of a macro name with a set of actual parameters i.e. the macro call statement is replaced by a sequence of assembly code. To differentiate between the original statement of a program and the statements resulting from macro expansion, each expanded statement is marked with a ‘+’ preceding its label field. There are two kinds of expansions 1. Lexical expansion. 2. Semantic expansion 1. Lexical expansion. Lexical expansion implies replacement of a character string by another character string during program generation. It replaces the occurrences of formal parameter by corresponding actual parameters. Example Consider the following macro definition MACRO INCR &MEM_VAL, &INCR_VAL, &REG MOVER &REG, &MEM_VAL ADD &REG, &INCR-VAL MOVEM &REG, &MEM_VAL
  • 3. System Programming Sunita M. Dol, CSE Dept Walchand Institute of Technology, Solapur Page 3 MEND Consider macro call statement on INCR INCR A, B, AREG The values of formal parameters are: Formal parameter value MEM_VAL A INCR_VAL B REG AREG Lexical expansion of the model statement leads to the code + MOVER AREG, A + ADD AREG, B + MOVEM AREG, A 2. Semantic expansion Semantic expansion implies generation of instructions tailored to the requirements of a specific usage e.g. generation of type specific instruction for manipulation of byte and word operands. It is characterized by the fact that different use of macro can lead to codes which differ in the number, sequence and opcodes of instructions. Example Consider the macro definition MACRO CLEAR &X, &N LCL &M &M SET 0 MOVER AREG, =’0’ .MORE MOVEM AREG, &X+&M &M SET &M+1 AIF (&M NE N) .MORE MEND Consider the macro call CLEAR B, 3
  • 4. System Programming Sunita M. Dol, CSE Dept Walchand Institute of Technology, Solapur Page 4 This macro call leads to generation of statements: + MOVER AREG, =’0’ + MOVEM AREG, B + MOVEM AREG, B+1 + MOVEM AREG, B+2 Nested Macro Calls A model statement in a macro may constitute a call on another macro. Such calls are known as nested macro calls. Expansion of nested macro calls follows the last- in-first-out (LIFO) rule. Thus, in a structure of nested macro calls, expansion of the latest macro call (I.e. the innermost macro call in the structure) is completed first. Example Consider an example MACRO COMPUTE &FRIST, &SECOND MOVEM BREG, TMP INCR &FIRST, &SECOND, AREG MOVER BREG, TMP MEND and macro definition MACRO INCR &MEM_VAL, &INCR_VAL, &REG= MOVER &REG, &MEM_VAL ADD &REG, &INCR-VAL MOVEM &REG, &MEM_VAL MEND
  • 5. System Programming Walchand Institute of Technology Input: #include<stdio.h> #define as 20+asd #define xyz 5 #define asd 10+xyz #define pf printf #define sf scanf void main(void) { pf("Enter a no:"); sf("%d",&a); b=as+asd+xyz; pf("xyz=%d",b); } Sunita M. Dol, CSE Dept Walchand Institute of Technology, Solapur #define asd 10+xyz pf("Enter a no:"); sf("%d",&a); b=as+asd+xyz; pf("xyz=%d",b); Sunita M. Dol, CSE Dept Page 5
  • 6. System Programming Sunita M. Dol, CSE Dept Walchand Institute of Technology, Solapur Page 6 Output: The old file #include<stdio.h> #define as 20+asd #define xyz 5 #define asd 10+xyz #define pf printf #define sf scanf void main(void) { pf("Enter a no:"); sf("%d",&a); b=as+asd+xyz; pf("xyz=%d",b); } MACRO EXPANSION as 20+asd xyz 5 asd 10+xyz pf printf sf scanf The new file #include<stdio.h> void main(void) { printf("Enter a no:"); scanf("%d",&a); b=20+10+5+10+5+5; printf("xyz=%d",b); }
  • 7. System Programming Sunita M. Dol, CSE Dept Walchand Institute of Technology, Solapur Page 7 Conclusion: A macro is a unit of specification for program generation through expansion. A model statement in a macro may constitute a call on another macro. Such calls are known as nested macro calls. Expansion of nested macro calls follows the last-in-first-out (LIFO) rule. Nested macro is implemented in C-language.