Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > lccwin fails to generate NOPs

Reply
Thread Tools

lccwin fails to generate NOPs

 
 
Edward Rutherford
Guest
Posts: n/a
 
      01-04-2011
Hello

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.

.file "c:\\nop_test.c"
_$M0:
.file "c:\\nop_test.c"
.text
.text
; 1 main()
.type _main,function
_main:
; 2 {
.line 2
; 3 ;
; 4 ;
; 5 ;
; 6 ;
; 7 puts("done");
.line 7
pushl $_$2
call _puts
addl $4,%esp
movl $0,%eax
_$1:
; 8 }
.line 8
ret
_$3:
.size _main,_$3-_main
.globl _main
.extern _puts
.data
_$2:
; "done\x0"
.byte 100,111,110,101,0
 
Reply With Quote
 
 
 
 
Ben Pfaff
Guest
Posts: n/a
 
      01-04-2011
Edward Rutherford <(E-Mail Removed)> 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.


There is no portable way to do that.
--
Ben Pfaff
http://benpfaff.org
 
Reply With Quote
 
 
 
 
glen herrmannsfeldt
Guest
Posts: n/a
 
      01-04-2011
In comp.compilers.lcc Edward Rutherford <(E-Mail Removed)> wrote:

> 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?


The "null statement" exists in many languages as a place to put a
statement label without attaching it to a statement that does
something else. Otherwise, it is also convenient sometimes for
the grammar to allow for it for other reasons. In C, for example,
it is sometimes needed as the statement in a for or while loops.

while(something()) ;

I have never known a compiler, for any language, to generate
assembly NOP for the null statement.

> Here is the C code:


> main()
> {
> ;
> ;
> ;
> ;
> ;
> puts("done");
> }


-- glen
 
Reply With Quote
 
jacob navia
Guest
Posts: n/a
 
      01-04-2011
Le 04/01/11 23:30, Edward Rutherford a écrit :
> Hello
>
> 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");
> }


lccwin generates NO CODE for an empty statement. I do not know where
you got the idea that an empty statement should generate a NOP

That idea is completely wrong, sorry.

BUT THERE IS SOLUTION:

I can develop a special version FOR YOU that will emit a NOP
when you write an empty statemnt.

Please write to
jacob at jacob dot remcomp dot fr

for pricing...

 
Reply With Quote
 
Ben Pfaff
Guest
Posts: n/a
 
      01-04-2011
jacob navia <(E-Mail Removed)> writes:

> Le 04/01/11 23:30, Edward Rutherford a écrit :
>> 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.

>
> I can develop a special version FOR YOU that will emit a NOP
> when you write an empty statemnt.


A special version of lcc-win will not be a portable solution.
--
Ben Pfaff
http://benpfaff.org
 
Reply With Quote
 
jacob navia
Guest
Posts: n/a
 
      01-04-2011
Le 04/01/11 23:50, Ben Pfaff a écrit :
> jacob navia<(E-Mail Removed)> writes:
>
>> Le 04/01/11 23:30, Edward Rutherford a écrit :
>>> 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.

>>
>> I can develop a special version FOR YOU that will emit a NOP
>> when you write an empty statemnt.

>
> A special version of lcc-win will not be a portable solution.


Ahhh c'mon Ben, why screw my business?

Besides it is 100 portable, you can copy it in as many machines as you
like, and if you put it in a USB key, you can carry it around anywhere.

100% PORTABLE!



 
Reply With Quote
 
Edward Rutherford
Guest
Posts: n/a
 
      01-04-2011
Ben Pfaff wrote:
> jacob navia <(E-Mail Removed)> writes:
>
>> Le 04/01/11 23:30, Edward Rutherford a écrit :
>>> 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.

>>
>> I can develop a special version FOR YOU that will emit a NOP when you
>> write an empty statemnt.

>
> A special version of lcc-win will not be a portable solution.


True - perhaps C needs a new nop keyword to be added.

Jacob is obviously joking about "pricing" - this would be a very easy
fix, only a few minutes work, and I would suggest having a compile time
option so that all users of lcc can choose how they want C empty
statements to be translated, in case some of them prefer the old
behaviour.
 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      01-04-2011
Edward Rutherford <(E-Mail Removed)> 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) http://www.velocityreviews.com/forums/(E-Mail Removed) <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"
 
Reply With Quote
 
jacob navia
Guest
Posts: n/a
 
      01-04-2011
Le 04/01/11 23:54, Edward Rutherford a écrit :
> Ben Pfaff wrote:
>> jacob navia<(E-Mail Removed)> writes:
>>
>>> Le 04/01/11 23:30, Edward Rutherford a écrit :
>>>> 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.
>>>
>>> I can develop a special version FOR YOU that will emit a NOP when you
>>> write an empty statemnt.

>>
>> A special version of lcc-win will not be a portable solution.

>
> True - perhaps C needs a new nop keyword to be added.
>


#define __nop__ _asm("nop")

I can't understand why inline asm is not used here...

 
Reply With Quote
 
robertwessel2@yahoo.com
Guest
Posts: n/a
 
      01-04-2011
On Jan 4, 4:54*pm, Edward Rutherford
<(E-Mail Removed)> wrote:
> Ben Pfaff wrote:
> > jacob navia <(E-Mail Removed)> writes:

>
> >> Le 04/01/11 23:30, Edward Rutherford a crit :
> >>> 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.

>
> >> I can develop a special version FOR YOU that will emit a NOP when you
> >> write an empty statemnt.

>
> > A special version of lcc-win will not be a portable solution.

>
> True - perhaps C needs a new nop keyword to be added.
>
> Jacob is obviously joking about "pricing" - this would be a very easy
> fix, only a few minutes work, and I would suggest having a compile time
> option so that all users of lcc can choose how they want C empty
> statements to be translated, in case some of them prefer the old
> behaviour.



Perhaps a __nop intrinsic (which, somewhat bizarrely, has been
implemented on a fair number of compilers), would be a better idea.
(Tongue-sort-of-in-cheek)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
MIDI files in C(lccwin/WIN XP) ravi C Programming 4 08-02-2010 05:44 PM
Failed to generate a user instance of SQL Server. Only an integratedconnection can generate a user instance. Harlan Messinger ASP .Net 2 03-28-2010 06:51 PM
Status of lccwin sandeep C Programming 9 02-08-2010 05:48 PM
How to generate warnings when How generate a warning when int is converted to bool or vice versa? PengYu.UT@gmail.com C++ 3 04-06-2006 11:24 PM
How to generate variable labels for same component within a generate loop Weng Tianxiang VHDL 5 02-16-2006 01:45 PM



Advertisments