Solved tiny nasm program won't run

I briefly toyed with the x64 code posted here two years ago.
https://forums.freebsd.org/threads/assembly-simple-hello-world.53274/#post-299339

I tried it again today after reading a post by user ahev.

Now I get an error.

$ nasm -f elf64 hello.asm
$ ld hello.o -o hello
$ ./hello
ELF binary type "0" not known.


Here's the code:

Code:
%include    'system.inc'

section    .data
hello    db    'Hello, World!', 0Ah
hbytes    equ    $-hello

section    .text
global    _start
_start:
mov  rdx, dword hbytes
mov rsi, dword hello
mov rdi, 1
mov rax, SYS_write
syscall
push    dword 0
sys.exit

No idea why I'm getting invalid output.
 
Something got broken. nasm is defaulting to the linux style ELF header. Here's the workaround.

brandelf -t freebsd hello

This wan't necessary two years ago.
 
Back
Top