Skip to content

Instantly share code, notes, and snippets.

@hyunjun
Last active August 29, 2015 14:27
Show Gist options
  • Save hyunjun/693e04c3fec40094cef9 to your computer and use it in GitHub Desktop.
Save hyunjun/693e04c3fec40094cef9 to your computer and use it in GitHub Desktop.
from c to asm using (g)objdump
  • execution

    $ gcc -g -c if_else.c
    $ gcc -g -c switch.c
    
    $ objdump -d -M intel -S if_else.o > if_else.asm  # Linux
    $ objdump -d -M intel -S switch.o > switch.asm
    
    $ gobjdump -d -M intel -S if_else.o > if_else.asm # OS X
    $ gobjdump -d -M intel -S switch.o > switch.asm
    
  • installation

    $ brew install binutils # OS X
    ==> Downloading https://homebrew.bintray.com/bottles/binutils-2.25.yosemite.bottle.tar.gz
    ######################################################################## 100.0%
    ==> Pouring binutils-2.25.yosemite.bottle.tar.gz
    🍺  /usr/local/Cellar/binutils/2.25: 107 files, 140M
    
#include <stdio.h>
int main(int argc, char* argv[]) {
int i, cnt = 0;
for ( i = 0; i < 100000000; ++i ) {
int j = i % 3;
if ( j == 0 ) {
} else if ( j == 1 ) {
cnt += 1;
} else {
cnt += 1;
}
}
return 0;
}
#include <stdio.h>
int main(int argc, char* argv[]) {
int i, cnt = 0;
for ( i = 0; i < 100000000; ++i ) {
int j = i % 3;
switch ( j ) {
case 0:
break;
case 1:
cnt += 1;
break;
default:
cnt += 1;
break;
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment