1

I just started learning assembly ( < 1 week, so please forgive me if this is stupid), but I can't seem to figure out why this code won't produce an output:

section .data
    message db "Hello World!",10
    
section .text
    global _start

_start:
    mov rax,1
    mov rdi,1
    mov rsi,message
    mov rdx,14
    syscall
    mov rax,60
    mov rdi,0
    syscall

I was following this online tutorial, along with a few others, but I can't seem to figure out why there isn't any output. It assembles and links without error (console input is: nasm -f elf64 hello.asm -o hello.o, followed by: ld hello.o -o hello. When ran, it takes a second, and then a new prompt appears).

I am on windows, which was all that I could find online for what the cause might be, but could not find a solution. I have tried using -f win64 followed by link.exe hello.obj /entry:_start /subsystem:console I have also swapped subsystem:console for subsystem:windows just in case, to no avail. I am completely lost, and all help is greatly appreciated. Thank you!

P.S. If being on windows is the problem, is there a good guide online for nasm on windows. (I have tried masm and using as, but keep running into problems with them so I decided to opt for nasm)

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
drachen
  • 11
  • 1
  • Those are Linux system calls. Windows is completely different. You can't follow a Linux tutorial unless you use a VM or WSL (Windows Subsystem for Linux). – Peter Cordes Aug 22 '20 at 23:44
  • What are the windows system calls, or do you know a good tutorial for windows I can follow. Either way, thank you for the help. – drachen Aug 23 '20 at 00:10
  • The actual `syscall` ABI on Windows is undocumented and only intended to be used by the Windows DLLs. See [Make a program using only system-calls not windows dll's](https://stackoverflow.com/q/44721985) for example. What you're supposed to do is call WinAPI functions in the DLLs that the kernel maps into your process whether you want them or not. As I said, look for a Windows NASM tutorial, e.g. [How to write hello world in assembler under Windows?](https://stackoverflow.com/q/1023593) I think has an x64 answer – Peter Cordes Aug 23 '20 at 00:49

1 Answers1

1

A simple explanation: You can't use syscall on Windows. You need to import console writing functions from Windows DLLs and call them.

FlatAssembler
  • 667
  • 7
  • 30
  • 3
    Hypothetically you *could* do direct system calls on Windows, but the [entry points](https://j00ru.vexillium.org/syscalls/nt/64/) keep changing around (even between different builds of the same major version number) – harold Aug 23 '20 at 00:00
  • How do import the functions from dlls and then call them? I found a tutorial that uses global _start extern puts section .text _start: sub rsp, 28h mov rcx, message call puts add rsp, 28h ret message: db 'Hello', 0 as the code, but puts ends up being an unresolved external, I cannot find how to fix it. Is this the proper way to do it, is the code wrong, or am I still doing something wrong. Thank you! – drachen Aug 23 '20 at 00:11