Tagged: assembly Toggle Comment Threads | Keyboard Shortcuts

  • CG 6:50 pm on October 13, 2010 Permalink | Reply
    Tags: assembly, , , linux,   

    Compiling assembly on Linux (Ubuntu on Virtual Box) 

    gcc -S logical.c

    gcc -O1 -S logical.c

    gcc -O2 -S logical.c

    objdump -d logical.o

  • CG 3:39 pm on October 12, 2010 Permalink | Reply
    Tags: assembly, , , , mac os x,   

    Compiling assembly on Snow Leopard 

    Comparing the compiling result with compiling assembly with Leopard (Mac OS X 10.5)

    code in c

    int logical(int x, int y){
       int t1 = x^y;
       int t2 = t1 >> 17;
       int mask = (1<<13)-7;
       int rval = t2 & mask;
       return rval;

    gcc -S logical.c

    gcc -O1 -S logical.c

    gcc -O2 -S logical.c

    dumping object file
    gcc -c logical.c
    otool -tv logical.o

  • CG 12:38 pm on November 20, 2008 Permalink | Reply
    Tags: assembly, ,   

    Compiling with OS X 

    TA-ing this class, I have to explain about compilation system. Later found out that OS X does not support many of the tools that relate to loading, linking and executing programs. More about it here.

    To generate an assembly code from a c program saved as code.c :

    gcc -S code.c

    that will result code.s

    The file code.s looks like:


    Using optimization option

    gcc -O1 -S code.c
    gcc -O2 -S code.c


    to compile and assemble code:

    gcc -c code.c

    will result code.o in binary format

    to dump the object code, instead of

    objdump -d code.o

    i use

    otools -tv code.o


    [this posting is still being updated at any time

    i’m doing many things at the same time right now 🙂 ]

    • kusprasapta 6:03 pm on November 20, 2008 Permalink | Reply

      try to compile the code with several optimization level, such as -O1 or -O2.
      it will produce different assembly code’s instructions.
      you’ll love it 😀

    • CG 6:40 pm on November 20, 2008 Permalink | Reply

      @kusprasapta: i will update the posting right after i try the optimization level 😉

    • tetangga@sebelah.com 9:57 pm on November 20, 2008 Permalink | Reply

      kalau menurut Applied C++: Practical Techniques for Building Better Software
      ini lah cara tunning C++
      1. Measure performance with release builds and not debugging builds.
      2. Compute only those Items that you need.
      3. Compute or fetch items only once.
      4. Use Integer instead floating point when possible.
      5. Know the object being used In time-critical code, especially copy constructor end assignment operators.
      6. Remove all debugging and log-generated code from your time-critical code once It’is fully debugged.
      7. Deliver release versions or your software internally as early as possible.
      8. Avoid excessive operations with heavyweight objects, like the standard library string class. Pre-compute quantities to speed up run-time calculations.
      9. Avoid system calls and heap allocation In time-critical sections of code.
      10. Minimize locks In time-critical sections of code.
      11. Develop an efficient algorithm that works correctly before you start fine tuning your code. Use unit test to ensure that tuning hasn’t broken anything.
      12. Use a profiler to find out where the biggest performance problems are before doing. a lot of small optimizations.

      yang paling penting menurut pengalamanku nomer 11 dan 12. optimization menggunakan compiler tercangih, atau menggunakan tool tercanggih tidak bisa mengalahkan optimization secara manual dengan memperbaiki algoritma (math optimization)

    • CG 2:47 pm on November 21, 2008 Permalink | Reply

      @tetangga sebelah: a very detail explanation. thank you 🙂

    • kusprasapta 4:26 pm on November 21, 2008 Permalink | Reply

      setuju no 11 dan 12 yang paling penting.
      dalam suatu diskusi dengan pak Waskita, pernah dibahas tentang unit test ini.

Compose new post
Next post/Next comment
Previous post/Previous comment
Show/Hide comments
Go to top
Go to login
Show/Hide help
shift + esc