在 Mac 上编译 ARM .s 文件 [英] Compiling ARM .s file on Mac

查看:26
本文介绍了在 Mac 上编译 ARM .s 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Mac Os X 上编译 .s ARM 程序集文件时遇到问题.我的 .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

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

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

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

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?

推荐答案

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

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

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

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.

这篇关于在 Mac 上编译 ARM .s 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆