I'm starting to pock around with assembly for a school project. The project stipulates we have to write in ASM 64 bits.
Here is my code :
global _start
_start:
sub esp, 4
mov [esp], byte 'H'
mov [esp+1], byte 'e'
mov [esp+2], byte 'y'
mov [esp+3], byte '!'
mov eax, 4
mov ebx, 1
mov ecx, esp
mov edx, 4
int 0x80
mov eax, 1
mov ebx, 0
int 0x80
Compiling and linking with this works :
➜ nasm -f elf32 ex3.asm && ld -m elf_i386 ex3.o -o ex3 && ./ex3
Hey!
But compiling with this doesn't :
➜ nasm -f elf64 ex3.asm && ld -m elf_x86_64 ex3.o -o ex3 && ./ex3
[1] 17876 segmentation fault (core dumped) ./ex3
My idea is that I use a 64 bits cpu machine (xubuntu on a VM provided by the school for this project), and the project states it has to be 64bits code, so I should compile with the later flags, but it will only work with the former. What causes the segmentation fault ?
Any idea why my code is not right for 64 bits compilation ?
Cheers !