Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Workflow for writing ARM assembly code on the iphone

I would like to begin writing ARM assembler and running it on the iPhone.

This is not with the intent of using in an app to be released to the app store - Basically I would like to solve problems on ProjectEuler using ARM and the iPhone, just for hobby and educational purposes.

How can I go about doing this? I have not been able to come up with a way get a project running using any hand written arm.

like image 402
Joe Cannatti Avatar asked Oct 16 '09 19:10

Joe Cannatti


People also ask

Is ARM assembly a programming language?

Assembly language is a low-level programming language for a computer or other programmable device that is closest to the machine language. It is often specific to a particular computer architecture so there are multiple types of assembly languages.


2 Answers

I haven't been able to find any information about how to write assembly code specifically for the iPhone, but like the other people said here, you can either:

1) write inline asm statements in C/C++/ObjC code, or 2) write standalone assembly functions in a '.s' file and simply add it in your XCode sources, or 3) write standalone assembly functions for an external assembler such as NASM. You write assembly code in a '.s' file and generate a '.o' object file using NASM and link the object file with your project in XCode.

So if you are just trying to write a few assembly instructions then inline assembler would be the easiest way, but if you plan on writing several assembly functions then I'd recommend a standalone assembly file. And if you plan on writing many assembly functions with macros and want cross-platform compatibility, etc, then I'd recommend using NASM to compile your assembly code into an object file. Because I am using the XCode gcc assembler and it is quite lacking compared to NASM. You can get NASM for free at http://www.nasm.us/

Once you have setup your assembler environment, you need to learn how to write ARM Assembly code! Because the iPhone (and many other portable devices and smartphones) use the ARM instruction set. There is a very good but old intro to ARM assembly at http://www.coranac.com/tonc/text/asm.htm.

When it comes to assembly programming, the official instruction set reference manual is usually the main source of information for everything you will write, so you should go to the ARM website and download the ARM and Thumb-2 Quick Reference Card (6 pages long) as well as the 2 full documents for your exact CPU.

For example, the iPhone 3GS and iPhone 4 both have an ARMv7-A Cortex-A8 CPU, so you can download the ARM Architecture Reference Manual ARMv7-A and ARMv7-R Edition (2000 pages long) that tells you exactly which instructions are available and exactly how they work, and the Cortex™-A8 Technical Reference Manual that explains the instruction timing, etc for your specific CPU.

like image 179
Shervin Emami Avatar answered Sep 30 '22 19:09

Shervin Emami


You can use gcc to make asm inlines with __asm__, or just get a gnu as for arm and write code in separate files. You should have no problems with later linking them up to your project, but I'd suggest you to use c/Objective-C code to wrap up your asm stubs, as writing the whole iPhone application in assembler is somewhat hard (you need to be pretty good in ObjC runtime internals).

You might be interested in using custom Makefiles, however Xcode projects should be sufficient for most of the taks too.

like image 38
Farcaller Avatar answered Sep 30 '22 19:09

Farcaller