How to write ARM Assembly code for Android or iPhone or Raspberry Pi

To write Assembly language code for ARM, you can either:

  1. write inline asm statements in C/C++/Objective-C 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. You write Assembly code in a ‘.s’ file and generate a ‘.o’ object file 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 many Assembly functions then I’d recommend a standalone Assembly file for GCC, or an external assembler such as FASMARM.
Once you have setup your assembler environment, you need to learn how to write ARM Assembly code, since iPhones and pretty much all portable devices, smartphones, tablets, smartwatches & Raspberry Pi / Linux dev boards use the same ARM instruction set. Some good intro tutorials to learn ARM Assembly are:

There are also the books ARM System Developer’s Guide and ARM Assembly Language. These are a good way to learn the basics of ARM Assembly from scratch, and then you can target specific features for your device such as NEON or Thumb-2 or multi-core.
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 (700 pages long) that explains the instruction timing, etc for your specific CPU. There is also a recent ARM Cortex-A Programmer’s Guide, containing useful info and comparisons of Cortex-A8, Cortex-A9, Cortex-A5 and Cortex-A15 CPUs.
UPDATE: Note that the Cortex-A5 & Cortex-A7 CPUs in recent ARM devices such as Raspberry Pi 2 and ODROID-C1 all use the ARMv7 instruction set and have CPUs similar to ARM Cortex-A8 or Cortex-A9 CPUs. Whereas the original Raspberry Pi 1 and the original iPhone 1 use an old ARMv6 instruction set and use an old ARM11 CPU, so they are quite different to all modern ARM CPUs.
It is important to understand that many ARM CPU’s include the NEON Advanced SIMD coprocessor (aka NEON or Media Processing Engine), and so if you expect to run operations that can take advantage of SIMD architecture (eg: heavily data parallel tasks), then you should make it a big priority to learn how to use NEON effectively! As mentioned above, the official ARM Architecture Reference Manual and ARM Cortex-A8 Reference Manual are the most important sources of info, but there are other places for quicker info such as:

Continue at:
The text above is owned by the site above referred.
Here is only a small part of the article, for more please follow the link
Also see:

2 Replies to “How to write ARM Assembly code for Android or iPhone or Raspberry Pi”

  1. Hi! I could have sworn I’ve been to this blog before but after reading through some of the post I realized it’s new to me. Anyhow, I’m definitely glad I found it and I’ll be bookmarking and checking back frequently!

Leave a Reply

Your email address will not be published. Required fields are marked *