I am trying to learn assembly language and am trying to do a basic "Hello, World" output. The error I am getting is:
ld: warning: -arch not specified
ld: warning: -macosx_version_min not specified, assuming 10.10
ld: warning: ignoring file hw.o, file was built for unsupported file format
( 0x7F 0x45 0x4C 0x46 0x02 0x01 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 )
which is not the architecture being linked (x86_64): hw.o
Undefined symbols for architecture x86_64:
"start", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for inferred architecture x86_64
My .asm file:
1 section .data
msg db "hello, assembly!"
section .text
global _start
_start:
mov rax, 1 ; rax: temp register; when we call syscall, rax must contain syscall number
; 1 means that we will use sys_write system call
mov rdi, 1 ; rdi: used to pass 1st argument to function
; it will be the first argument of sys_write
mov rsi, msg ; rsi: pointer used to pass 2nd argument to functions
; msg will be second buf argument for sys_write
mov rdx, 13 ; rdx: used to pass 3rd argument to function
; third paramater, length of the string. 3rd argument of sys_write
syscall ; we have all arguments now we call sys_write with syscall
mov rax, 60 ; pass 60 to rax for syscall exit
mov rdi, 0 ; error code, so with 0 are program must exit succesfully
syscall ; execute exit code
What I am entering in the command prompt:
$ nasm -f elf64 -g -F dwarf hw.asm
$ ld *.o
After I execute the second line on the command prompt, I get the error above.