Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
74
Добавлен:
14.04.2015
Размер:
2.03 Mб
Скачать

170

Chapter 6. Macro Processing Language

 

 

Macro Processor Language Functions

The MPL processor has several predefined macro processor functions. These MPL processor functions perform many useful operations that would be difficult or impossible to produce in a user-defined macro. An important difference between a user-defined macro and a MPL processor function is that user-defined macros may be redefined, while MPL processor functions can not be redefined.

We have already seen one of these MPL processor functions, DEFINE. DEFINE creates user defined macros. MPL processor functions are already defined when the MPL processor is started.

Comment Function

The MPL processing language can be very subtle, and the operation of macros written in a straightforward manner may not be immediately obvious. Therefore, it is often necessary to comment macro definitions. The comment function has the following syntax:

%'text'

%'text end-of-line

The comment function always evaluates to the null string. Two terminating characters are recognized, the apostrophe and the end-of-line character. The second form allows you to spread macro definitions over several lines while

6 avoiding unwanted end-of-lines in the return value. In either form, the text or comment is not evaluated for macro calls.

Example

%'this is macro comment.'

; this is an assembler comment.

%'the complete line including

end-of-line is a comment

Source text before MPL processing

MOV

R5,

R15

%'the following line will be kept separate'

MOV

R1,

 

%'this comment eats the newline character

R12

 

 

 

Output text from MPL processor

MOV

R5,

R15

MOV

R1,

R12

Keil Software — A51/AX51/A251 Macro Assembler and Utilities

171

 

 

Escape Function

Sometimes it is required to prevent the MPL processor from processing macro text. Two MPL processor functions perform this operation:

escape function

bracket function

The escape function interrupts scanning of macro text. The syntax of the escape function is:

%n text-n-characters-long

The metacharacter followed by a single decimal digit specifies the number of characters (maximum is 9) that are not evaluated. The escape function is useful for inserting a metacharacter (normally the % character), a comma, or a parenthesis.

Example

10%1% OF

10 = 1;

expands

to:

10% OF

10 = 1;

ASM%0251

 

expands

to:

ASM251

 

6

172

Chapter 6. Macro Processing Language

 

 

Bracket Function

The other MPL processor function that inhibits the processing of macro text is the bracket function. The syntax of the bracket function is:

%(balanced-text)

The bracket function disables all MPL processing of the text contained within the parentheses. However, the escape function, the comment function, and parameter substitution are still recognized.

Since there is no restriction for the length of the text within the bracket function, it is usually easier to use than the escape function.

Example

ASM%(251)

evaluates

to:

ASM251

%(1,2,3,4,5)

evaluates

to:

1,2,3,4,5

Macro definition of ‘DW’

 

%*DEFINE (DW (LIST, LABEL)) (

 

%LABEL:

DW

%LIST

 

)

 

 

 

Macro call to ‘DW’

 

 

 

%DW (%(120, 121, 122, 123, -1), TABLE)

6

Return value of the macro call to ‘DW’

 

 

 

TABLE:

DW

120, 121, 122, 123, -1

The macro above will add word definitions to the source file. It uses two

parameters: one for the word expression list and one for the label name. Without the bracket function it would not be possible to pass more than one expression in the list, since the first comma would be interpreted as the delimiter separating the actual parameters to the macro. The bracket function used in the macro call prevents the expression list (120, 121, 122, 123, -1) from being evaluated as separate parameters.

Keil Software — A51/AX51/A251 Macro Assembler and Utilities

173

 

 

METACHAR Function

The MPL processor function METACHAR allows the programmer to change the character that will be recognized by the MPL processor as the metacharacter. The use of this function requires extreme care.

The syntax of the METACHAR function is:

%METACHAR (balanced_text)

The first character of the balanced text is taken to be the new value of the metacharacter. The characters @, (, ), *, blank, tab, and identifier-characters are not allowed to be the metacharacter.

Example

%METACHAR (!)

;

change metacharacter to '!'

!(1,2,3,4)

;

bracket function invoked with !

6

Соседние файлы в папке HLP