Re: Question about MS C code generation

vbdis@aol.com (VBDis)
3 Dec 2003 20:27:43 -0500

          From comp.compilers

Related articles
Question about MS C code generation ruicui@sohu.com (2003-11-21)
Re: Question about MS C code generation joachim.durchholz@web.de (Joachim Durchholz) (2003-12-03)
Re: Question about MS C code generation tmk@netvision.net.il (2003-12-03)
Re: Question about MS C code generation vbdis@aol.com (2003-12-03)
Re: Question about MS C code generation bonzini@gnu.org (2003-12-03)
| List of all articles for this month |

From: vbdis@aol.com (VBDis)
Newsgroups: comp.compilers
Date: 3 Dec 2003 20:27:43 -0500
Organization: AOL Bertelsmann Online GmbH & Co. KG http://www.germany.aol.com
References: 03-11-090
Keywords: C, optimize
Posted-Date: 03 Dec 2003 20:27:43 EST

Im Artikel 03-11-090, ruicui@sohu.com (sugaray) schreibt:


> if(a<0) b=-5;
> else if(a>=0) b=5;
> else b=0;


Obviously this could be rewritten as:


b = (a<0) ? -5 : 5;


>my question is: 1) refer to the comment parts
No comment, for now.


> 2) was it any good, probably for the optimization purpose ?
IMO it was good for proving that every transformation of some given code can
introduce errors.


> 3) what kinda logic style would you prefer ?
A clear one, so that logic and transformation errors can be avoided easily.


> 4) if asked, how would you write this program in assembly ?
Why should one do so? Why this program, and which version? Optimized for size
or speed?


If ever, I would:
Step 1: use an good compiler, possibly for a different langugage.
Step 2: switch on all available optimizations.
Step 3: disassemble the compiler output, if no assembler listing is available.


In no case would I write x86 assembly code myself, even not for money. If you
want to learn writing machine code, then I'd suggest that you choose a
different CPU, perhaps with an emulator. If you want to learn how to write
efficient programs, then read more about algorithms and proof of correctness.
If you want to learn how to efficiently write programs, have a look at software
design and project management. Otherwise you should explain what you really
have in mind.


DoDi


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.