MISRA.ASM.ENCAPSAssembly language is not isolated. MISRA C 2012 Dir 4.3: Assembly language shall be encapsulated and isolatedAssembly language is not isolated. Category: Required Applies to: C90, C99 AmplificationWhere assembly language instructions are used they shall be encapsulated and isolated in:
RationaleFor reasons of efficiency it is sometimes necessary to embed simple assembly language instructions in-line, for example to enable and disable interrupts. If this is necessary, then it is recommended that it be achieved by using macros, or for C99, inline functions. Encapsulating assembly language is beneficial because:
Note: the use of in-line assembly language is an extension to standard C, and therefore violates Rule 1.2. Example#define NOP asm(" NOP") MISRA-C 2004 Rule 2.1 (required): Assembly language shall be encapsulated and isolated[Unspecified 11] Where assembly language instructions are required it is recommended that they be encapsulated and isolated in either (a) assembler functions, (b) C functions or (c) macros. For reasons of efficiency it is sometimes necessary to embed simple assembly language instructions in-line, for example to enable and disable interrupts. If it is necessary to do this for any reason, then it is recommended that it be achieved by using macros. Note that the use of in-line assembly language is an extension to standard C, and therefore also requires a deviation against Rule 1.1. Example#define NOP asm(" NOP") MISRA C++ 2008 Rule 7—4—3 (required): Assembly language shall be encapsulated and isolated.RationaleEnsuring that assembly language code is encapsulated and isolated aids portability. Where assembly language instructions are needed, they shall be encapsulated and isolated in either assembler functions or C++ functions. Examplevoid Delay ( void ) { asm ( "NOP" ); // Compliant } void fn ( void ) { DoSomething ( ); Delay ( ); // Assembler is encapsulated DoSomething ( ); asm ( "NOP" ); // Non-compliant DoSomething ( ); } |