Equivalent to NOP in C for inline?

I use KEIL to compile the program.

The program uses code

ASM ("NOP");

Unfortunately, the KEIL compiler does not accept the instruction.

The idea is to introduce a delay using the NOP build code (no operation).

What is the actual equivalent of this in C? Does it depend on the built-in controller that I use?

+7
c assembly embedded
source share
2 answers

Does it depend on the built-in controller that I use?

Yes. Embedded assembly is not part of the C standard (yet), it varies from compiler to compiler, and sometimes even between different target architectures of the same compiler. For more information, see the Inward Part of the ANSI C ASM Standard .

For example, for the C51 Keil compiler, syntax for inline assembly

 ... #pragma asm NOP #pragma endasm ... 

and for ARM syntax is similar to

 ... __asm { NOP } ... 

You will need to check the manual for the actual compiler that you are using.

For some of the most common opcode, some compilers provide so-called internal functions โ€” they can be called as a C function, but essentially you can insert assembler code like _nop_ () .

+2
source share

Most compilers have a built-in nop , Keil should also have this - try __nop()

See - http://www.keil.com/support/man/docs/armccref/armccref_CJABCDAD.htm

Internal functions are usually safer than directly adding assembly code for compatibility reasons.

+3
source share

All Articles