I am trying to write a simple hello world program in 64-bit assembly and run on Ubuntu 64 bit. The program is as follows :
global _start ; entry point export for ld section .text
_start: ; system call to write message to stdout
mov rax, 1 ; sys_write
mov rdi, 1 ; stdout
mov rsi, mes ; message address
mov rdx, len ; message length
syscall ; exit sys call
mov rax, 60 ; exit call id
mov rdi, 0 ; return success
syscall
section .data
mes: db 'Hello, world!',0x0A ; message
len : equ $-mes
I assembled it using nasm -f elf64 hello64.asm
and tried linking it using ld -o hello64 hello64.o
it gives me following error -
ld: i386:x86-64 architecture of input file `hello64.o' is incompatible with i386 output
I get same error even when using flags --oformat elf64-x86-64 or elf64-little or elf64-big.
can someone help out ?