Compiling ARM .s file on Mac

强颜欢笑 提交于 2019-12-06 06:35:02

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/9150909/compiling-arm-s-file-on-mac

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!