Upload
akbisoi1
View
244
Download
0
Embed Size (px)
Citation preview
8/12/2019 Ch4 Macro Processors
1/33
4. Macro Processors1
Chapter IV: Macro Processors
Overview: To study the designand implementationof macro
processors.
A macrorepresents a commonly used group ofstatements in the source programming language.
The macro processor replaces each macro instruction
with the corresponding group of source language
statements. (expanding)
8/12/2019 Ch4 Macro Processors
2/33
4. Macro Processors2
Macro definition
Invocation
Expansion (with substitution of parameters)
Basic macro processor functions
8/12/2019 Ch4 Macro Processors
3/33
4. Macro Processors3
Macro definition
Invocation
Expansion (with substitution of parameters)
Basic macro processor functions
8/12/2019 Ch4 Macro Processors
4/33
4. Macro Processors4
Macro definition
Invocation
Expansion (with substitution of parameters)
Basic macro processor functions
8/12/2019 Ch4 Macro Processors
5/33
4. Macro Processors5
8/12/2019 Ch4 Macro Processors
6/33
4. Macro Processors6
Use of macros in a SIC/XE program
8/12/2019 Ch4 Macro Processors
7/33
4. Macro Processors7
Use of macros in a SIC/XE program (cont.)
8/12/2019 Ch4 Macro Processors
8/33
4. Macro Processors8
Program from above with macros expanded
8/12/2019 Ch4 Macro Processors
9/33
4. Macro Processors9
Program from above with macros expanded(cont.)
8/12/2019 Ch4 Macro Processors
10/33
4. Macro Processors10
Discussions
Why does macro statement use JLT *-14?
Allow label?
8/12/2019 Ch4 Macro Processors
11/33
4. Macro Processors11
Macro processor algorithm and data structures
For one-pass macro processor, the definition of a
macro must appear in the source program before
any statements that invoke that macro.
Three important tables are used for the macro
processor: NAMTABDEFTABand
ARGTAB.
8/12/2019 Ch4 Macro Processors
12/33
4. Macro Processors12
Macro processor algorithm and data structures(cont.)
8/12/2019 Ch4 Macro Processors
13/33
4. Macro Processors13
Macro processor algorithmand data structures
8/12/2019 Ch4 Macro Processors
14/33
4. Macro Processors14
Macro processor algorithmand data structures (cont.)
8/12/2019 Ch4 Macro Processors
15/33
4. Macro Processors15
Macro processor algorithmand data structures (cont.)
8/12/2019 Ch4 Macro Processors
16/33
4. Macro Processors16
Machine-Independent Macro Processor Features
---- Concatenation of Macro Parameters
This feature enable a program to generate a seriesof variables named by XA1, XA2, XA3, , etc.and XB1, XB2, XB3, , etc. as well.
The body of the macro definition might contain astatement like
LDA X&ID1
It has some problems!!(solution: concatenation operator)
8/12/2019 Ch4 Macro Processors
17/33
4. Macro Processors17
Machine-Independent Macro Processor Features
---- Concatenation of Macro Parameters (cont.)
8/12/2019 Ch4 Macro Processors
18/33
4. Macro Processors18
Machine-Independent Macro Processor Features
---- Generation of unique labels
In general, the body of a macro instruction thatcontains labels is not possible.
It will cause duplicate definition.
Solution: use relative addressing (e.g., JEQ *03)
Drawback: For short jump, it is acceptable.For longer jump, it is not convenient, error-
prone, and difficult to read .
8/12/2019 Ch4 Macro Processors
19/33
4. Macro Processors19
Machine-Independent Macro Processor Features
---- Generation of unique labels (cont.)
8/12/2019 Ch4 Macro Processors
20/33
8/12/2019 Ch4 Macro Processors
21/33
4. Macro Processors21
Machine-Independent Macro Processor Features
---- Conditional Macro Expansion
For previous examples of macro instructions, thesestatements could be varied by the substitution of
parameters, but the form of the statement, and theorder in which they appeared, were unchanged.
Conditional macro expansion adds greatly to thepower and flexibility of a macro language.
8/12/2019 Ch4 Macro Processors
22/33
8/12/2019 Ch4 Macro Processors
23/33
4. Macro Processors23
Machine-Independent Macro Processor Features
---- Conditional Macro Expansion (cont.)
Ps. &EORCK is a macro-time variable.
8/12/2019 Ch4 Macro Processors
24/33
4. Macro Processors24
Machine-Independent Macro Processor Features
---- Conditional Macro Expansion (cont.)
8/12/2019 Ch4 Macro Processors
25/33
4. Macro Processors25
Machine-Independent Macro Processor Features
---- Conditional Macro Expansion (cont.)
8/12/2019 Ch4 Macro Processors
26/33
4. Macro Processors26
Machine-Independent Macro Processor Features
---- Macro-time looping statements
8/12/2019 Ch4 Macro Processors
27/33
4. Macro Processors27
Machine-Independent Macro Processor Features
---- Macro-time looping statements (cont.)
8/12/2019 Ch4 Macro Processors
28/33
4. Macro Processors28
Machine-Independent Macro Processor Features
---- Keyword Macro Parameters
Positional parametervs. Keyword parameter
GENER , , DIRECT, , , , , , 3.
GENER TYPE=DIRECT, CHANNEL=3.
8/12/2019 Ch4 Macro Processors
29/33
4. Macro Processors29
Machine-Independent Macro Processor Features
---- Keyword Macro Parameters (cont.)
8/12/2019 Ch4 Macro Processors
30/33
8/12/2019 Ch4 Macro Processors
31/33
4. Macro Processors31
Machine-Independent Macro Processor Features
---- Keyword Macro Parameters (cont.)
8/12/2019 Ch4 Macro Processors
32/33
4. Macro Processors32
Macro Processor Design Options
---- Recursive Macro Expansion
The invocation of one macro, which is defined byanother macro instruction.
Using a programming language that allows recursivecallsto write the macro processor.
8/12/2019 Ch4 Macro Processors
33/33
4 Macro Processors33