【发布时间】:2014-03-20 19:31:13
【问题描述】:
我有以下文件 hello.asm:
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 ;our dear string
len equ $ - msg ;length of our dear string
在 mac 上,我如何将其转换为 .o 文件。在 linux 上我会这样做
nasm -f elf64 -o hello.o hello.asm
ld -o hello hello.o
那么它可以被调用
./hello
我已经安装了 Xcode 和 MacPorts,谢谢
【问题讨论】:
-
你必须安装 nasm;
port install nasm。之后的过程应该是相似的,尽管 OS X 使用 Mach-O 二进制格式而不是 ELF,所以你需要查找要给-f的参数。 (尽管它可能根本不需要那个开关。) -
@echristopherson 我已经做了 $ sudo port install nasm