在Mac上编译ARM .s文件

发布于 2025-01-02 20:21:08 字数 324 浏览 4 评论 0原文

我使用的是 Mac Os X,但在编译 .s ARM 汇编文件时遇到问题。 我的 .s 文件是这样的:

mov r0, r1

只是为了看看它是否有效。 但当我这样做时 arm-elf-as my.s 我得到一个 a.out 文件。 我愿意 chmod +x a.out./a.out 但它说 无法执行二进制文件

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

I am on Mac Os X and I am having trouble compiling a .s ARM assembly file.
my .s file is this:

mov r0, r1

just to see if it works.
but when i do
arm-elf-as my.s
i get an
a.out file.
i do
chmod +x a.out
and
./a.out
but it says
cannot execute binary file

this has me confused, because it should be able to execute if i compiled it with arm-elf-as. How do i go about compiling this .s?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

赠意 2025-01-09 20:21:08

你已经组装好了,只是不能在 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 进行编译。

You're assembling it allright, you just can't run it on a Mac since Macs don't have ARM CPUs. If you install Xcode with iOS support, you can compile ARM code:

# 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

You won't be able to run anything, because for that you'll need a runtime system and and ARM CPU. You can use -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.2.sdk or similar to compile for the iPhoneOS for example.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文