在Mac上编译ARM .s文件

时间:2012-02-05 16:34:29

标签: macos assembly compilation arm gnu

我在Mac Os X上,我在编译.s ARM程序集文件时遇到问题。 我的.s文件是这样的:

mov r0, r1

只是看它是否有效。 但是当我这样做的时候 arm-elf-as my.s 我得到了 a.out个文件。 我做 chmod +x a.out./a.out 但它说 cannot execute binary file

这让我很困惑,因为如果我用arm-elf-as编译它应该能够执行。我如何编写这个.s?

1 个答案:

答案 0 :(得分:2)

你正好组装它,你不能在Mac上运行它,因为Mac没有ARM CPU。如果您安装支持iOS的Xcode,则可以编译ARM代码:

# the file
$ cat foo.s
    mov r0, r1

# compile with llvm-gcc
$ /Developer/Platforms/iPhoneOS.platform/usr/bin/llvm-gcc-4.2 -arch armv6 -c foo.s

# resulting file is ARM object file
$ file foo.o
foo.o: Mach-O object arm

# and you can disassemble it
$ otool -v -t foo.o
foo.o:
(__TEXT,__text) section
00000000    e1a00001    mov r0, r1

你将无法运行任何东西,因为你需要一个运行时系统和ARM CPU。例如,您可以使用-isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.2.sdk或类似代码来编译iPhoneOS。