NetBSD-Users archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Help to run assembly code
Hi everyone
I'm learning assembly, but I can't manage to run the linked binary.
It keeps saying "sh: Cannot execute ELF binary ./hello". I even
loaded the compat_linux kernel module. Does anyone know what I'm
forgetting?
------------------------------------------------------------------------
Assembler: NASM version 3.01 compiled on Dec 14 2025(pkg)
Linker: ld(system)
Uname -a output:
NetBSD moncao 10.1 NetBSD 10.1 (GENERIC) #0: Mon Dec 16 13:08:11 UTC
2024
mkrepro%mkrepro.NetBSD.org@localhost:/usr/src/sys/arch/amd64/compile/GENERIC amd64
-------- Assembly Code ---------
; Compile: nasm -f elf64 hello.asm -o hello.o
; Link: ld -o hello hello.o
; Run: ./hello
section .data
msg db 'Hello, NetBSD!', 10
len equ $ - msg
section .text
global _start
_start:
; write syscall
mov rax, 4 ; NetBSD x86-64 syscall number for write
mov rdi, 1 ; file descriptor: stdout
mov rsi, msg ; buffer address
mov rdx, len ; buffer length
syscall
; exit syscall
mov rax, 1 ; NetBSD x86-64 syscall number for exit
mov rdi, 0 ; exit code 0
syscall ; invoke syscall
Best regards,
Isac
Home |
Main Index |
Thread Index |
Old Index