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

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

153

 

 

In the previous example, the FLAG_CLR macro is declared to clear any of a number of flag variables. The FLAGS argument specifies a list of arguments that are used by the IRP directive in line 3. The IRP directive repeats the instruction

for each parameter in the FLAGS argument.

The FLAG_CLR macro is invoked in lines 21, 27, and 35. In line 21, only one parameter is passed. In line 27, three parameters are passed, and in line 35, four parameters are passed. The parameter list is enclosed in angle brackets so that it may be referred to as a single macro parameter, FLAGS. The code generated by the macro is found in lines 26, 32–34, and 40–43.

% Operator

The percent character (%) is used to pass the value of an expression to a macro rather than passing the literal expression itself. For example, the following program example shows a macro declaration that requires a numeric value along with macro invocations that use the percent operator to pass the value of an expression to the macro.

 

 

1

OUTPORT

MACRO

N

 

 

 

 

 

 

 

5

 

 

2

 

MOV

A, #N

 

 

 

 

5

 

MOV

P0, A

 

 

 

 

3

 

 

 

 

 

 

4

 

ENDM

 

 

 

 

 

 

6

 

 

 

 

 

 

00FF

7

RESET_SIG

EQU

0FFh

 

 

 

0000

8

CLEAR_SIG

EQU

0

 

 

 

 

9

 

 

 

 

 

 

 

 

10

 

 

 

 

 

 

 

 

11

 

OUTPORT %(RESET_SIG AND NOT 11110000b)

 

0000

740F

12+1

MOV

A, #15

 

 

 

0002

F580

13+1

MOV

P0, A

 

 

 

 

 

14

 

 

 

 

 

 

 

 

15

 

OUTPORT %(CLEAR_SIG OR 11110000b)

 

0004

74F0

16+1

MOV

A, #240

 

 

 

0006

F580

17+1

MOV

P0, A

 

 

 

In this example, the expressions evaluated in lines 11 and 15 could not be passed to the macro because the macro expects a numeric value. Therefore, the expressions must be evaluated before the macro. The percent sign forces Ax51 to generate a numeric value for the expressions. This value is then passed to the macro.

154

Chapter 5. Assembler Macros

 

 

;; Operator

The double semicolon operator is used to signal that the remaining text on the line should not be emitted when the macro is expanded. This operator is typically used to precede comments that do not need to be expanded when the macro is invoked.

Example

REGCLR

MACRO

CNT

 

REGNUM

SET

0

 

 

MOV

A, #0

;; load A with 0

 

REPT

CNT

;; rpt for CNT registers

 

MOV

R&REGNUM, A

;; set R# to 0

REGNUM SET %(REGNUM+1)

ENDM

ENDM

! Operator

The exclamation mark operator is used to indicate that a special character is to be passed literally to a macro. This operator enables you to pass comma and angle bracket characters, that would normally be interpreted as delimiters, to a

5 macro.

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