title: x86 assembly - how to use Windows API _WriteConsole@4 - masm32 syntax
body: <p>In result to my post <strong>Can I use int21h on windows xp to print things?</strong>, I have seen an article about using Windows API's and in this article was a reference to using the _WriteConsole@4 API to print a message to the console. The article is at <a href="http://cs.lmu.edu/~ray/notes/x86assembly/" rel="nofollow noreferrer">http://cs.lmu.edu/~ray/notes/x86assembly/</a>. </p>
  
  <p>Here is my code so far:</p>
  
  <pre><code>.386P
  .model  flat
  extern  _ExitProcess@4:near
  extern  _GetStdHandle@4:near
  extern  _WriteConsoleA@20:near
  public  _go
  
  .data
        msg     byte    'if you get this, it worked.', 10
        handle  dword   ?
        written dword   ?
  .code 
  start:
  _go:    
        push    -11
        call    _GetStdHandle@4
        mov     handle, eax
        push    0
        push    offset written
        push    13
        push    offset msg
        push    handle
        call    _WriteConsoleA@20
        push    0
        call    _ExitProcess@4
  end start
  </code></pre>
  
  <p>I am using this syntax to compile the code:
  ML:</p>
  
  <pre><code>ml (the file is called test.asm) test.asm /c
  </code></pre>
  
  <p>Link:</p>
  
  <pre><code>link test.obj C:\masm32\lib\kernel32.lib /SUBSYSTEM:CONSOLE /entry:go
  </code></pre>
  
  <p>I have gotten it to compile and link, but when I run the .exe that is produced, it does absolutely nothing, not even an error return. The console is just black. Why is this?</p>
  
  <p>Any help would be greatly appreciated. And to the users of this forum, I apologize for bombarding stackoverflow.com every day, it is just that I have very few resources to learn with.</p>
  
  <p>Thanks in advance,</p>
  
  <p>Progrmr</p>