|
|||||||||||
|
Technical Support On-Line Manuals C166 User's Guide |
Use in Macro DefinitionsC macros provide a convenient way to insert extended inline assembly code into your C source code. Macros demand extra care because they expand in a single logical line. Follow these rules to create trouble-free macros:
For example:
#define ABLOCK __asm { /* comment */ \
__asm mov R5,#0x10 \
__asm l1: mov rl4,#'}' \
__asm mov R6,R5 \
__asm jnbs R6.2,l1 \
}
The __asm keywords (highlighted in red) seem superfluous. However, they are required because C macros are expanded in a single line. The preprocessor's handling of '#' within macro definitions that begin with the __asm keyword is relaxed (since # is used for immediate values in assembly language). In standard C, an assembly immediate value like #0x10 would cause an error in the preprocessor phase because it violates the C preprocessor rules. The following example demonstrates how to define and use an extended inline assembly block in a macro.
#define ABLOCK __asm { /* comment */ \
__asm mov R5,#0x10 \
__asm l1: mov rl4,#'}' \
__asm mov R6,R5 \
__asm bset R6.3 \
__asm jnbs R6.2,l1 \
}
int i;
void main (void) {
i = 1;
ABLOCK // expand inline assembly macro
i = 2;
}
| ||||||||||
|
|||||||||||
Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.