title: Hello world using nasm in windows assembly
body: <p>I'm using <a href="http://sourceforge.net/projects/nasm/" rel="noreferrer">nasm</a> to compile the following assembly. However the code crashes in the console under Windows.</p>
  <blockquote>
  <p>C:\&gt;nasm -f win32 test.asm -o test.o</p>
  <p>C:\&gt;ld test.o -o test.exe</p>
  </blockquote>
  <pre><code>section .data
    msg   db    'Hello world!', 0AH
    len   equ   $-msg
  
  section .text
    global _WinMain@16
  
  _WinMain@16:
    mov   edx, len
    mov   ecx, msg
    mov   ebx, 1
    mov   eax, 4
    int   80h
  
    mov   ebx, 0
    mov   eax, 1
    int   80h
  </code></pre>
  <p>According to this <a href="http://en.kioskea.net/faq/1559-compiling-an-assembly-program-with-nasm" rel="noreferrer">post</a>. The <code>main</code> function is not available under Windows and must be replaced by <code>WinMain</code>.</p>
  <p>So if your entry point is <code>_start</code> or <code>main</code>, it should be changed to <code>_WinMain@16</code> and change the <code>ret</code> at the end of the procedure to <code>ret 16</code>:</p>
  <p>My working example:</p>
  <pre><code>section .text       
   global _WinMain@16       
  
  _WinMain@16:       
   mov eax, 0       
   ret 16 
  </code></pre>