Skip to main content

IAR Embedded Workbench for RH850 3.20.x

Macro processing directives

In this section:
Syntax

_args

ENDM

ENDR

EXITM

LOCAL symbol [,symbol] …

name MACRO [argument] [,argument] …

REPT expr

REPTC formal,actual

REPTI formal,actual [,actual] …

Parameters

actual

Strings to be substituted.

argument

Symbolic argument names.

expr

An expression.

formal

An argument into which each character of actual (REPTC) or each string of actual (REPTI) is substituted.

name

The name of the macro.

symbol

Symbols to be local to the macro.

Description

These directives allow user macros to be defined. For information about the restrictions that apply when using a directive in an expression, see Expression restrictions.

Directive

Description

Expression restrictions

_args

Is set to number of arguments passed to macro.

ENDM

Ends a macro definition.

ENDR

Ends a repeat structure.

EXITM

Exits prematurely from a macro.

LOCAL

Creates symbols local to a macro.

MACRO

Defines a macro.

REPT

Assembles instructions a specified number of times.

No forward references

No external references

Absolute

Fixed

REPTC

Repeats and substitutes characters.

REPTI

Repeats and substitutes text.

Table 127. Macro processing directives  


A macro is a user-defined symbol that represents a block of one or more assembler source lines. Once you have defined a macro, you can use it in your program like an assembler directive or assembler mnemonic.

When the assembler encounters a macro, it looks up the macro’s definition, and inserts the lines that the macro represents as if they were included in the source file at that position.

Macros perform simple text substitution effectively, and you can control what they substitute by supplying parameters to them.

The macro process consists of three distinct phases:

  1. The assembler scans and saves macro definitions. The text between MACRO and ENDM is saved but not syntax checked.

  2. A macro call forces the assembler to invoke the macro processor (expander). The macro expander switches (if not already in a macro) the assembler input stream from a source file to the output from the macro expander. The macro expander takes its input from the requested macro definition.

    The macro expander has no knowledge of assembler symbols since it only deals with text substitutions at source level. Before a line from the called macro definition is handed over to the assembler, the expander scans the line for all occurrences of symbolic macro arguments, and replaces them with their expansion arguments.

  3. The expanded line is then processed as any other assembler source line. The input stream to the assembler continues to be the output from the macro processor, until all lines of the current macro definition have been read.