The document discusses macro processors and their functions. It covers:
- The basic functions of a macro processor including macro directives, prototypes, and expansion.
- One-pass and two-pass macro processing algorithms. One-pass can handle nested macros recursively.
- Data structures for storing macro definitions and arguments during expansion.
- Techniques for handling nested macros, generating unique labels, and conditional and looping expansion.
- Machine-independent features like concatenation, null arguments, and keyword parameters.
Introduction, Macro Definition and Call, Macro Expansion, Nested Macro Calls, Advanced Macro Facilities, Design Of a Macro Preprocessor, Design of a Macro Assembler, Functions of a Macro Processor, Basic Tasks of a Macro Processor, Design Issues of Macro Processors, Features, Macro Processor Design Options, Two-Pass Macro Processors, One-Pass Macro Processors
A macro processor is a system software. Macro is that the Section of code that the programmer writes (defines) once, and then can use or invokes many times.
Description of all types of Loaders from System programming subjects.
eg. Compile-Go Loader
General Loader
Absolute Loader
Relocating Loader
Practical Relocating Loader
Linking Loader
Linker Vs. Loader
general relocatable loader
Introduction, Macro Definition and Call, Macro Expansion, Nested Macro Calls, Advanced Macro Facilities, Design Of a Macro Preprocessor, Design of a Macro Assembler, Functions of a Macro Processor, Basic Tasks of a Macro Processor, Design Issues of Macro Processors, Features, Macro Processor Design Options, Two-Pass Macro Processors, One-Pass Macro Processors
A macro processor is a system software. Macro is that the Section of code that the programmer writes (defines) once, and then can use or invokes many times.
Description of all types of Loaders from System programming subjects.
eg. Compile-Go Loader
General Loader
Absolute Loader
Relocating Loader
Practical Relocating Loader
Linking Loader
Linker Vs. Loader
general relocatable loader
Assembler is a kind of system software that translate mnemonic codes written in assembly language (which is, in turn, a low-level language) into its equivalent object code (which is, in turn, need to change into executable code by loader and linker)
Assemblers Elements of Assembly Language Programming, Design of the Assembler, Assembler Design Criteria, Types of Assemblers, Two-Pass Assemblers, One-Pass Assemblers, Single pass Assembler for Intel x86 , Algorithm of Single Pass Assembler, Multi-Pass Assemblers, Advanced Assembly Process, Variants of Assemblers Design of two pass assembler
Assembler is a kind of system software that translate mnemonic codes written in assembly language (which is, in turn, a low-level language) into its equivalent object code (which is, in turn, need to change into executable code by loader and linker)
Assemblers Elements of Assembly Language Programming, Design of the Assembler, Assembler Design Criteria, Types of Assemblers, Two-Pass Assemblers, One-Pass Assemblers, Single pass Assembler for Intel x86 , Algorithm of Single Pass Assembler, Multi-Pass Assemblers, Advanced Assembly Process, Variants of Assemblers Design of two pass assembler
Task Perform addition subtraction division and multiplic.pdfacsmadurai
Task: Perform addition, subtraction, division, and multiplication, of rational numbers on MIPS Mars
Programming Simulator by writing a code and print the answers (using macros) from the pictures
provided. Also, when you write the code make sure you follow this format,
format:
.macro print_int (%x)
li $v0, 1
add $a0, $zero, %x
syscall
.end_macro
print_int ($s0)
print_int (10)
Intro Settings Syscalls IDE Debugging Command Tools History Limitations Exception Handlers
Macros Acknowledgements MARS home Writing and Using Macros .macro, .end_macro,.eqv and
.include directives are new in MARS 4.3 Introduction to macros Patterson and Hennessy define a
macro as a pattern-matching and replacement facility that provides a simple mechanism to name
a frequently used sequence of instructions [1]. This permits the programmer to specify the
instruction sequence by invoking the macro. This requires only one line of code for each use
instead of repeatedly typing in the instruction sequence each time. It follows the axiom "define
once, use many times," which not only reduces the chance for error but also facilitates program
maintenance. Macros are like procedures (subroutines) in this sense but operate differently than
procedures. Procedures in MIPS assembly language follow particular protocols for procedure
definition, call and return. Macros operate by substituting the macro body for each use at the time
of assembly. This substitution is called macro expansion.. They do not require the protocols and
execution overhead of procedures. As a simple example, you may want to terminate your program
from a number of locations. If you are running from the MARS IDE, you will use system call 10,
exit. The instruction sequence is pretty easy 1i$v0,10syscal1 but still tedious. You can define a
macro, let's call it done, to represent this sequence [ begin{array}{l} text { macro done } text { i1 } $
text { vo, } 10 text { syscali } text { +end_macro } end{array} ] then invoke it whenever you wish
with the statement done At assembly time, the assembler will replace each occurrence of the
statement done with the two-statement sequence 1i$v0,10syscali This is the macro expansion.
The runtime simulator is unaware of macros or macro expansion. If running MARS from the
command line, perhaps you want to return a termination value. This can be done with syscall 17,
exit2, which takes the termination value as an argument. An equivalent macro, let's call it
terminate would be macro terminate (stermination_value) ii $a0, itermination_value li $v0,17
syscali .end_macro This macro defines a formal parameter to represent the termination value. You
would invoke it with the statement terminate (1) to terminate with value 1. Upon assembly, the
statement terminate (1) would be replaced byterninate (1) to terminate with value 1. Upon
assembly, the statement terainate (1) would be replaced by the three-statement sequence The
argument value, 1, is substituted wherever the formal parameter teermi.
This PPT covers the entire topic of Macro Assembler. This Includes the topic such as design of a macro assembler, 3 passes of macro assembler etc.
This is the PPT of System Programming.
Saudi Arabia stands as a titan in the global energy landscape, renowned for its abundant oil and gas resources. It's the largest exporter of petroleum and holds some of the world's most significant reserves. Let's delve into the top 10 oil and gas projects shaping Saudi Arabia's energy future in 2024.
Cosmetic shop management system project report.pdfKamal Acharya
Buying new cosmetic products is difficult. It can even be scary for those who have sensitive skin and are prone to skin trouble. The information needed to alleviate this problem is on the back of each product, but it's thought to interpret those ingredient lists unless you have a background in chemistry.
Instead of buying and hoping for the best, we can use data science to help us predict which products may be good fits for us. It includes various function programs to do the above mentioned tasks.
Data file handling has been effectively used in the program.
The automated cosmetic shop management system should deal with the automation of general workflow and administration process of the shop. The main processes of the system focus on customer's request where the system is able to search the most appropriate products and deliver it to the customers. It should help the employees to quickly identify the list of cosmetic product that have reached the minimum quantity and also keep a track of expired date for each cosmetic product. It should help the employees to find the rack number in which the product is placed.It is also Faster and more efficient way.
Water scarcity is the lack of fresh water resources to meet the standard water demand. There are two type of water scarcity. One is physical. The other is economic water scarcity.
Final project report on grocery store management system..pdfKamal Acharya
In today’s fast-changing business environment, it’s extremely important to be able to respond to client needs in the most effective and timely manner. If your customers wish to see your business online and have instant access to your products or services.
Online Grocery Store is an e-commerce website, which retails various grocery products. This project allows viewing various products available enables registered users to purchase desired products instantly using Paytm, UPI payment processor (Instant Pay) and also can place order by using Cash on Delivery (Pay Later) option. This project provides an easy access to Administrators and Managers to view orders placed using Pay Later and Instant Pay options.
In order to develop an e-commerce website, a number of Technologies must be studied and understood. These include multi-tiered architecture, server and client-side scripting techniques, implementation technologies, programming language (such as PHP, HTML, CSS, JavaScript) and MySQL relational databases. This is a project with the objective to develop a basic website where a consumer is provided with a shopping cart website and also to know about the technologies used to develop such a website.
This document will discuss each of the underlying technologies to create and implement an e- commerce website.
Welcome to WIPAC Monthly the magazine brought to you by the LinkedIn Group Water Industry Process Automation & Control.
In this month's edition, along with this month's industry news to celebrate the 13 years since the group was created we have articles including
A case study of the used of Advanced Process Control at the Wastewater Treatment works at Lleida in Spain
A look back on an article on smart wastewater networks in order to see how the industry has measured up in the interim around the adoption of Digital Transformation in the Water Industry.
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdffxintegritypublishin
Advancements in technology unveil a myriad of electrical and electronic breakthroughs geared towards efficiently harnessing limited resources to meet human energy demands. The optimization of hybrid solar PV panels and pumped hydro energy supply systems plays a pivotal role in utilizing natural resources effectively. This initiative not only benefits humanity but also fosters environmental sustainability. The study investigated the design optimization of these hybrid systems, focusing on understanding solar radiation patterns, identifying geographical influences on solar radiation, formulating a mathematical model for system optimization, and determining the optimal configuration of PV panels and pumped hydro storage. Through a comparative analysis approach and eight weeks of data collection, the study addressed key research questions related to solar radiation patterns and optimal system design. The findings highlighted regions with heightened solar radiation levels, showcasing substantial potential for power generation and emphasizing the system's efficiency. Optimizing system design significantly boosted power generation, promoted renewable energy utilization, and enhanced energy storage capacity. The study underscored the benefits of optimizing hybrid solar PV panels and pumped hydro energy supply systems for sustainable energy usage. Optimizing the design of solar PV panels and pumped hydro energy supply systems as examined across diverse climatic conditions in a developing country, not only enhances power generation but also improves the integration of renewable energy sources and boosts energy storage capacities, particularly beneficial for less economically prosperous regions. Additionally, the study provides valuable insights for advancing energy research in economically viable areas. Recommendations included conducting site-specific assessments, utilizing advanced modeling tools, implementing regular maintenance protocols, and enhancing communication among system components.
Overview of the fundamental roles in Hydropower generation and the components involved in wider Electrical Engineering.
This paper presents the design and construction of hydroelectric dams from the hydrologist’s survey of the valley before construction, all aspects and involved disciplines, fluid dynamics, structural engineering, generation and mains frequency regulation to the very transmission of power through the network in the United Kingdom.
Author: Robbie Edward Sayers
Collaborators and co editors: Charlie Sims and Connor Healey.
(C) 2024 Robbie E. Sayers
Explore the innovative world of trenchless pipe repair with our comprehensive guide, "The Benefits and Techniques of Trenchless Pipe Repair." This document delves into the modern methods of repairing underground pipes without the need for extensive excavation, highlighting the numerous advantages and the latest techniques used in the industry.
Learn about the cost savings, reduced environmental impact, and minimal disruption associated with trenchless technology. Discover detailed explanations of popular techniques such as pipe bursting, cured-in-place pipe (CIPP) lining, and directional drilling. Understand how these methods can be applied to various types of infrastructure, from residential plumbing to large-scale municipal systems.
Ideal for homeowners, contractors, engineers, and anyone interested in modern plumbing solutions, this guide provides valuable insights into why trenchless pipe repair is becoming the preferred choice for pipe rehabilitation. Stay informed about the latest advancements and best practices in the field.
2. INTRODUCTIONINTRODUCTION
A macro instruction (Macro) is a notational
convenience for the programmer
◦ Allows the programmer to write short hand
programs (modular programming).
The macro processor replaces each macro
instruction with its equivalent block of
instructions.
The macro processor is not concerned with
the meaning of the involved statements during
expansion.
The design of the macro processor is
generally machine independent.
3. BASIC MACRO PROCESSOR FUNCTIONSBASIC MACRO PROCESSOR FUNCTIONS
Directives used during usage of Macro:
◦ Macro: Indicates begin of Macro
◦ MEND: indicates end of Macro
Prototype for Macro:
◦ Each argument starts with Name and macro
◦ Parameter list
.
.
MEND
BODY: The statement will be generated as the
expansion of Macro
6. MACRO INVOCATIONMACRO INVOCATION
A macro invocation statement (a macro call) gives
the name of the macro instruction being invoked
and the arguments to be used in expanding the
macro.
◦ macro_name p1, p2, …
Difference between macro call and procedure call
◦ Macro call: statements of the macro body are
expanded each time the macro is invoked.
◦ Procedure call: statements of the subroutine
appear only one, regardless of how many times
the subroutine is called.
7. MACRO INVOCATIONMACRO INVOCATION
Question
◦ How does a programmer decide to use
macro calls or procedure calls?
From the viewpoint of a programmer
From the viewpoint of the CPU
8. EXCHANGE THE VALUES OF TWOEXCHANGE THE VALUES OF TWO
VARIABLESVARIABLES
void exchange(int a, int b) {
int temp;
temp = a;
a = b;
b = temp;
}
main() {
int i=1, j=3;
printf("BEFORE - %d %dn", i, j);
exchange(i, j);
printf("AFTER - %d %dn", i, j);
}
What’s the result?
9. 12 LINES OF ASSEMBLY CODE12 LINES OF ASSEMBLY CODE
10. SWAP TWO VARIABLES BY MACROSWAP TWO VARIABLES BY MACRO
#define swap(i,j) { int temp; temp=i; i=j;
j=temp; }
main() {
int i=1, j=3;
printf("BEFORE - %d %dn", i, j);
swap(i,j);
printf("AFTER - %d %dn", i, j);
}
11. BASIC MACRO PROCESSORBASIC MACRO PROCESSOR
FUNCTIONSFUNCTIONS
MAIN LDA #1
STA I
LDA #3
STA J
. Invoke a macro
LDA I
STA TEMP
LDA J
STA I
LDA TEMP
STA J
I RESW 1
J RESW 1
TEMP RESW 1
END MAIN
12. MACRO EXPANSIONMACRO EXPANSION
Each macro invocation statement will be
expanded into the statements that form the
body of the macro.
Arguments from the macro invocation
are substituted for the parameters in the
macro prototype (according to their
positions).
◦ In the definition of macro: parameter
◦ In the macro invocation: argument
13. MACRO EXPANSIONMACRO EXPANSION
Comment lines within the macro body will
be deleted.
Macro invocation statement itself has been
included as a comment line.
The label on the macro invocation statement
has been retained as a label on the first
statement generated in the macro expansion.
◦ We can use a macro instruction in exactly
the same
◦ way as an assembler language
mnemonic.
18. NO LABEL IN MACRO BODYNO LABEL IN MACRO BODY
Problem of the label in the body of macro:
◦ If the same macro is expanded multiple
times at different places in the program …
◦ There will be duplicate labels, which will
be treated as errors by the assembler.
Solutions:
◦ Do not use labels in the body of macro.
◦ Explicitly use PC-relative addressing
instead.
Ex, in RDBUFF and WRBUFF macros,
19. TWO-PASS MACRO PROCESSORTWO-PASS MACRO PROCESSOR
You may design a two-pass macro
processor
◦ Pass 1:
Process all macro definitions
◦ Pass 2:
Expand all macro invocation
statements
20. TWO-PASS MACRO PROCESSORTWO-PASS MACRO PROCESSOR
However, one-pass may be enough
◦ Because all macros would have to be
defined during the first pass before any
macro invocations were expanded.
The definition of a macro must appear
before any statements that invoke that
macro.
◦ Moreover, the body of one macro can
contain definitions of other macros.
21. EXAMPLE OF RECURSIVE MACROEXAMPLE OF RECURSIVE MACRO
DEFINITIONDEFINITION
MACROS (for SIC)
◦ Contains the definitions of RDBUFF
and WRBUFF written in SIC
instructions.
22. RECURSIVE MACRO DEFINITIONRECURSIVE MACRO DEFINITION
MACROX (for SIC/XE)
◦ Contains the definitions of RDBUFF
and WRBUFF written in SIC/XE
instructions.
23. MACRO DEFINITION: AN EXAMPLEMACRO DEFINITION: AN EXAMPLE
A program that is to be run on SIC
system could invoke MACROS whereas a
program to be run on SIC/XE can invoke
MACROX.
However, defining MACROS or
MACROX does not define RDBUFF and
WRBUFF.
◦ These definitions are processed only
when an invocation of MACROS or
MACROX is expanded.
24. ONE-PASS MACRO PROCESSORONE-PASS MACRO PROCESSOR
A one-pass macro processor that alternate
between macro definition and macro expansion in
a recursive way is able to handle recursive macro
definition.
Restriction
◦ The definition of a macro must appear in the
◦ source program before any statements that
◦ invoke that macro.
◦ This restriction does not create any real
◦ inconvenience.
25. DATA STRUCTURE FOR ONE-PASSDATA STRUCTURE FOR ONE-PASS
MACRO PROCESSORMACRO PROCESSOR
DEFTAB (definition table)
◦ Stores the macro definition including
macro
◦ prototype and macro body
◦ Comment lines are omitted.
◦ References to the macro instruction
parameters are
◦ converted to a positional notation for
efficiency in
◦ substituting arguments.
26. DATA STRUCTURE FOR ONE-PASSDATA STRUCTURE FOR ONE-PASS
MACRO PROCESSORMACRO PROCESSOR
NAMTAB
◦ Stores macro names
◦ Serves as an index to DEFTAB
◦ Pointers to the beginning and the end of
the
◦ macro definition (DEFTAB)
ARGTAB
◦ Stores the arguments of macro invocation
◦ according to their positions in the
argument list
◦ As the macro is expanded, arguments from
◦ ARGTAB are substituted for the
corresponding
◦ parameters in the macro body.
33. HANDLING NESTED MACROHANDLING NESTED MACRO
In DEFINE procedure
◦ When a macro definition is being entered
into
◦ DEFTAB, the normal approach is to
continue
◦ until an MEND directive is reached.
◦ This would not work for nested macro
definition because the first MEND
encountered in the inner macro will
terminate the whole macro definition
process.
34. HANDLING NESTED MACROHANDLING NESTED MACRO
To solve this problem, a counter LEVEL is
used to keep track of the level of macro
definitions.
◦ Increase LEVEL by 1 each time a
MACRO directive is read.
◦ Decrease LEVEL by 1 each time a MEND
directive is read.
◦ A MEND terminates the whole macro
definition process when LEVEL reaches 0.
◦ This process is very much like matching
left and right parentheses when scanning an
arithmetic expression.
35. COMPARISON OF MACROCOMPARISON OF MACRO
PROCESSOR DESIGNPROCESSOR DESIGN
One-pass algorithm
Every macro must be defined before it is
called
One-pass processor can alternate
between macro definition and macro
expansion
Nested macro definitions are allowed but
nested calls are not
36. COMPARISON OF MACROCOMPARISON OF MACRO
PROCESSOR DESIGNPROCESSOR DESIGN
Two-pass algorithm
◦ Pass1: Recognize macro definitions
◦ Pass2: Recognize macro calls
◦ Nested macro definitions are not
allowed
38. CONCATENATION OF MACROCONCATENATION OF MACRO
PARAMETERSPARAMETERS
Concatenation parameters with other
character strings.
◦ Used when a program consists a set of
series of variables.
39. COMPARISON OF MACROCOMPARISON OF MACRO
PROCESSOR DESIGNPROCESSOR DESIGN
Ambiguity problem
◦ If &ID and &ID1 are parameters
Solution to this ambiguity problem
◦ Use a special concatenation operator “-
>” to specify the end of the parameter
41. GENERATING UNIQUE LABELSGENERATING UNIQUE LABELS
Labels in the macro body may cause
“duplicate labels” problem if the macro is
invocated and expanded multiple times. Ex:
•Use of relative addressing at the source statement level is
very inconvenient, error-prone, and difficult to read.
42. GENERATING UNIQUE LABELSGENERATING UNIQUE LABELS
Let the macro processor generate unique
labels for each macro invocation and
expansion.
◦ During macro expansion, the $ will be replaced
with
◦ $xx, where xx is a two-character alphanumeric
counter
◦ of the number of macro instructions expanded.
◦ xx=AA,AB,AC,…..
This allows 1296 macro expansions in a
single program.
45. GENERATION OF UNIQUE LABELSGENERATION OF UNIQUE LABELS
Conditional assembly depends on
parameters provided
Part I is expanded if condition part is true,
otherwise part II is expanded
Compare operator: NE, EQ, LE, GT
46. GENERATION OF UNIQUE LABELSGENERATION OF UNIQUE LABELS
Begins with “&” but is not a macro instruction
parameter
Can be used to store working values during
the macro expansion
◦ -Store the evaluation result of Boolean
expression
-Control the macro-time conditional structures
Be initialized to a value of 0
Be set by a macro processor directive, SET
Ex: &EORCK SET 1
&EORCTR SET &EORCTR + 1
51. MACRO-TIME LOOPINGMACRO-TIME LOOPING
WHILE ( cond )
……
ENDW
Macro processor function
◦ %NITEMS: The number of members in an
argument list
The execution of testing of IF/WHILE,
SET,
◦ - %NITEMS() occurs at macro expansion
time
52. USE OF MACRO-TIME LOOPINGUSE OF MACRO-TIME LOOPING
STATEMENTSTATEMENT
53. USE OF MACRO-TIME LOOPINGUSE OF MACRO-TIME LOOPING
STATEMENTSTATEMENT
54. IMPLEMENTATION-CONDITIONALIMPLEMENTATION-CONDITIONAL
MACRO EXPANSIONMACRO EXPANSION
IF-ELSE-ENDIF structure
◦ The macro processor must maintain a
symbol table
-This table contains the values of all
macro-time variables used.
- Entries in this table are made or
modified when SET statements are
processed.
- This table is used to look up the current
value of a macro-time variable whenever
it is required.
55. IMPLEMENTATION-CONDITIONALIMPLEMENTATION-CONDITIONAL
MACRO EXPANSIONMACRO EXPANSION
When an IF statement is encountered during
the expansion of a macro, the specified
Boolean expression is evaluated.
TRUE
◦The macro processor continues to process
lines from DEFTAB until it encounters the
next ELSE or ENDIF statement.
◦If ELSE is encountered, then skips to END
FALSE
◦The macro processor skips ahead in
DEFTAB until it finds the next ELSE or
ENDIF statement.
56. IMPLEMENTATION-CONDITIONALIMPLEMENTATION-CONDITIONAL
MACRO EXPANSIONMACRO EXPANSION
When an IF statement is encountered during
the expansion of a macro, the specified
Boolean expression is evaluated.
-TRUE
The macro processor continues to process
lines from DEFTAB until it encounters the
next ENDW statement.
When ENDW is encountered, the macro
processor returns to the preceding WHILE,
re-evaluates the Boolean expression, and
takes action based on the new value.
59. NEXT – AFTER A BREAKNEXT – AFTER A BREAK
Keyword macro parameters
Recursive Macros
Line-by-Line Macros
Integrated Macros
60. USE OF MACRO-TIME LOOPINGUSE OF MACRO-TIME LOOPING
STATEMENTSTATEMENT
61. IMPLEMENTATION-CONDITIONALIMPLEMENTATION-CONDITIONAL
MACRO EXPANSIONMACRO EXPANSION
IF-ELSE-ENDIF structure
◦ The macro processor must maintain a
symbol
◦ table
Entries in this table are made or modified
when SET statements are processed.
This table is used to look up the current
value of a macro-time variable whenever
it is required.
This table contains the values of all
macro-time variables used.
62. IMPLEMENTATION-CONDITIONALIMPLEMENTATION-CONDITIONAL
MACRO EXPANSIONMACRO EXPANSION
When an IF statement is encountered during the
expansion of a macro, the specified Boolean
expression is evaluated.
◦ TRUE
The macro processor continues to process lines
from DEFTAB until it encounters the
next ELSE or ENDIF statement.
If ELSE is encountered, then skips to ENDIF
◦ FALSE
The macro processor skips ahead in DEFTAB
until it finds the next
ELSE or ENDIF statement.
63. IMPLEMENTATION-CONDITIONALIMPLEMENTATION-CONDITIONAL
MACRO EXPANSIONMACRO EXPANSION
WHILE-ENDW structure
◦ When an WHILE statement is encountered during
the expansion of a macro, the specified Boolean
expression is evaluated.
◦ TRUE
-- The macro processor continues to process lines
from DEFTAB until it encounters the next ENDW
statement.
-- When ENDW is encountered, the macro
processor returns to the preceding WHILE, re-
evaluates the Boolean expression, and takes action
based on the new value.
65. KEYWORD MACRO PARAMETERSKEYWORD MACRO PARAMETERS
Keyword macro parameters
◦ Positional parameters and arguments are
associated according to their positions in
the macro prototype and invocation.
◦ If an argument is to be omitted, a null
argument should be used to maintain the
proper order in macro invocation:
◦ Ex: XXX MACRO &P1, &P2, …., &P20,
….
XXX A1, A2,,,,,,,,,,…,,A20,…..
66. KEYWORD MACRO PARAMETERSKEYWORD MACRO PARAMETERS
It is not suitable if a macro has a large
number of parameters, and only a few of
these are given values in a typical
invocation.
67. KEYWORD MACRO PARAMETERSKEYWORD MACRO PARAMETERS
Keyword Parameters
◦ Each argument is written with the
keyword that names the corresponding
parameter.
◦ Argument may appear any order.
◦ Null arguments are no longer required to
be used.
◦ It is easier, less error prone and readable
form to have keyword parameter than
positional parameter.
68. KEYWORD MACRO PARAMETERSKEYWORD MACRO PARAMETERS
Keyword Parameters
◦ Each argument is written with the
keyword that names the corresponding
parameter.
◦ Argument may appear any order.
◦ Null arguments are no longer required to
be used.
◦ It is easier, less error prone and readable
form to have keyword parameter than
positional parameter.
Ex P1=A1, P2=A2, … P20=A20
69. USE OF KEYWORD MACROUSE OF KEYWORD MACRO
PARAMETERSPARAMETERS
70. USE OF KEYWORD PARAMETERS INUSE OF KEYWORD PARAMETERS IN
MACROMACRO
71. USE OF KEYWORD PARAMETERS INUSE OF KEYWORD PARAMETERS IN
MACROMACRO
74. PROBLEM OF RECURSIVE MACROPROBLEM OF RECURSIVE MACRO
PARAMETERSPARAMETERS
Previous Macro Design Doesn’t take care
of recursive macro expansion.
◦ Problems:
When procedure EXPAND is called
recursively the invocation argument in
the ARGTAB will be overwritten.
The boolean variable Expand would set
to false when the inner macro expansion
is completed without having an idea that
the it is part of another outer macro
whose expansion is still not completed.
75. PROBLEM OF RECURSIVE MACROPROBLEM OF RECURSIVE MACRO
PARAMETERSPARAMETERS
Previous Macro Design Doesn’t take care
of recursive macro expansion.
◦ Solutions:
Write the macro processor in a programming
language which automatically takes care of
the recursive calls thus retaining the local
variables.
If written in a language without recursion
support, use a stack to take care of pushing
and popping the local variables and return
addresses thus retaining their values.
76. GENERAL PURPOSE MACROGENERAL PURPOSE MACRO
PROCESSORSPROCESSORS
◦ Macro processor that do not depend on any
particular language, can be used with
variety of languages.
◦ Pros
Programmers do not need not learn any
macro language.
Although its development costs is little
high than those for the language specific
macro processor, but these macros does
not need to be repeated for every
language.
77. GENERAL PURPOSE MACROGENERAL PURPOSE MACRO
PROCESSORSPROCESSORS
◦ Macro processor that do not depend on any
particular language, can be used with variety of
languages.
◦ Cons
Large number of details must be dealt within a
programming language.
Situations in which normal macro parameter
substitution should not occur, e.g., comments.
Facilities for grouping together terms,
expressions, or statements
Tokens, e.g., identifiers, constants, operators,
keywords.
Syntax must be consistent with the programming
language.
78. MACRO PROCESSING WITHINMACRO PROCESSING WITHIN
LANGUAGE TRANSLATORSLANGUAGE TRANSLATORS
◦ Macro processor discussed so far are
preprocessors that
Process macro definitions
Expand macro invocation
Produces an expanded version of the
macro at the place of the call and then use
it by the assembler or the compiler.
◦ Macro processing functions can be
combined with the language translators.
Line-by-line macro processors
Integrated macro processors
79. LINE-BY-LINE MACROLINE-BY-LINE MACRO
PROCESSORSPROCESSORS
◦ Used as sort of input routine the assembler or compiler.
Read source program.
Handle macro definition and expand the invocation.
Pass output lines to the assembler or compiler.
◦ Benefits
Avoid making an extra pass over the source program.
Data structures required by the translators and the macro
processor can be kept same.
Utility subroutines by the translators and the macros can
be kept same.
Scanning input lines, Searching tables.
80. INTEGRATED MACRO PROCESSORSINTEGRATED MACRO PROCESSORS
◦ An integrated macro processor can make
use of any information about the source
program that is extracted by the
language translators
◦ An integrated macro processor can
support macro instructions that depend
upon the context in which they occur.
81. INTEGRATED MACRO PROCESSORSINTEGRATED MACRO PROCESSORS
◦ Definitions and invocations of macros are
handled by a preprocessor, which is
generally not integrated with the rest of the
compiler.
◦ Example
#DEFINE NULL 0
#DEFINE EOF (-1)
#DEFINE EQ ==
#DEFINE ABSDIF (x, y)
{X>Y? X-Y:Y-X}
82. INTEGRATED MACRO PROCESSORSINTEGRATED MACRO PROCESSORS
◦ Parameter substitutions are not
performed within quoted.
◦ #define DISPLAY( EXPR) printf(“
EXPR= %d n”, EXPR)
Example
◦ DISPLAY( I* J+ 1) ==> printf(“ EXPR
= %d n”, I* J+ 1)
83. INTEGRATED MACRO PROCESSORSINTEGRATED MACRO PROCESSORS
◦ Recursive macro definitions or invocations
After a macro is expanded, the macro processor
rescans the text that has been generated, looking
for more macro definitions or invocations.
Macro cannot invoke or define itself recursively.
Example
DISPLAY( ABSDIFF( 3, 8))
SCANS
printf(“ ABSDIFF( 3, 8)” “= %d n”,
ABSDIFF( 3, 8))
RESCANS
printf(“ ABSDIFF( 3, 8)” “= %d n”, ( (3)>( 8) ?
(3) -
(8) : (8)-( 3) ))
84. ANSI C MACRO LANGUAGEANSI C MACRO LANGUAGE
Conditional compilation statements
Example 1
#ifndef BUFFER_ SIZE
#define BUFFER_ SIZE 1024
#endif
Example 2
#define DEBUG 1
:
#if DEBUG == 1
printf(…) /* debugging outout */
#endif