Edward Rutherford <> writes:
> I am trying to write code that includes a certain number of NOPs in the
> generated machine code, I would like to do it portably so without using
> inline asm.
>
> On lccwin, even without optimisations, no NOPs are generated. I have
> searched the documentation but there does not seem to be any compiler
> option covering NOP generation. Can anyone help?
>
> Here is the C code:
>
> main()
> {
> ;
> ;
> ;
> ;
> ;
> puts("done");
> }
>
> Here is the generated assembly - as you can see, the 5 NOPs are missing.
[snip]
An empty statement does not specify the generation of any particular
machine instruction.
In fact, *no* C statement specifies the generation of any particular
machine instruction. The job of a compiler is to generate code
that implements the semantics of your C program, not to generate
any particular CPU instructions. (C has been called a "portable
assembler", but it really isn't.)
If you want to generate a particular number of NOP instructions
(I won't ask why), you'll have to use some implementation-specific
method. I think lcc-win supports some sort of non-standard inline
asm; you said you don't want to use inline asm, but that's pretty
much your best option. No portable C solution exists.
Followups redirected.
--
Keith Thompson (The_Other_Keith)
kst- <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"