title: Assembly Syscalls in 64-bit Windows
body: <p>I am on windows 10, with Cygwin installed. I have been using Cygwin for the compilation/assembly of c and assembly programs using Cygwin-installed "gcc" and "nasm". From what I know, nasm has a -f win64 mode, so it can assemble 64-bit programs. Now, for x64 assembly programming on windows, it seems youtube has a lack of tutorials. Most assembly programming tutorials on youtube are either for x64 linux or x32 windows, and I need to be able to print a string to the console on x64 windows, without the use of any external functions such as C's "printf".</p>
  
  <p>StackOverflow links that didn't work for me:</p>
  
  <p><a href="https://stackoverflow.com/questions/10708502/64-bit-windows-assembler">64-bit windows assembler</a></p>
  
  <p>As far as I know, nasm does support 64-bit windows using the -f win64 extension. Also, the answers have nothing to do with how to write an actual program in assembly on x64 bit windows</p>
  
  <p><a href="https://stackoverflow.com/questions/1023593/how-to-write-hello-world-in-assembler-under-windows">How to write hello world in assembler under Windows?</a></p>
  
  <p>All answers that give code give only code for outdated windows versions (32-bit), except one. The one answer that works for 64 bit I tried, but the command to link the object file gave an error for me, that the system could not find the path specified.</p>
  
  <p><a href="https://stackoverflow.com/questions/15145357/windows-x64-assembler">windows x64 assembler?</a></p>
  
  <p>This site does not contain any code, which is what I need. Also, I am trying to write the Hello World program in nasm.</p>
  
  <p><a href="https://stackoverflow.com/questions/6577458/64-bit-assembly-when-to-use-smaller-size-registers">64 bit assembly, when to use smaller size registers</a></p>
  
  <p>The question actually contains code for a hello world program, but when executed under cygwin on windows 10 (my device), I get a segmentation fault.</p>
  
  <p><a href="https://stackoverflow.com/questions/4429398/why-does-windows64-use-a-different-calling-convention-from-all-other-oses-on-x86?noredirect=1&amp;lq=1">Why does Windows64 use a different calling convention from all other OSes on x86-64?</a></p>
  
  <p>I have tried disassembling a C Hello World Program with objdump -d, but this calls printf, a prebuilt C function, and I am trying to avoid using external functions.</p>
  
  <p>I have tried other external functions (such as Messagebox), but they return errors because something does not recognize the functions. Also, I am trying not to use any extern functions if possible, only syscall, sysenter, or interrupts.</p>
  
  <p>CODE:</p>
  
  <p>Attempt #1:</p>
  
  <pre><code>    section .data
      msg db "Hello, World!", 10, 0
      section .text
      mov rax, 1
      mov rdi, 1
      mov rsi, msg
      mov rdx, 14
      syscall
      mov rax, 60
      mov rdi, 0
      syscall
  </code></pre>
  
  <p>Problem: Assembles and links properly, but throws a segmentation fault when run.</p>
  
  <p>Attempt #2:</p>
  
  <pre><code>    section .text
      mov ah, 0eh
      mov al, '!', 0
      mov bh, 0
      mov bl, 0
      int 10h
  </code></pre>
  
  <p>Problem: Does not assemble properly; says "test.asm:3: error: invalid combination of opcode and operands"</p>
  
  <p>Attempt #3:</p>
  
  <pre><code>    section .text
      msg db 'test', 10, 0
      mov rdi, 1
      mov rsi, 1
      mov rdx, msg
      mov rcx, 5
      syscall
      mov rdi, 60
      mov rsi, 0
      syscall
  </code></pre>
  
  <p>Problem: Assembles and links properly, but throws a segmentation fault when run.</p>
  
  <p>Attempt #4:</p>
  
  <pre><code>    section .text
      mov ah, 0eh
      mov al, '!'
      mov bh, 0
      mov bl, 0
      int 10h
  </code></pre>
  
  <p>Problem: Assembles and links properly, but throws a segmentation fault when run.</p>
  
  <p>I just need an example of a hello world assembly program that works on 64-bit Windows 10. 32-bit programs seem to return errors when I run them. If it is not possible to print a string to the console without using external functions, an example of a program that uses external functions and works on 64-bit Windows 10 would be nice.</p>
  
  <p>I heard that syscalls in windows have far different addresses than those in linux.</p>