I recently started trying to program in FreeBSD x86_64 assembly, following some tutorials and I ended up with such hello world program.
Everything seems to be right, the write syscall, which is 4 is called with the correct arguments, the exit syscall which is 1 is also called with the correct argument in the rdi register. I compile the file using yasm:
Running the file yields this output:
I do not know what I can do about this. I tried using objdump to ensure that the code is right.
Everything looks fine.
Code:
section .data
hello db "Hello, world!", 10
section .text
global _start
_start:
mov rdi, 1
mov rsi, hello
mov rdx, 14
mov rax, 4
syscall
mov rax, 1
mov rdi, 0
syscall
yasm -f elf64 hello.asm -o hello.o
and it compiles without errors. I link the file using ld: ld -o hello hello.o
and there are no errors here either.Running the file yields this output:
Code:
Hello, world!
fish: Job 1, './hello' terminated by signal SIGSEGV (Address boundary error)
Code:
> objdump -d hello.o
hello.o: file format elf64-x86-64
Disassembly of section .text:
0000000000000000 <_start>:
0: 48 c7 c7 01 00 00 00 movq $0x1, %rdi
7: 48 c7 c6 00 00 00 00 movq $0x0, %rsi
e: 48 c7 c2 0e 00 00 00 movq $0xe, %rdx
15: 48 c7 c0 04 00 00 00 movq $0x4, %rax
1c: 0f 05 syscall
1e: 48 c7 c0 01 00 00 00 movq $0x1, %rax
25: 48 c7 c7 00 00 00 00 movq $0x0, %rdi
2c: 0f 05 syscall