10
Chapter 5 Macros and Macro Preprocessors

Chapter 5

Embed Size (px)

DESCRIPTION

Chapter 5. Macros and Macro Preprocessors. Other facilities for Expansion Time Loops. The REPT statement: REPT MACROCONST10 LCL&M &MSET1 REPT10 DC‘&M’ &MSET&M+1 ENDM MEND. The IRP statement: IRP < formal parameter >, < argument-list > - PowerPoint PPT Presentation

Citation preview

Page 1: Chapter 5

Chapter 5

Macros and Macro Preprocessors

Page 2: Chapter 5

Other facilities for Expansion Time Loops

• The REPT statement:REPT <expression>

MACRO CONST10

LCL &M

&M SET 1

REPT 10

DC ‘&M’

&M SET &M+1

ENDM

MEND

Page 3: Chapter 5

• The IRP statement:IRP <formal parameter>, <argument-list>

MACROCONSTS &M, &N, &ZIRP &Z, &M, 7, &NDC ‘&Z’ENDMMEND

Page 4: Chapter 5

Design of a Macro Preprocessor

• The macro preprocessor accepts an assembly program containing definitions and calls and translates it into an assembly program which calls and translates it into an assembly program which does not contain any macro definitions or calls.

• A macro assembler is an assembler that performs macro expansion as well as assembly.

• A macro preprocessor segregates macro expansion from the process of program assembly.

• A macro preprocessor is economical as it uses an existing assembler but a macro assembler is more efficient as it performs macro expansion as well as assembly.

Page 5: Chapter 5

A schematic of a macro preprocessor

Program with macro definitions and calls

TargetProgram

Macro Pre-processor

Assembler

Page 6: Chapter 5

Design Overview• Identify the macro calls in the program.

• Determine the values of formal parameters.

• Maintain the values of expansion time variables declared in the macro.

• Organize expansion time control flow.

• Determine the values of sequencing symbols.

• Perform expansion of a model statement.

The following 4 step procedure is followed to arrive at a design specification for each task:

• Identify the information necessary to perform a task.

• Design a suitable data structure to record the information.

• Determine the processing necessary to obtain the information.

• Determine the processing necessary to perform the task.

Page 7: Chapter 5

Task DS used Description

Identify macro calls

MNT Designed to hold the names of all macros defined in the program

Values of formal parameters

APT

PDT

Actual Parameter Table

<formal parameter name>,<value>

Parameter Default Table

<formal parameter name>,<default value>

Maintain expansion time variables

EVT Expansion time variables’ table

<EV name>,<value>

Organize expansion time control flow

MDT Macro definition table

Page 8: Chapter 5

Determine values of sequencing symbols

SST (Sequencing Symbols Table)

<sequencing symbols name>, <MDT entry #>

Performing expansion of model statement

MEC points to MDT

EV from APT, EVT

SS from SST

Lexical substitution takes place

Page 9: Chapter 5

Data Structures

Table Fields in each entry

Macro name table (MNT) Macro name, no. of positional parameters (#PP), no. of keyword parameters (#KP), no. of expansion time variables (#EV), MDT pointer (MDTP), KPDTAB pointer (KPDTP), SSTAB pointer (SSTP)

Parameter Name Table (PNTAB) Parameter name

EV Name Table (EVNTAB) EV name

SS Name Table (SSNTAB) SS name

Keyword Parameter Default Table (KPDTAB)

parameter name, default value

Page 10: Chapter 5

Contd.

Table Fields in each entry

Macro Definition Table (MDT) Label, Opcode, Operands

Actual Parameter Table (APT) Value

EV Table (EVTAB) Value

SS Table (SSTAB) MDT entry #