ARM Instruction Set
ARM Architecture Deep Dive · CPU Architectures track
5 min read
In this module
Fixed-Width Simplicity
x86 instructions range from 1 to 15 bytes. AArch64 instructions are always exactly 32 bits (4 bytes), no exceptions. This fixed width is a defining feature of the RISC approach. The CPU always knows where the next instruction starts: add 4 to the current address. No parsing, no variable-length decoding logic, no ambiguity.
ARM is a load/store architecture. Only two kinds of instructions touch memory: loads (memory → register) and stores (register → memory). Every arithmetic and logic instruction operates on register values exclusively. That's a sharp departure from x86, where a single ADD can pull a memory value straight into a register. The load/store rule simplifies the pipeline and makes instruction timing predictable.
Thumb Mode (AArch32)
The original 32-bit ARM instructions decode beautifully, but they aren't compact. For memory-pinched embedded systems, ARM introduced Thumb mode: a set of 16-bit compressed instructions that handle common operations in half the space.
Thumb-2 went further by interleaving 16-bit and 32-bit instructions, giving you something close to Thumb's code density with something close to full ARM's performance. AArch32 processors can flip between ARM and Thumb mode at runtime.
AArch64 dropped Thumb entirely. Its fixed 32-bit width is considered a fair trade between code density and decode simplicity.
Conditional Execution (AArch32)
One of ARM's most distinctive features in AArch32 is conditional execution. Every instruction includes a 4-bit condition code field. Instead of writing a branch to skip an instruction, you can make the instruction itself conditional:
CMP R0, #0 @ compare R0 with 0ADDNE R1, R1, #1 @ add 1 to R1, but only if R0 was Not Equal to 0This avoids pipeline flushes from short branches. AArch64 replaced pervasive conditional execution with conditional select and conditional compare instructions, which accomplish similar goals with a cleaner encoding.
Common AArch64 Instructions
| Instruction | Purpose |
|---|---|
MOV Xd, Xs | Copy register to register |
ADD Xd, Xn, Xm | Add two registers |
SUB Xd, Xn, Xm | Subtract |
LDR Xd, [Xn] | Load from memory address in Xn |
STR Xs, [Xn] | Store to memory address in Xn |
CMP Xn, Xm | Compare (subtract and set flags) |
B label | Unconditional branch |
BL label | Branch with link (function call, saves return address in X30) |
RET | Return (branch to address in X30) |
AND Xd, Xn, Xm | Bitwise AND |
ORR Xd, Xn, Xm | Bitwise OR |
Notice the three-operand format: ADD X0, X1, X2 means X0 = X1 + X2. Destination separate from sources. Much cleaner than x86's two-operand ADD RAX, RBX, which means RAX = RAX + RBX and destroys one of its inputs in the process. (x86 has partial escapes: LEA can add two registers into a third, and the VEX-encoded AVX instructions are three-operand.)
A few more forms turn up constantly in real disassembly. ADDS and SUBS are the flag-setting versions of ADD and SUB (plain ADD leaves the flags alone; CMP is really SUBS into the zero register). LDP and STP load or store a pair of registers at once, which is how function prologues save X29 and X30. Many data-processing instructions accept a shifted second operand, as in add x2, x0, x1, lsl #3. And because instructions are 32 bits wide, a 64-bit constant is built 16 bits at a time with MOVZ (move and zero the rest) followed by up to three MOVK (move and keep).
Here's how those pieces combine in a real loop. The listing is a tidied version of what GCC produces at -O2 for summing an array (your compiler may lay it out a little differently). Hover over the C to find its instructions, and look at three details:
ldr x3, [x0], #8is a post-index load: it reads from the address inx0, then adds 8 tox0. Loading the element and advancing the pointer is one instruction.- The compiler dropped
ialtogether. It computes an end pointer once (add x2, x0, x1, lsl #3, which isa + n*8) and stops whenx0reaches it. cmpsets the flags andb.nereads them. Nothing else in the loop touches the flags, so the branch sees exactly the comparison just before it.
Summing an array on AArch64
ARMHover over code lines or mapping badges to see correspondences
Instruction Encoding
AArch64 instructions use a regular encoding where the top bits identify the instruction group (data processing, load/store, branch, and so on). The decoder can spot the instruction type from a handful of bits, then route to the right execution unit with minimal logic. x86, by contrast, makes the decoder slog through prefix bytes, opcode bytes, ModR/M, and SIB just to figure out what the instruction even is.
Try It: Translate x86 to AArch64
The runner on this site only executes x86-64, so this one's on paper. Translate each x86-64 snippet into AArch64, using X1 for RBX, X0 for RAX (W0 for EAX) and X2 for RCX. Remember the load/store rule, and count how many instructions each one needs.
1. add [rbx], eax ; 32-bit add straight into memory2. mov rax, [rbx + rcx*8] ; load element rcx of an array of 8-byte values3. cmp rax, rcx jl .Lsmaller ; signed less-thanShow the answer
1. ldr w3, [x1] // load: memory can't be an ADD operand add w3, w3, w0 // operate in registers (any free register will do) str w3, [x1] // store the result back
2. ldr x0, [x1, x2, lsl #3] // still one instruction: base + index shifted left by 3
3. cmp x0, x2 b.lt .LsmallerThe first costs three instructions because x86's read-modify-write has to be split into a load, an add and a store. The second surprises people: AArch64 addressing can scale an index register too, so an array load stays a single instruction. The third maps one to one, with the condition code moving onto the branch as b.lt.