You are on page 1of 33

Chapter IV: Macro Processors

Overview:
To study the design and implementation of macro

processors. A macro represents a commonly used group of statements in the source programming language. The macro processor replaces each macro instruction with the corresponding group of source language statements. (expanding)

4. 1

Macro Processors

Basic macro processor functions


Macro definition
Invocation Expansion (with substitution of parameters)

4. 2

Macro Processors

Basic macro processor functions


Macro definition

Invocation Expansion (with substitution of parameters)

4. 3

Macro Processors

Basic macro processor functions


Macro definition Invocation

Expansion (with substitution of parameters)

4. 4

Macro Processors

4. 5

Macro Processors

Use of macros in a SIC/XE program

4. 6

Macro Processors

Use of macros in a SIC/XE program (cont.)

4. 7

Macro Processors

Program from above with macros expanded

4. 8

Macro Processors

Program from above with macros expanded (cont.)

4. 9

Macro Processors

Discussions
Why does macro statement use JLT *-14?

Allow label?

4.10

Macro Processors

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.

4.11

Macro Processors

Macro processor algorithm and data structures (cont.)

4.12

Macro Processors

Macro processor algorithm and data structures

4.13

Macro Processors

Macro processor algorithm and data structures (cont.)

4.14

Macro Processors

Macro processor algorithm and data structures (cont.)

4.15

Macro Processors

Machine-Independent Macro Processor Features ---- Concatenation of Macro Parameters


This feature enable a program to generate a series

of variables named by XA1, XA2, XA3, , etc. and XB1, XB2, XB3, , etc. as well.

The body of the macro definition might contain a

statement like LDA


It has some problems!!

X&ID1

(solution: concatenation operator)


4.16 Macro Processors

Machine-Independent Macro Processor Features ---- Concatenation of Macro Parameters (cont.)

4.17

Macro Processors

Machine-Independent Macro Processor Features ---- Generation of unique labels


In general, the body of a macro instruction that

contains 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, errorprone, and difficult to read .


4.18 Macro Processors

Machine-Independent Macro Processor Features ---- Generation of unique labels (cont.)

4.19

Macro Processors

Machine-Independent Macro Processor Features ---- Generation of unique labels (cont.)

4.20

Macro Processors

Machine-Independent Macro Processor Features ---- Conditional Macro Expansion


For previous examples of macro instructions, these

statements could be varied by the substitution of parameters, but the form of the statement, and the order in which they appeared, were unchanged.
Conditional macro expansion adds greatly to the

power and flexibility of a macro language.

4.21

Macro Processors

Machine-Independent Macro Processor Features ---- Conditional Macro Expansion (cont.)

4.22

Macro Processors

Machine-Independent Macro Processor Features ---- Conditional Macro Expansion (cont.)

Ps. &EORCK is a macro-time variable.


4.23 Macro Processors

Machine-Independent Macro Processor Features ---- Conditional Macro Expansion (cont.)

4.24

Macro Processors

Machine-Independent Macro Processor Features ---- Conditional Macro Expansion (cont.)

4.25

Macro Processors

Machine-Independent Macro Processor Features ---- Macro-time looping statements

4.26

Macro Processors

Machine-Independent Macro Processor Features ---- Macro-time looping statements (cont.)

4.27

Macro Processors

Machine-Independent Macro Processor Features ---- Keyword Macro Parameters


Positional parameter vs. Keyword parameter

GENER , , DIRECT, , , , , , 3. GENER TYPE=DIRECT, CHANNEL=3.

4.28

Macro Processors

Machine-Independent Macro Processor Features ---- Keyword Macro Parameters (cont.)

4.29

Macro Processors

Machine-Independent Macro Processor Features ---- Keyword Macro Parameters (cont.)

4.30

Macro Processors

Machine-Independent Macro Processor Features ---- Keyword Macro Parameters (cont.)

4.31

Macro Processors

Macro Processor Design Options ---- Recursive Macro Expansion


The invocation of one macro, which is defined by

another macro instruction.


Using a programming language that allows recursive

calls to write the macro processor.

4.32

Macro Processors

4.33

Macro Processors

You might also like