The document discusses macro processors and macro expansion. Some key points:
- A macro is a shorthand notation that allows a programmer to write a block of code once then invoke it multiple times by calling the macro.
- When a macro is invoked, the macro processor replaces it with the body of statements defined in the macro, substituting any arguments for parameters.
- This expands the code without analyzing the meaning of the statements, in a way that is machine independent.
- The example shows how a macro definition declares parameters with & and how expansion substitutes arguments for parameters in the body when the macro is invoked.
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.
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.
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.
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.
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
These slides contain the concept of Macros. Macros in C Language are very powerful and used mostly to reduce the time and size of a code. It also allows reusing the code
JIMS BCA Curriculum includes Macros in Unit V of Programming Using C Subject.
JIMS provides an updated Curriculum and includes the concepts in depth.
Admission to BCA is Open.
https://www.jimssouthdelhi.com/admission-procedure.html
A microprocessor is an electronic component that is used by a computer to do its work. It is a central processing unit on a single integrated circuit chip containing millions of very small components including transistors, resistors, and diodes that work together.
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...Juraj Vysvader
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I didn't get rich from it but it did have 63K downloads (powered possible tens of thousands of websites).
How to Position Your Globus Data Portal for Success Ten Good PracticesGlobus
Science gateways allow science and engineering communities to access shared data, software, computing services, and instruments. Science gateways have gained a lot of traction in the last twenty years, as evidenced by projects such as the Science Gateways Community Institute (SGCI) and the Center of Excellence on Science Gateways (SGX3) in the US, The Australian Research Data Commons (ARDC) and its platforms in Australia, and the projects around Virtual Research Environments in Europe. A few mature frameworks have evolved with their different strengths and foci and have been taken up by a larger community such as the Globus Data Portal, Hubzero, Tapis, and Galaxy. However, even when gateways are built on successful frameworks, they continue to face the challenges of ongoing maintenance costs and how to meet the ever-expanding needs of the community they serve with enhanced features. It is not uncommon that gateways with compelling use cases are nonetheless unable to get past the prototype phase and become a full production service, or if they do, they don't survive more than a couple of years. While there is no guaranteed pathway to success, it seems likely that for any gateway there is a need for a strong community and/or solid funding streams to create and sustain its success. With over twenty years of examples to draw from, this presentation goes into detail for ten factors common to successful and enduring gateways that effectively serve as best practices for any new or developing gateway.
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
These slides contain the concept of Macros. Macros in C Language are very powerful and used mostly to reduce the time and size of a code. It also allows reusing the code
JIMS BCA Curriculum includes Macros in Unit V of Programming Using C Subject.
JIMS provides an updated Curriculum and includes the concepts in depth.
Admission to BCA is Open.
https://www.jimssouthdelhi.com/admission-procedure.html
A microprocessor is an electronic component that is used by a computer to do its work. It is a central processing unit on a single integrated circuit chip containing millions of very small components including transistors, resistors, and diodes that work together.
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...Juraj Vysvader
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I didn't get rich from it but it did have 63K downloads (powered possible tens of thousands of websites).
How to Position Your Globus Data Portal for Success Ten Good PracticesGlobus
Science gateways allow science and engineering communities to access shared data, software, computing services, and instruments. Science gateways have gained a lot of traction in the last twenty years, as evidenced by projects such as the Science Gateways Community Institute (SGCI) and the Center of Excellence on Science Gateways (SGX3) in the US, The Australian Research Data Commons (ARDC) and its platforms in Australia, and the projects around Virtual Research Environments in Europe. A few mature frameworks have evolved with their different strengths and foci and have been taken up by a larger community such as the Globus Data Portal, Hubzero, Tapis, and Galaxy. However, even when gateways are built on successful frameworks, they continue to face the challenges of ongoing maintenance costs and how to meet the ever-expanding needs of the community they serve with enhanced features. It is not uncommon that gateways with compelling use cases are nonetheless unable to get past the prototype phase and become a full production service, or if they do, they don't survive more than a couple of years. While there is no guaranteed pathway to success, it seems likely that for any gateway there is a need for a strong community and/or solid funding streams to create and sustain its success. With over twenty years of examples to draw from, this presentation goes into detail for ten factors common to successful and enduring gateways that effectively serve as best practices for any new or developing gateway.
top nidhi software solution freedownloadvrstrong314
This presentation emphasizes the importance of data security and legal compliance for Nidhi companies in India. It highlights how online Nidhi software solutions, like Vector Nidhi Software, offer advanced features tailored to these needs. Key aspects include encryption, access controls, and audit trails to ensure data security. The software complies with regulatory guidelines from the MCA and RBI and adheres to Nidhi Rules, 2014. With customizable, user-friendly interfaces and real-time features, these Nidhi software solutions enhance efficiency, support growth, and provide exceptional member services. The presentation concludes with contact information for further inquiries.
Large Language Models and the End of ProgrammingMatt Welsh
Talk by Matt Welsh at Craft Conference 2024 on the impact that Large Language Models will have on the future of software development. In this talk, I discuss the ways in which LLMs will impact the software industry, from replacing human software developers with AI, to replacing conventional software with models that perform reasoning, computation, and problem-solving.
In software engineering, the right architecture is essential for robust, scalable platforms. Wix has undergone a pivotal shift from event sourcing to a CRUD-based model for its microservices. This talk will chart the course of this pivotal journey.
Event sourcing, which records state changes as immutable events, provided robust auditing and "time travel" debugging for Wix Stores' microservices. Despite its benefits, the complexity it introduced in state management slowed development. Wix responded by adopting a simpler, unified CRUD model. This talk will explore the challenges of event sourcing and the advantages of Wix's new "CRUD on steroids" approach, which streamlines API integration and domain event management while preserving data integrity and system resilience.
Participants will gain valuable insights into Wix's strategies for ensuring atomicity in database updates and event production, as well as caching, materialization, and performance optimization techniques within a distributed system.
Join us to discover how Wix has mastered the art of balancing simplicity and extensibility, and learn how the re-adoption of the modest CRUD has turbocharged their development velocity, resilience, and scalability in a high-growth environment.
Accelerate Enterprise Software Engineering with PlatformlessWSO2
Key takeaways:
Challenges of building platforms and the benefits of platformless.
Key principles of platformless, including API-first, cloud-native middleware, platform engineering, and developer experience.
How Choreo enables the platformless experience.
How key concepts like application architecture, domain-driven design, zero trust, and cell-based architecture are inherently a part of Choreo.
Demo of an end-to-end app built and deployed on Choreo.
Experience our free, in-depth three-part Tendenci Platform Corporate Membership Management workshop series! In Session 1 on May 14th, 2024, we began with an Introduction and Setup, mastering the configuration of your Corporate Membership Module settings to establish membership types, applications, and more. Then, on May 16th, 2024, in Session 2, we focused on binding individual members to a Corporate Membership and Corporate Reps, teaching you how to add individual members and assign Corporate Representatives to manage dues, renewals, and associated members. Finally, on May 28th, 2024, in Session 3, we covered questions and concerns, addressing any queries or issues you may have.
For more Tendenci AMS events, check out www.tendenci.com/events
We describe the deployment and use of Globus Compute for remote computation. This content is aimed at researchers who wish to compute on remote resources using a unified programming interface, as well as system administrators who will deploy and operate Globus Compute services on their research computing infrastructure.
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTier1 app
Even though at surface level ‘java.lang.OutOfMemoryError’ appears as one single error; underlyingly there are 9 types of OutOfMemoryError. Each type of OutOfMemoryError has different causes, diagnosis approaches and solutions. This session equips you with the knowledge, tools, and techniques needed to troubleshoot and conquer OutOfMemoryError in all its forms, ensuring smoother, more efficient Java applications.
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisGlobus
JASMIN is the UK’s high-performance data analysis platform for environmental science, operated by STFC on behalf of the UK Natural Environment Research Council (NERC). In addition to its role in hosting the CEDA Archive (NERC’s long-term repository for climate, atmospheric science & Earth observation data in the UK), JASMIN provides a collaborative platform to a community of around 2,000 scientists in the UK and beyond, providing nearly 400 environmental science projects with working space, compute resources and tools to facilitate their work. High-performance data transfer into and out of JASMIN has always been a key feature, with many scientists bringing model outputs from supercomputers elsewhere in the UK, to analyse against observational or other model data in the CEDA Archive. A growing number of JASMIN users are now realising the benefits of using the Globus service to provide reliable and efficient data movement and other tasks in this and other contexts. Further use cases involve long-distance (intercontinental) transfers to and from JASMIN, and collecting results from a mobile atmospheric radar system, pushing data to JASMIN via a lightweight Globus deployment. We provide details of how Globus fits into our current infrastructure, our experience of the recent migration to GCSv5.4, and of our interest in developing use of the wider ecosystem of Globus services for the benefit of our user community.
Quarkus Hidden and Forbidden ExtensionsMax Andersen
Quarkus has a vast extension ecosystem and is known for its subsonic and subatomic feature set. Some of these features are not as well known, and some extensions are less talked about, but that does not make them less interesting - quite the opposite.
Come join this talk to see some tips and tricks for using Quarkus and some of the lesser known features, extensions and development techniques.
Modern design is crucial in today's digital environment, and this is especially true for SharePoint intranets. The design of these digital hubs is critical to user engagement and productivity enhancement. They are the cornerstone of internal collaboration and interaction within enterprises.
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Globus
The Earth System Grid Federation (ESGF) is a global network of data servers that archives and distributes the planet’s largest collection of Earth system model output for thousands of climate and environmental scientists worldwide. Many of these petabyte-scale data archives are located in proximity to large high-performance computing (HPC) or cloud computing resources, but the primary workflow for data users consists of transferring data, and applying computations on a different system. As a part of the ESGF 2.0 US project (funded by the United States Department of Energy Office of Science), we developed pre-defined data workflows, which can be run on-demand, capable of applying many data reduction and data analysis to the large ESGF data archives, transferring only the resultant analysis (ex. visualizations, smaller data files). In this talk, we will showcase a few of these workflows, highlighting how Globus Flows can be used for petabyte-scale climate analysis.
Check out the webinar slides to learn more about how XfilesPro transforms Salesforce document management by leveraging its world-class applications. For more details, please connect with sales@xfilespro.com
If you want to watch the on-demand webinar, please click here: https://www.xfilespro.com/webinars/salesforce-document-management-2-0-smarter-faster-better/
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...informapgpstrackings
Keep tabs on your field staff effortlessly with Informap Technology Centre LLC. Real-time tracking, task assignment, and smart features for efficient management. Request a live demo today!
For more details, visit us : https://informapuae.com/field-staff-tracking/
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar
The European Union Agency for Law Enforcement Cooperation (Europol) has suffered an alleged data breach after a notorious threat actor claimed to have exfiltrated data from its systems. Infamous data leaker IntelBroker posted on the even more infamous BreachForums hacking forum, saying that Europol suffered a data breach this month.
The alleged breach affected Europol agencies CCSE, EC3, Europol Platform for Experts, Law Enforcement Forum, and SIRIUS. Infiltration of these entities can disrupt ongoing investigations and compromise sensitive intelligence shared among international law enforcement agencies.
However, this is neither the first nor the last activity of IntekBroker. We have compiled for you what happened in the last few days. To track such hacker activities on dark web sources like hacker forums, private Telegram channels, and other hidden platforms where cyber threats often originate, you can check SOCRadar’s Dark Web News.
Stay Informed on Threat Actors’ Activity on the Dark Web with SOCRadar!
Multiple Your Crypto Portfolio with the Innovative Features of Advanced Crypt...Hivelance Technology
Cryptocurrency trading bots are computer programs designed to automate buying, selling, and managing cryptocurrency transactions. These bots utilize advanced algorithms and machine learning techniques to analyze market data, identify trading opportunities, and execute trades on behalf of their users. By automating the decision-making process, crypto trading bots can react to market changes faster than human traders
Hivelance, a leading provider of cryptocurrency trading bot development services, stands out as the premier choice for crypto traders and developers. Hivelance boasts a team of seasoned cryptocurrency experts and software engineers who deeply understand the crypto market and the latest trends in automated trading, Hivelance leverages the latest technologies and tools in the industry, including advanced AI and machine learning algorithms, to create highly efficient and adaptable crypto trading bots
Multiple Your Crypto Portfolio with the Innovative Features of Advanced Crypt...
handout6.pdf
1. Chapter 4 Macro Processors
-- Basic Macro Processor Functions
Introduction
„ A macro instruction (macro) 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
instruction with the corresponding group of source
language statements (expanding)
„ Normally, it performs no analysis of the text it handles.
„ It does not concern the meaning of the involved statements during
macro expansion.
„ The design of a macro processor generally is
machine independent!
Basic macro processor functions
„ Two new assembler directives are used in macro
definition
„ MACRO: identify the beginning of a macro definition
„ MEND: identify the end of a macro definition
„ Prototype for the macro
„ Each parameter begins with ‘’
name MACRO parameters
:
body
:
MEND
„ Body: the statements that will be generated as the expansion of the
macro.
Macro expansion
Source
M1 MACRO D1, D2
STA D1
STB D2
MEND
.
M1 DATA1, DATA2
.
M1 DATA4, DATA3
Expanded source
.
.
.
STA DATA1
STB DATA2
.
STA DATA4
STB DATA3
.
2. Example of macro definition
Figure 4.1, pp. 178
!! !
#! $ %$#!$'
(
( #!
(
) !
*+,- ) ! '
.)’$ %’ !%
/0 12 !
- .)’$ %’ ' 3
-
4 /0 1* )
4 ' $#!) ' #!
5 ) ! )! 3'
5 / 12, '#
, ) $' % 3'
,
-
Macro 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.
„ 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
4
Exchange the values of two variables
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?
5
Pass by Reference
void exchange(int *p1, int *p2) {
int temp;
temp = *p1;
*p1 = *p2;
*p2 = temp;
}
main() {
int i=1, j=3;
printf(BEFORE - %d %dn, i, j);
exchange(i, j);
printf(AFTER - %d %dn, i, j);
}
3. ,
12 Lines of Assembly Code
. Subroutine EXCH
EXCH LDA @P1
STA TEMP
LDA @P2
STA @P1
LDA TEMP
STA @P2
RSUB
P1 RESW 1
P2 RESW 1
TEMP RESW 1
MAIN LDA #1
STA I
LDA #3
STA J
. Call a subroutine
LDA #I
STA P1
LDA #J
STA P2
JSUB EXCH
I RESW 1
J RESW 1
END MAIN
Swap 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);
}
6 Lines of Assembly Code
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
Macro 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
„ 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.
5. 4
No label in the 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,
JEQ *+11
JLT *-14
„ It is inconvenient and error-prone.
„ The way of avoiding such error-prone method will be discussed in
Section 4.2.2
5
Two-pass macro processor
„ You may design a two-pass macro processor
„ Pass 1:
„ Process all macro definitions
„ Pass 2:
„ Expand all macro invocation statements
„ 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.
,
Example of recursive macro definition
Figure 4.3, pp.182
„ MACROS (for SIC)
„ Contains the definitions of RDBUFF and WRBUFF
written in SIC instructions.
A ; ;B : C
#! $ %$#!$'
(
( A ; ;B C
(
A; #!C
6#! $!%$#!$'
(
( A ; ;B C
A; 6#!C
(
(
(
- A; C
Example of recursive macro definition
Figure 4.3, pp.182
„ MACROX (for SIC/XE)
„ Contains the definitions of RDBUFF and WRBUFF
written in SIC/XE instructions.
) AD) : C
#! $ %$#!$'
(
( AD)B C
(
A; #!C
6#! $!%$#!$'
(
( AD)B C
(
A; 6#!C
(
(
- A; )C
6. Example of macro definitions
„ 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.
One-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.
Data structures
for one-pass macro 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.
„ 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.
Data structures
7. Algorithm
Procedure GETLINE
If EXPANDING then
get the next line to be processed from DEFTAB
Else
read next line from input file
Procedure DEFINE
Make appropriate entries in
DEFTAB and NAMTAB
Procedure EXPAND
Set up the argument values in ARGTAB
Expand a macro invocation statement (like in
MAIN procedure)
- Iterations of
• GETLINE
• PROCESSLINE
Procedure PROCESSLINE
• DEFINE
• EXPAND
• Output source line
MAIN program
- Iterations of
• GETLINE
• PROCESSLINE
-
Algorithm
Figure 4.5, pp. 184
:=#
E;
)
.‘’
F E :@ GH ;;@
A C
A : H : C
) I.
‘ ’
3
AF=@C
A : H : C
4
Algorithm
Figure 4.5, pp. 185
: #
: H H #
%I2
%J
3
= : @
E9EH @ H
@ #
.‘’
%I.%*
.‘ ’
%I.%–
A : C
AF=@C
#H 9 ;; ;
A C
5
Algorithm
Figure 4.5, pp. 185
)
) 3I.!
@ : ; AH HC #
EH E : B : 3#
F=@ : B : GH ;;@ :
; : ;
3
AF=@C
) 3I.
A) C
3
) 3
G@ : ; #
E9E E 3# H @
AC
;G@ HE@
A3 C
8. ,
Handling nested macro definition
„ 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.
„ 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.
Comparison of Macro Processors 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
„ Two-pass algorithm
„ Pass1: Recognize macro definitions
„ Pass2: Recognize macro calls
„ Nested macro definitions are not allowed