What's the cause of the increase in unportable assembly code which targets the 64-bit ARM ISA in Apple’s ARM-based computers?

Writing portable ARM64 assembly
Apr 13, 2023
An unfortunate side effect of the rising popularity of Apple’s ARM-based computers is an increase in unportable assembly code which targets the 64-bit ARM ISA. This is because developers are writing these bits of assembly code to speed up their programs when run on Apple’s ARM-based computers, without considering the other 64-bit ARM devices out there, such as SBCs and servers running Linux or BSD.

The good news is that it is very easy to write assembly which targets Apple’s computers as well as the other 64-bit ARM devices running operating systems other than Darwin. It just requires being aware of a few differences between the Mach-O and ELF ABIs, as well as knowing what Apple-specific syntax extensions to avoid. By following the guidance in this blog, you will be able to write assembly code which is portable between Apple’s toolchain, the official ARM assembly toolchain, and the GNU toolchain.
The increase in unportable assembly code targeting the 64-bit ARM ISA in Apple's ARM-based computers is primarily caused by:

* **Focus on Apple's Ecosystem:** Developers are primarily focused on optimizing performance for Apple's ARM-based computers running macOS. This leads to them using Apple-specific assembly instructions and conventions, which are not necessarily compatible with other ARM platforms.
* **Limited Cross-Platform Considerations:** Developers may not be aware of the differences between Apple's ARM64 ABI (Application Binary Interface) and other ARM64 ABIs like the standard ELF (Executable and Linkable Format) ABI. This can lead to code that relies on Apple-specific features and fails to function correctly on other systems.
* **Lack of Portability Awareness:** There might be a lack of awareness or emphasis on writing portable assembly code. Developers may not consider the need to make their code work on various ARM platforms beyond Apple's ecosystem.

The good news is that writing portable ARM64 assembly is achievable. It involves:

* **Understanding ABI Differences:** Developers need to be aware of the differences between Apple's Mach-O ABI and other ARM64 ABIs.
* **Avoiding Apple-Specific Syntax:** Using standard ARM assembly syntax and instructions ensures compatibility with other ARM toolchains.
* **Adopting a Cross-Platform Mindset:** Developers should consider the broader ARM ecosystem and strive to write code that functions correctly on different operating systems and hardware.

By following these guidelines, developers can create ARM64 assembly code that is portable across various platforms, maximizing the reach and reusability of their work. 
