An HLI assembler macro is defined by using the define preprocessor directive.
For example, a macro could be defined to clear the R0 register.
/* The following macro clears R0. */ #define ClearR0 {__asm CLR R0;}
The source code invokes the ClearR0 macro in the following manner.
ClearR0;
And then the preprocessor expands the macro.
{ __asm CLR R0 ; } ;
An HLI assembler macro can contain one or several HLI assembler instructions. As the ANSI-C preprocessor expands a macro on a single line, you cannot define an HLI assembler block in a macro. You can, however, define a list of HLI assembler instructions.
/* The following macro clears R0 and R1. */ #define ClearR0and1 {__asm CLR R0; __asm CLR R1; }
The macro is invoked in the following way in the source code:
ClearR0and1;
The preprocessor expands the macro:
{ __asm CLR R0 ; __asm CLR R1 ; } ;
You can define an HLI assembler macro on several lines using the line separator `\'.
/* The following macro clears R0 and R1. */ #define ClearR0andR1 {__asm CLR R0; \ __asm CLR R1;}
The macro is invoked in the following way in the source code.
ClearR0andR1;
The preprocessor expands the macro.
{__asm CLR R0; __asm CLR R1; };