Top Banner
4. Macro Processors 1 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)
33

4. Macro Processors1 Chapter IV: Macro Processors Overview: r To study the design and implementation of macro processors. r A macro represents a commonly.

Jan 02, 2016

Download

Documents

Joel Griffin
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: 4. Macro Processors1 Chapter IV: Macro Processors Overview: r To study the design and implementation of macro processors. r A macro represents a commonly.

4. Macro Processors1

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)

Page 2: 4. Macro Processors1 Chapter IV: Macro Processors Overview: r To study the design and implementation of macro processors. r A macro represents a commonly.

4. Macro Processors2

Macro definition Invocation Expansion (with substitution of parameters)

Basic macro processor functions

Page 3: 4. Macro Processors1 Chapter IV: Macro Processors Overview: r To study the design and implementation of macro processors. r A macro represents a commonly.

4. Macro Processors3

Macro definition

Invocation Expansion (with substitution of parameters)

Basic macro processor functions

Page 4: 4. Macro Processors1 Chapter IV: Macro Processors Overview: r To study the design and implementation of macro processors. r A macro represents a commonly.

4. Macro Processors4

Macro definition Invocation

Expansion (with substitution of parameters)

Basic macro processor functions

Page 5: 4. Macro Processors1 Chapter IV: Macro Processors Overview: r To study the design and implementation of macro processors. r A macro represents a commonly.

4. Macro Processors5

Page 6: 4. Macro Processors1 Chapter IV: Macro Processors Overview: r To study the design and implementation of macro processors. r A macro represents a commonly.

4. Macro Processors6

Use of macros in a SIC/XE program

Page 7: 4. Macro Processors1 Chapter IV: Macro Processors Overview: r To study the design and implementation of macro processors. r A macro represents a commonly.

4. Macro Processors7

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

Page 8: 4. Macro Processors1 Chapter IV: Macro Processors Overview: r To study the design and implementation of macro processors. r A macro represents a commonly.

4. Macro Processors8

Program from above with macros expanded

Page 9: 4. Macro Processors1 Chapter IV: Macro Processors Overview: r To study the design and implementation of macro processors. r A macro represents a commonly.

4. Macro Processors9

Program from above with macros expanded (cont.)

Page 10: 4. Macro Processors1 Chapter IV: Macro Processors Overview: r To study the design and implementation of macro processors. r A macro represents a commonly.

4. Macro Processors10

Discussions…

Why does macro statement use JLT *-14? Allow label?

Page 11: 4. Macro Processors1 Chapter IV: Macro Processors Overview: r To study the design and implementation of macro processors. r A macro represents a commonly.

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: NAMTAB 、 DEFTAB 、 and ARGTAB.

Page 12: 4. Macro Processors1 Chapter IV: Macro Processors Overview: r To study the design and implementation of macro processors. r A macro represents a commonly.

4. Macro Processors12

Macro processor algorithm and data structures (cont.)

Page 13: 4. Macro Processors1 Chapter IV: Macro Processors Overview: r To study the design and implementation of macro processors. r A macro represents a commonly.

4. Macro Processors13

Macro processor algorithm and data structures

Page 14: 4. Macro Processors1 Chapter IV: Macro Processors Overview: r To study the design and implementation of macro processors. r A macro represents a commonly.

4. Macro Processors14

Macro processor algorithm and data structures (cont.)

Page 15: 4. Macro Processors1 Chapter IV: Macro Processors Overview: r To study the design and implementation of macro processors. r A macro represents a commonly.

4. Macro Processors15

Macro processor algorithm and data structures (cont.)

Page 16: 4. Macro Processors1 Chapter IV: Macro Processors Overview: r To study the design and implementation of macro processors. r A macro represents a commonly.

4. Macro Processors16

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 X&ID1

It has some problems!! (solution: concatenation operator)

Page 17: 4. Macro Processors1 Chapter IV: Macro Processors Overview: r To study the design and implementation of macro processors. r A macro represents a commonly.

4. Macro Processors17

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

Page 18: 4. Macro Processors1 Chapter IV: Macro Processors Overview: r To study the design and implementation of macro processors. r A macro represents a commonly.

4. Macro Processors18

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, error- prone, and difficult to read .

Page 19: 4. Macro Processors1 Chapter IV: Macro Processors Overview: r To study the design and implementation of macro processors. r A macro represents a commonly.

4. Macro Processors19

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

Page 20: 4. Macro Processors1 Chapter IV: Macro Processors Overview: r To study the design and implementation of macro processors. r A macro represents a commonly.

4. Macro Processors20

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

Page 21: 4. Macro Processors1 Chapter IV: Macro Processors Overview: r To study the design and implementation of macro processors. r A macro represents a commonly.

4. Macro Processors21

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.

Page 22: 4. Macro Processors1 Chapter IV: Macro Processors Overview: r To study the design and implementation of macro processors. r A macro represents a commonly.

4. Macro Processors22

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

Page 23: 4. Macro Processors1 Chapter IV: Macro Processors Overview: r To study the design and implementation of macro processors. r A macro represents a commonly.

4. Macro Processors23

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

Ps. &EORCK is a macro-time variable.

Page 24: 4. Macro Processors1 Chapter IV: Macro Processors Overview: r To study the design and implementation of macro processors. r A macro represents a commonly.

4. Macro Processors24

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

Page 25: 4. Macro Processors1 Chapter IV: Macro Processors Overview: r To study the design and implementation of macro processors. r A macro represents a commonly.

4. Macro Processors25

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

Page 26: 4. Macro Processors1 Chapter IV: Macro Processors Overview: r To study the design and implementation of macro processors. r A macro represents a commonly.

4. Macro Processors26

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

Page 27: 4. Macro Processors1 Chapter IV: Macro Processors Overview: r To study the design and implementation of macro processors. r A macro represents a commonly.

4. Macro Processors27

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

Page 28: 4. Macro Processors1 Chapter IV: Macro Processors Overview: r To study the design and implementation of macro processors. r A macro represents a commonly.

4. Macro Processors28

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

Positional parameter vs. Keyword parameter

GENER , , DIRECT, , , , , , 3.

GENER TYPE=DIRECT, CHANNEL=3.

Page 29: 4. Macro Processors1 Chapter IV: Macro Processors Overview: r To study the design and implementation of macro processors. r A macro represents a commonly.

4. Macro Processors29

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

Page 30: 4. Macro Processors1 Chapter IV: Macro Processors Overview: r To study the design and implementation of macro processors. r A macro represents a commonly.

4. Macro Processors30

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

Page 31: 4. Macro Processors1 Chapter IV: Macro Processors Overview: r To study the design and implementation of macro processors. r A macro represents a commonly.

4. Macro Processors31

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

Page 32: 4. Macro Processors1 Chapter IV: Macro Processors Overview: r To study the design and implementation of macro processors. r A macro represents a commonly.

4. Macro Processors32

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.

Page 33: 4. Macro Processors1 Chapter IV: Macro Processors Overview: r To study the design and implementation of macro processors. r A macro represents a commonly.

4. Macro Processors33