ASM x86 (64-bit) printing extra bytes in Hello World
06:21 22 Aug 2024

The expected output is Hello World, but the result is something like Hello Worldhi. It's probably an issue with the len variable. I have a little bit of experience with x86_32 and I was shifting towards x86_64, but then got this error in a Hello World.

BITS 64
section .data
    text db "Hello World", 0  ; Add a null byte at the end
    text2 db "hi"
    len equ $-text

section .text
global _start
_start:
    mov rax, 1
    mov rdi, 1
    mov rsi, text
    mov rdx, len
    syscall

    mov rax, 60
    mov rdi, 0
    syscall

Just in case it matters, I am using these commands to make an object file and then linking it:

nasm -f elf64 -o build/main.o src/main.asm

ld -m elf_x86_64 build/main.o -o main
assembly x86-64 64-bit nasm machine-code