Start here

Home
About Klocwork
What's new
Fixed issues
Release notes
Installation

Reference

C/C++ checkers
Java checkers
C# checkers
MISRA C 2004 checkers
MISRA C++ 2008 checkers
MISRA C 2012 checkers
MISRA C 2012 checkers with Amendment 1
Commands
Metrics
Troubleshooting
Reference

Product components

C/C++ Integration build analysis
Java Integration build analysis
Desktop analysis
Refactoring
Klocwork Static Code Analysis
Klocwork Code Review
Structure101
Tuning
Custom checkers

Coding environments

Visual Studio
Eclipse for C/C++
Eclipse for Java
IntelliJ IDEA
Other

Administration

Project configuration
Build configuration
Administration
Analysis performance
Server performance
Security/permissions
Licensing
Klocwork Static Code Analysis Web API
Klocwork Code Review Web API

Community

View help online
Visit RogueWave.com
Klocwork Support
Rogue Wave Videos

Legal

Legal information

MISRA.ASM.ENCAPS

Assembly language is not isolated.

MISRA C 2012 Dir 4.3: Assembly language shall be encapsulated and isolated

Assembly language is not isolated.

Category: Required

Applies to: C90, C99

Amplification

Where assembly language instructions are used they shall be encapsulated and isolated in:

  • Assembly language functions;
  • C functions (inline functions preferred for C99);
  • C macros.

Rationale

For 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:

  • It improves readability;
  • The name, and documentation, of the encapsulating macro or function makes the intent of the assembly language clear;
  • All uses of assembly language for a given purpose can share the same encapsulation which improves maintainability;
  • The assembly language can easily be substituted for a different target or for purposes of static analysis.

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.

Rationale

Ensuring 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.

Example

void Delay ( void )
{
   asm ( "NOP" ); // Compliant
}
void fn ( void )
{
   DoSomething ( );
   Delay ( ); // Assembler is encapsulated
   DoSomething ( );
   asm ( "NOP" ); // Non-compliant
   DoSomething ( );
}