Thread: assembly/C

  1. #1
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008


    Since C generates assembly code, would you get a higher performance by writing the code in assembly instead of C? Can you give me some general examples when assembly would be more beneficial in terms of speed?

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Farncombe, Surrey, England
    Yes, you can do that, but you really need to be reasoably skiled in assembler programming to achieve BETTER than the compiler. If we look at the example given with a for-loop by andinue(sp?) earlier, I wouldn't be able to improve on what gcc generated with -O2.

    It is also non-portable, harder to write (because one average line of C turns into 2-3 lines of assembler) harder to maintain, and less error checking.

    Many compilers support inline assembler, but you can't compile gcc-inline assembler with MS compiler or vice-versa, so you are tied to a particular compiler vendor.

    All these factors make it so that you really need to think carefully before you start using assembler instead of C.

    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Rishon LeZion, Israel
    Moreover - using profiler and some optimizing technincs - you can actually optimize the assembler output of your compiler still writing code in C
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    David J. Wheeler

  4. #4
    Ugly C Lover audinue's Avatar
    Join Date
    Jun 2008
    Well, is there any AT&T to Intel syntax converter? :P

    Btw, I'm a little bit confusing using AT&T on GCC.

Popular pages Recent additions subscribe to a feed