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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With