title: Cross compile MASM-syntax assembly with mingw on Linux
body: <p>I want to cross compile a Metasploit template (in assembly language) for 64 bit Windows on Kali Linux.</p>
  
  <p>I am trying to compile from assembly to exe.</p>
  
  <p>Here is the code -</p>
  
  <pre><code>; Author: Stephen Fewer (stephen_fewer[at]harmonysecurity[dot]com)
  ; Architecture: x64
  ;
  ; Assemble and link with the following command:
  ; "C:\Program Files\Microsoft Visual Studio 9.0\VC\bin\x86_amd64\ml64" template_x64_windows.asm /link /subsystem:windows /defaultlib:"C:\Program Files\Microsoft SDKs\Windows\v6.0A\Lib\x64\kernel32.lib" /entry:main 
  
  extrn ExitProcess : proc
  extrn VirtualAlloc : proc
  
  .code
  
      main proc 
          sub rsp, 40        ;
          mov r9, 40h        ; 
          mov r8, 3000h      ; 
          mov rdx, 4096      ; 
          xor rcx, rcx       ; 
          call VirtualAlloc  ; lpPayload = VirtualAlloc( NULL, 4096, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE );
          mov rcx, 4096      ;
          mov rsi, payload   ;
          mov rdi, rax       ;
          rep movsb          ; memcpy( lpPayload, payload, 4096 );
          call rax           ; lpPayload();
          xor rcx, rcx       ;
          call ExitProcess   ; ExitProcess( 0 );
      main endp
  
      payload proc
          A byte 'PAYLOAD:'
          B db 4096-8 dup ( 0 )
      payload endp
  end
  
  </code></pre>
  
  <p>I am using w64-mingw32, and I can compile 32 bit c files with the command i686-mingw32msvc-gcc xxx, but I am having trouble with compiling 64 bit assembly.</p>
  
  <p>There are so many different options for w64-mingw32, I have tried numerous, all with error messages.  To be honest, I haven't done assembly since I had a Commodore 64.</p>
  
  <p>I tried:</p>
  
  <pre><code>x86_64-w64-mingw32-gcc -c template_x64_windows.asm -o file.o
  </code></pre>
  
  <p>And the error message is -</p>
  
  <pre><code>template_x64_windows.asm: linker input file unused because linking not done
  </code></pre>
  
  <p>I don't even know which option will compile assembly, I have checked online for howt-o's, nothing.</p>