1 Chapter 4 Macro Processors. 2 Introduction A macro instruction (abbreviated to macro) is simply a notational convenience for the programmer. A macro.

Презентация:



Advertisements
Похожие презентации
Loader Design Options Linkage Editors Dynamic Linking Bootstrap Loaders.
Advertisements

HPC Pipelining Parallelism is achieved by starting to execute one instruction before the previous one is finished. The simplest kind overlaps the execution.
Data Types in C. A Data Type A data type is –A set of values AND –A set of operations on those values A data type is used to –Identify the type of a variable.
Inner Classes. 2 Simple Uses of Inner Classes Inner classes are classes defined within other classes The class that includes the inner class is called.
In mathematics, the notion of permutation is used with several slightly different meanings, all related to the act of permuting (rearranging) objects.
Operator Overloading Customised behaviour of operators Chapter: 08 Lecture: 26 & 27 Date:
© 2005 Cisco Systems, Inc. All rights reserved. BGP v Route Selection Using Policy Controls Applying Route-Maps as BGP Filters.
2005 Pearson Education, Inc. All rights reserved. 1 Object-Oriented Programming: Interface.
The category of mood. The category of mood is an explicit verbal category expressing the relation of the action denoted by the predicate to reality as.
Knot theory. In topology, knot theory is the study of mathematical knots. While inspired by knots which appear in daily life in shoelaces and rope, a.
Correlation. In statistics, dependence refers to any statistical relationship between two random variables or two sets of data. Correlation refers to.
Unit II Constructor Cont… Destructor Default constructor.
PERT/CPM PROJECT SCHEDULING Allocation of resources. Includes assigning the starting and completion dates to each part (or activity) in such a manner that.
Some ideas of semantic analysis for anaphora resolution Dmitry P. Vetrov Dorodnicyn Computing Centre of RAS.
Charles Kime & Thomas Kaminski © 2008 Pearson Education, Inc. (Hyperlinks are active in View Show mode) Chapter 6 – Selected Design Topics Part 4 – Programmable.
Combination. In mathematics a combination is a way of selecting several things out of a larger group, where (unlike permutations) order does not matter.
Operators and Arithmetic Operations. Operators An operator is a symbol that instructs the code to perform some operations or actions on one or more operands.
Centrifugal force (rotating reference frame). Centrifugal force (from Latin centrum "center" and fugere "to flee") can generally be any force directed.
© 2005 Cisco Systems, Inc. All rights reserved. BGP v Customer-to-Provider Connectivity with BGP Connecting a Multihomed Customer to Multiple Service.
Michael Marchenko. In mathematics, a sequence is an ordered list of objects (or events). Like a set, it contains members (also called elements, or terms),
Транксрипт:

1 Chapter 4 Macro Processors

2 Introduction A macro instruction (abbreviated to macro) is simply a notational convenience for the programmer. A macro represents a commonly used group of statements in the source programming language Expanding a macros –Replace each macro instruction with the corresponding group of source language statements

3 Introduction (Contd) E.g. –On SIC/XE requires a sequence of seven instructions to save the contents of all registers Write one statement like SAVERGS A macro processor is not directly related to the architecture of the computer on which it is to run Macro processors can also be used with high-level programming languages, OS command languages, etc.

4 Basic Macro Processor Functions Macro Processor A program with Macro definitions and Macro invocations A program without Macro definitions Assembler Object program Expanded program

5 Basic Macro Processor Functions Macro Definition –Two new assembler directives MACRO MEND –A pattern or prototype for the macro instruction Macro name and parameters –See figure 4.1

6 Basic Macro Processor Functions Macro invocation –Often referred to as a macro call Need the name of the macro instruction begin invoked and the arguments to be used in expanding the macro Expanded program –Figure 4.2 –No macro instruction definitions –Each macro invocation statement has been expanded into the statements that form the body of the macro, with the arguments from the macro invocation substituted for the parameters in the prototype

7 Basic Macro Processor Functions Macro invocations and subroutine calls are different Note also that the macro instructions have been written so that the body of the macro contains no label –Why?

8 Macro Processor Algorithm and Data Structures It is easy to design a two-pass macro processor –Pass 1: All macro definitions are processed –Pass 2: All macro invocation statements are expanded However, a two-pass macro processor would not arrow the body of one macro instruction to contain definitions of other macros –See Figure 4.3

9 Macro Processor Algorithm and Data Structures Sub-Macro definitions are only processed when an invocation of their Super-Macros are expanded –See Figure 4.3: RDBUFF A one-pass macro processor that can alternate between macro definition and macro expansions able to handle macros like those in Figure 4.3

10 Macro Processor Algorithm and Data Structures Because of the one-pass structure, the definition of a macro must appear in the source program before any statements that invoke that macro Three main data structures involved in an one-pass macro processor –DEFTAB, NAMTAB, ARGTAB

11 Machine-Independent Macro Processor Feature Concatenation of Macro Parameters Generation of Unique Labels Conditional Macro Expansion Keyword Macro Parameters

12 Concatenation of Macro Parameters Most macro processors allow parameters to be concatenated with other character strings –The need of a special catenation operator LDA X&ID1 LDA X&ID –The catenation operator LDA X&ID 1 See figure 4.6

13 Generation of Unique Labels It is in general not possible for the body of a macro instruction to contain labels of the usual kind –Leading to the use of relative addressing at the source statement level Only be acceptable for short jumps Solution: –Allowing the creation of special types of labels within macro instructions –See Figure 4.7

14 Generation of Unique Labels Solution: –Allowing the creation of special types of labels within macro instructions –See Figure 4.7 Labels used within he macro body begin with the special character $ –Programmers are instructed no to use $ in their source programs

15 Conditional Macro Expansion Most macro processors can modify the sequence of statements generated for a macro expansion, depending on the arguments supplied in the macro invocation See Figure 4.7

16 Conditional Macro Expansion Most macro processors can modify the sequence of statements generated for a macro expansion, depending on the arguments supplied in the macro invocation See Figure 4.7 –Macro processor directive IF, ELSE, ENDIF SET –Macro-time variable (set symbol) WHILE-ENDW –See Figure 4.9

17 Keyword Macro Parameters Positional parameters –Parameters and arguments were associated with each other according to their positions in the macro prototype and the macro invocation statement –Consecutive commas is necessary for a null argument GENER,,DIRECT,,,,,,3 –See Figure 4.10

18 Keyword Macro Parameters Keyword parameters –Each argument value is written with a keyword that names the corresponding parameter –A macro may have a large number of parameters, and only a few of these are given values in a typical invocation GENER TYPE=DIRECT, CHANNEL=3

19 Macro Processor Design Options Recursive Macro Expansion –In Figure 4.3, we presented an example of the definition of on macro instruction by another. We have not dealt with the invocation of on macro by another (nested macro invocation) –See Figure 4.11

20 Macro Processor Design Options Recursive Macro ExpansionApplying Algorithm of Fig. 4.5 Problem: –The processing would proceed normally until line 50, which contains a statement invoking RDCHAR –In addition, the argument from the original macro invocation (RDBUFF) would be lost because the values in ARGTAB were overwritten with the arguments from the invocation of RDCHAR Solution: –These problems are not difficult to solve if the macro processor is begin written in a programmin glanguage that allows recursive call

21 General-Purpose Macro Processors Macro processors have been developed for some high-level programming languages These special-purpose macro processors are similar in general function and approach; however, the details differ from language to language

22 General-Purpose Macro Processors The advantages of such a general-purpose approach to macro processing are obvious –The programmer does not need to learn about a different macro facility for each compiler or assembler language, so much of the time and expense involved in training are eliminated –A substantial overall saving in software development cost

23 General-Purpose Macro Processors In spite of the advantages noted, there are still relatively few general-purpose macro processors. Why? 1.In a typical programming language, there are several situations in which normal macro parameter substitution should no occur –E.g. comments should usually be ignored by a macro processor

24 General-Purpose Macro Processors 2.Another difference between programming languages is related to their facilities for grouping together terms, expressions, or statements –E.g. Some languages use keywords such as begin and end for grouping statements. Others use special characters such as { and }.

25 General-Purpose Macro Processors 3.A more general problem involves the okens of the programming language –E.g. identifiers, constants, operators, and keywords –E.g. blanks

26 General-Purpose Macro Processors 4.Another potential problem with general- purpose macro processors involves the syntax used for macro definitions and macro invocation statements. With most special- purpose macro processors, macro invocations are very similar in form to statements in the source programming language