assembly/C

This is a discussion on assembly/C within the C Programming forums, part of the General Programming Boards category; Since C generates assembly code, would you get a higher performance by writing the code in assembly instead of C? ...

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

    assembly/C

    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
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    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.

    --
    Mats
    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
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,454
    Moreover - using profiler and some optimizing technincs - you can actually optimize the assembler output of your compiler still writing code in C
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  4. #4
    Ugly C Lover audinue's Avatar
    Join Date
    Jun 2008
    Location
    Indonesia
    Posts
    489
    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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21