In the first article in this series on developing for Apple Silicon Macs using assembly language, I built a simple framework AsmAttic to use as the ba

Code in ARM Assembly: Registers explained

submited by
Style Pass
2021-06-16 08:30:02

In the first article in this series on developing for Apple Silicon Macs using assembly language, I built a simple framework AsmAttic to use as the basis for developing ARM assembly language routines. In that, I provided a short and simple demonstration of calling an assembly routine and getting its result. This article starts to explain the mechanics of writing your own routines, by explaining the register architecture of ARM64 processors.

In that first article, I glibly produced a C wrapper of extern double multadd(double, double, double) to call an assembly language routine of _multadd:
STR LR, [SP, #-16]!
FMADD D0, D0, D1, D2
LDR LR, [SP], #16
RET

Stepping through the lines of assembly, that first saves a set of registers, performs the floating point operation I want, restores the registers, and returns. For any of that to make sense, you first need to understand the register architecture of the ARM64 processor.

The processor has three main types of register: general-purpose, floating point (including SIMD) and special. When calling and running routines like this, you’re most concerned with the first two, which are explained in detail in ARM’s Procedure Call Standard (references below), and Apple’s platform-specific document (references).

Leave a Comment