Code in ARM Assembly: Integer arithmetic

submited by
Style Pass
2021-07-13 07:30:03

This article continues looking at ARM64 assembly language using the general-purpose registers. The previous article worked through instructions for moving data around; this looks at integer arithmetic instructions.

Although working with 64-bit Swift integers should be straightforward in terms of registers (X0-X30), other datatypes crop up frequently. As a reminder:

Generally useful abstract registers are XZR, the 64-bit X Zero Register, and WZR, its 32-bit W equivalent, which represent zero.

These use X registers for 64-bit values, and W registers for 32-bit. Generally speaking, you can’t mix registers such as adding two W registers into an X register, although there are composite instructions which can extend a smaller datatype in one register, as explained below.

As you might expect, each of those basic instructions has variants and relatives which form extended families. If you’re doing anything beyond simple arithmetic on values of the same size, it pays to be more familiar with individual instructions.

Leave a Comment