0

I tried to make hello world in nasm, but it's not printing Hello world and I'm currently using window 11 64 bits.

The picture shows it's not printing: https://i.stack.imgur.com/an8jl.png

here's my compile command:

nasm -f win64 main.asm


ld -o main.exe main.obj

here's my asm code:

section .data
    msg db 'Hello, world!', 0xa  ; string to be printed
    len equ $ - msg     ; length of the string

section .text
    global _start

_start:
    mov rax, 1       ; system call number (sys_write)
    mov rdi, 1       ; file descriptor (stdout)
    mov rsi, msg     ; message to write
    mov rdx, len     ; message length
    syscall          ; call kernel

    mov rax, 60      ; system call number (sys_exit)
    xor rdi, rdi     ; exit code 0
    syscall          ; call kernel

I want it to print hello world :V

  • 2
    Windows doesn't support Linux system calls. – Peter Cordes Jul 19 '23 at 15:01
  • Installl [WSL](https://learn.microsoft.com/en-us/windows/wsl/install), open its terminal, change to your project directory and then try `./main.exe`. – vitsoft Jul 19 '23 at 17:01
  • @vitsoft: That will probably only work if that `ld` made an ELF executable from the COFF `win64` `.obj` input file. Or maybe if it's a PE32+ Windows executable, binfmt-misc might transparently run it under WINE, in which case the native Linux system calls might still work. (If the entry point works.) – Peter Cordes Jul 19 '23 at 17:16
  • 1
    @PeterCordes Yes, it works because `ld` in WSL links COFF to ELF Exec. `file main.exe` says `main.exe: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, not stripped`. – vitsoft Jul 19 '23 at 18:45
  • 2
    @vitsoft: You said to run the existing `main.exe` made by whatever `ld` this was. I'd recommend re-running `ld` inside WSL so you're getting GNU Binutils `ld` configured to make ELF executables by default, so an extra step after changing directory to this inside WSL before `./main.exe` – Peter Cordes Jul 19 '23 at 19:43
  • (And more normally, you'd want to build this with `nasm -felf64` to make an ELF `.o` before using `ld`, but yes it should work with Linux `ld` on a `nasm -fwin64` object file.) – Peter Cordes Jul 20 '23 at 02:14

0 Answers0