I wrote a small program using NASM and try to run it, but I got an error "Segmentation fault". I use Linux (Debian) and 64-bit processor.
My program:
global _start
section .text
_start: mov eax, 16
add eax, 24
How I assemble and link:
nasm -f elf main.asm
ld -m elf_i386 main.o -o main
./main
Result when run:
Segmentation fault
I also tried assembling and linking this way:
nasm main.asm && sudo chmod +x main
./main
And get this error:
bash: ./main: cannot execute binary file: Exec format error
Why am I getting a segmentation fault? And how can I fix it?