AMD64汇编语言编译/构建错误

时间:2015-08-29 06:27:26

标签: macos assembly osx-yosemite nasm x86-64

我正在尝试学习汇编语言,并试图做一个基本的“Hello,World”输出。我得到的错误是:

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

我的.asm文件:

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

我在命令提示符中输入的内容:

$ nasm -f elf64 -g -F dwarf hw.asm
$ ld *.o

在命令提示符下执行第二行后,我收到上面的错误。

0 个答案:

没有答案