I use KEIL to compile a program.
The program uses the code
asm("NOP");
Unfortunately KEIL compiler does not accept the statement.
The idea is to introduce a delay by using NOP (no operation) assembly code.
What is the actual equivalent of this in C ? Does this vary with the embedded controller that I use?
There's an intrinsic nop
in most compilers, Keil should have this as well - try __nop()
See - https://www.keil.com/support/man/docs/armcc/armcc_chr1359124998347.htm
Intrinsic functions are usually safer than directly adding assembly code for compatibility reasons.
Does this vary with the embedded controller that I use?
Yes. Inline 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. See Is inline asm part of the ANSI C standard? for more information.
For example, for the C51
Keil compiler, the syntax for inline assembly is
...
#pragma asm
NOP
#pragma endasm
...
while for ARM
, the syntax is something like
...
__asm {
NOP
}
...
You will need to check the manual for the actual compiler you are using.
For some of the more common opcodes, some compilers provide so-called intrinsics - these can be called like a C function but essentially insert assembly code, like _nop_ ()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With