Workflow for writing ARM assembly code on the iphone

前端 未结 4 1817
情深已故
情深已故 2021-01-31 12:06

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 w

4条回答
  •  闹比i
    闹比i (楼主)
    2021-01-31 12:34

    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.

提交回复
热议问题