title: How can I run this assembly code on OS X?
body: <p>Starting to learn assembly, I was given some Hello World assembly code created during the class on Linux. I would like to get it to work for 64-bit Mac OS X.</p>
  
  <p><strong>code.asm</strong>:</p>
  
  <pre><code>SECTION .data       
      hola:   db "Hola!",10   
      tam:    equ $-hola      
  
  SECTION .text       
      global main     
  
  main:               
  
      mov edx,tam     
      mov ecx,hola        
      mov ebx,1       
      mov eax,4       
      int 0x80        
  
      mov ebx,0       
      mov eax,1       
      int 0x80        
  </code></pre>
  
  <p>This is what I do:</p>
  
  <pre><code>nasm -f macho32 -o object.o code.asm
  gcc -m32 -o program object.o
  </code></pre>
  
  <p>Which tells me:</p>
  
  <blockquote>
    <p>Undefined symbols for architecture i386:   "_main", referenced from:
          start in crt1.10.6.o ld: symbol(s) not found for architecture i386</p>
  </blockquote>
  
  <p>Searching for this error, I found this question: <a href="https://stackoverflow.com/q/10726434/555690">nasm and gcc: 32 bit linking failed (64 bit Mac OS X)</a></p>
  
  <p>One answer says</p>
  
  <blockquote>
    <p>The problem you're having is that you're creating a 32-bit Linux(ELF)
    object file which isn't compatible with the Mac OS X object format.
    Try switching '-f elf' to '-f macho32'.</p>
  </blockquote>
  
  <p>But I'm definitely using <code>-f macho32</code>. So what would the problem be then?</p>