Mac OSX中的x86组装错误

时间:2018-07-13 11:34:47

标签: macos assembly x86 nasm 32-bit

我有以下x86汇编在线教程获得的汇编代码:

section .text
   global _start     ;must be declared for linker (ld)

start:              ;tells linker entry point
   mov  edx,len     ;message length
   mov  ecx,msg     ;message to write
   mov  ebx,1       ;file descriptor (stdout)
   mov  eax,4       ;system call number (sys_write)
   int  0x80        ;call kernel

   mov  eax,1       ;system call number (sys_exit)
   int  0x80        ;call kernel

section .data
msg db 'Hello, world!', 0xa  ;string to be printed
len equ $ - msg     ;length of the string

我将上面的代码保存在文件“ hello.asm”中

现在,当我在终端中编译并链接它时,出现以下错误!

root@mac:~# nasm -f macho hello.asm && gcc -o hello hello.o

ld: warning: ignoring file hello.o, file was built for i386 which is not the architecture being linked (x86_64): hello.o
Undefined symbols for architecture x86_64:
  "_main", referenced from:
     implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

0 个答案:

没有答案