Use the define preprocessor directive to define an HLI assembler macro.
The following listing defines a macro that clears 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;
Then the preprocessor expands the ClearR0 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 (refer the following listing).
/* The following macro clears R0 and R1. */ #define ClearR0and1 {__asm CLR R0; __asm CLR R1; }
The source code invokes this macro in the following way:
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 source code invokes the macro in the following way:
ClearR0andR1;
The preprocessor expands the ClearR0andR1 macro:
{__asm CLR R0; __asm CLR R1; };