I am using compiler related assembly language function asm() in my PIC32 MCU C code. My code is compiled and working fine with just using asm("reset") function in my C code.When checking MISRA compliance I am getting following MISRA error:
function 'asm' undeclared, assumed to return int [MISRA 2012 Rule 17.3, mandatory]asm("reset");
asm("reset");
How can I resolve this MISRA error for this assembly language function? I also tried creating function macro to use it but still getting an error.
function 'asm' undeclared, assumed to return int [MISRA 2012 Rule 17.3, mandatory]ASM_RESET(void);
#define ASM_RESET(void) asm("reset")
ASM_RESET(void);
It looks like PC-Lint isn't recognizing asm
as a keyword. It is treating it as a function which has no prototype. You could try adding +rw(asm)
to the options.
On the other hand, this forum post suggests that the legal way is to define a reset
function in standalone file that includes only assembly, and show the C file a prototype for it.
reset.c:
void reset(void) {
asm("reset");
}
test.c:
#include "reset.h"
...
reset();
asm
is a compiler extension keyword , not a function. Being compiler specific, it is not automatically recognised by your static analysis tool,and your compiler's inline assembly syntax is "function-like", so it applies the function prototyping rule.
You need to configure PC-Lint correctly using a configuration file or command line options that describe the implementation defined behaviour of your compiler. That may include a great many options, but in this case you should use:
-dasm()=
which will cause the analyser to ignore inline assembly code with the function-like syntax asm(...)
Alternatively you can ignore the inline assembler syntax during static analysis by conditionally defining a macro that hides all such directives:
#if defined _lint
#define asm( asmstr )
#endif
This however would hide other deviations from the checker, such as rules about encapsulation and isolation of in-line assembly. For that reason you should not use a macro or inline assembly mixed with C code lines, but rather define a wrapper function:
void reset(void)
{
asm("reset");
}
and place the reset()
function defined above in a separate translation unit and simply omit that source code from the analysis - as if it were library code.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.