Viewing disassembly on OSX – Using objdump.

On linux you can use something called objdump. On OSX you need to install binutils. To do that use macports:

sudo port install binutils

For my machine it got installed in:

/opt/local/x86_64-apple-darwin10.8.0/bin/objdump

You can then call it.

/opt/local/x86_64-apple-darwin10.8.0/bin/objdump -M intel -D a.out | grep -A20 main.:

-M puts the disassembly into intel format
-D specifies the file

the pipe to grep prevents looking at the whole listing and the -A20 shows 20 lines following the matched line which is going to be main().

Here is what it outputs:

0000000100000f10 <_main>:
   100000f10:	55                   	push   rbp
   100000f11:	48 89 e5             	mov    rbp,rsp
   100000f14:	48 8d 3d 13 00 00 00 	lea    rdi,[rip+0x13]        # 100000f2e <_puts$stub+0x6>
   100000f1b:	e8 08 00 00 00       	call   100000f28 <_puts$stub>
   100000f20:	c9                   	leave  
   100000f21:	c3                   	ret    

Disassembly of section __TEXT.__symbol_stub1:

0000000100000f22 <_exit$stub>:
   100000f22:	ff 25 10 01 00 00    	jmp    QWORD PTR [rip+0x110]        # 100001038 <_exit$stub>

0000000100000f28 <_puts$stub>:
   100000f28:	ff 25 12 01 00 00    	jmp    QWORD PTR [rip+0x112]        # 100001040 <_puts$stub>

Disassembly of section .cstring:

0000000100000f2e <.cstring>:
   100000f2e:	48                   	rex.W
   100000f2f:	65                   	gs