Skip to content
Tutorials Center
My learning

Topics

Lesson 25 of 40 ยท ARM Assembly

x86-64 vs ARM64: Side by Side

Compare x86-64 and ARM64 assembly: CISC vs RISC, instruction length, memory operands, flags, calling conventions and memory ordering, with runnable demos.

You have now seen both major instruction sets of the modern world. x86-64 runs most desktops, laptops and cloud servers built over the last two decades. ARM64 (also called AArch64) runs nearly every phone, Apple's M-series Macs, and a fast-growing share of servers. Both can add numbers, call functions and loop, so a program written in C compiles for either. Underneath, the two make very different design choices, and knowing them helps you read compiler output, debug crashes and understand why the same program can behave differently on each.

This lesson is a guided comparison. We will go through the big ideas (instruction length, memory access, flags, calling conventions, memory ordering), look at the same C function compiled for both, and finish with three runnable stand-ins that make the differences concrete. The real assembly in this lesson is read-only; the TryIts are small JavaScript models.

Two design philosophies

The usual shorthand is CISC versus RISC.

  • x86-64 is CISC (complex instruction set computer). It grew by adding instructions for decades while staying compatible with 1970s and 1980s code. Instructions vary in length, can operate directly on memory, and some do a lot at once.
  • ARM64 is RISC (reduced instruction set computer). It was designed fresh in 2011, with a small regular set of instructions, a fixed width, and a strict split between "work on registers" and "touch memory".

The labels are a simplification. Modern x86 CPUs translate complex instructions into simpler internal operations (micro-ops) before running them, and ARM64 has plenty of rich instructions too. What the labels still describe well is the programmer-visible difference, which is what you see when you read assembly.

Topic x86-64 ARM64
Instruction length 1 to 15 bytes always 4 bytes
General registers 16 (rax to r15) 31 (x0 to x30) plus xzr and sp
Operands usually two (destination is also a source) usually three (add x0, x1, x2)
Memory access many instructions take a memory operand only load and store instructions
Flags most arithmetic sets them set only by adds, subs, cmp and friends
Return address pushed on the stack by call saved in link register x30 by bl
Byte order little-endian little-endian in practice

Instruction length

On ARM64 every instruction is exactly 32 bits. That makes decoding trivial: the CPU always knows where the next instruction starts, and it can decode several in parallel. The price is that large constants do not fit in one instruction. Loading a full 64-bit constant takes up to four (mov followed by three movk).

On x86-64 an instruction can be as short as one byte (ret, push rbp) or as long as 15. Common operations stay compact, which saves memory and instruction cache, but decoding is complicated, because a decoder cannot know where instruction two starts until it has worked out how long instruction one is. Modern x86 cores spend real hardware on that problem.

Let us count bytes for equivalent operations in both sets. The x86-64 sizes below are the standard encodings; ARM64 is always 4.

JS Code size: variable vs fixed length

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Do not read this as "x86 is denser, so it wins". Real programs differ, and ARM64 code is often competitive in size. The point is the shape: variable and compact on one side, uniform and easy to decode on the other.

Memory operands and load/store

On x86-64 you can write add dword ptr [rdi], 5 and the CPU loads, adds and stores in one instruction. On ARM64 the same job needs three:

ASM
; x86-64 (Intel syntax)
add dword ptr [rdi], 5

; ARM64
ldr w1, [x0]
add w1, w1, 5
str w1, [x0]

ARM64 is a load/store architecture: arithmetic works only on registers, and ldr and str (plus a few relatives) are the only way to touch memory. The result is more instructions, but each one is simple, and addressing modes such as pre-index and post-index (covered in ARM Load/Store) update a pointer and access memory in one step. Inside the CPU, the x86 version splits into the same three micro-operations, so the gap in speed is much smaller than the gap in instruction count.

Flags

x86 arithmetic sets the flags almost every time: add, sub, and, inc and the rest all update ZF, SF, CF and OF as a side effect, and a following jcc reads them. ARM64 arithmetic does not touch flags unless you ask. add leaves them alone; adds updates them. cmp x0, x1 is simply subs xzr, x0, x1 (a subtraction whose result is thrown away). Because flags are not clobbered by every instruction, compilers can place a compare early and use its result later, and the CPU has fewer false dependencies between instructions.

There is one famous trap. After a subtraction or compare, the carry flag means opposite things: x86 sets CF when a borrow occurred (the first number was smaller, unsigned), while ARM sets C when no borrow occurred. The conditions are named to match: x86 jb (below) tests CF, and ARM's b.lo (lower) tests that C is clear.

JS Same subtraction, different carry

Press Run (or Ctrl + Enter) to see the console output here.

No output.

The N, Z and V flags mean the same on both. Only the carry polarity is flipped for subtraction, and addition carries mean the same thing on both.

Calling conventions

Both architectures pass the first few arguments in registers and return values in a register, but the register names and counts differ. These are the Linux and macOS (System V and AAPCS64) conventions; see Calling Conventions for the full tables.

x86-64 System V ARM64 AAPCS64
Integer arguments rdi, rsi, rdx, rcx, r8, r9 x0 to x7
Floating-point arguments xmm0 to xmm7 v0 to v7 (d0, s0 views)
Integer return rax (and rdx for 128 bits) x0 (and x1)
Return address on the stack link register x30
Callee-saved rbx, rbp, r12 to r15 x19 to x28 (plus x29 frame pointer)

ARM64 passes more arguments in registers (eight versus six), and because bl stores the return address in x30 instead of memory, a function that calls nothing (a leaf) can return without any stack traffic at all. A function that calls others must first save x30, which is why you often see stp x29, x30, [sp, -16]! in a prologue.

The same function in both

Take this small C function:

C
int scaled(int *a, int i, int k) {
    return a[i] * k + 1;
}

At -O2, a typical GCC compile for each target looks like this (exact instructions can vary with compiler version):

ASM
; x86-64, Intel syntax            ; ARM64
scaled:                           scaled:
  movsx rsi, esi                    ldr  w0, [x0, w1, sxtw 2]
  mov   eax, [rdi+rsi*4]            mul  w0, w0, w2
  imul  eax, edx                    add  w0, w0, 1
  add   eax, 1                      ret
  ret

Read them side by side. Arguments are a in rdi/x0, i in esi/w1 and k in edx/w2. On x86 the index must first be sign-extended (movsx) so it can be used inside a 64-bit address, then one mov loads a[i] using the scaled-index addressing mode. ARM64 folds the sign extension and the scaling into the load itself (sxtw 2 means sign-extend the word and shift left by 2). Both then multiply and add 1, and return the result in the first return register.

Memory ordering

The last big difference is invisible in single-threaded code. When several CPU cores run threads that share memory, the order in which one core's writes become visible to others depends on the architecture's memory model.

  • x86-64 uses a strong model (TSO, total store order). Stores from one core become visible in program order, and loads are not reordered with other loads. Only one reordering is allowed: a later load may pass an earlier store to a different address.
  • ARM64 uses a weaker model. Unless you ask otherwise, the hardware may reorder most combinations of loads and stores to different addresses, as long as a single thread cannot tell.

So code that is subtly wrong (a flag set without proper synchronization) may happen to work on x86 for years and then fail on ARM. Correct code uses the language's atomics. In C and C++, release/acquire operations compile to nothing special on x86 for plain stores and loads, but to stlr and ldar (store-release, load-acquire) or explicit dmb barrier instructions on ARM64.

The classic "message passing" test shows the effect. Thread 1 writes data = 1 then flag = 1. Thread 2 reads flag then data. If thread 2 sees flag == 1, it should see data == 1. The next demo enumerates every interleaving, once with the stores in order and once with them reordered.

JS Message passing, with and without reordering

Press Run (or Ctrl + Enter) to see the console output here.

No output.

With in-order stores the surprising result r1=1 r2=0 never appears. When the flag store may become visible first, it does. On real ARM hardware the reordering can also happen on the reader side, and the fix in both cases is a release store paired with an acquire load.

Where each one lives

x86-64 dominates desktops, gaming PCs and most older cloud fleets, where decades of software and raw single-thread performance matter. ARM64 leads in phones and tablets, Apple Silicon Macs (M-series chips, where macOS translates x86 programs with Rosetta 2 when no native build exists), and cloud servers such as AWS Graviton and Ampere-based machines, which are popular for their power efficiency. Many projects now publish both builds, and a Docker image often comes in amd64 and arm64 variants.

For you as a learner the good news is that the concepts transfer: registers, the stack, calling conventions, flags and addressing exist on both. Once you can read one, the other takes days, not months.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. Which statement about instruction length is correct?

    x86-64 has variable-length encodings up to 15 bytes, while every ARM64 instruction is exactly 32 bits, which keeps decoding simple.
  2. 2. How does ARM64 add 5 to an integer stored in memory?

    ARM64 is a load/store architecture: load into a register, do the arithmetic there, store the result back.
  3. 3. After cmp 3, 5 (3 is smaller), which carry value results?

    x86 sets CF when a borrow occurs; ARM sets C when no borrow occurs, so the polarity is opposite after a subtraction or compare.
  4. 4. Why can code with a missing memory barrier work on x86 but fail on ARM64?

    x86-64's TSO model forbids most reorderings that ARM64's weaker model allows, so the bug stays hidden on x86.
  5. 5. Where does ARM64's bl instruction save the return address?

    bl stores the return address in x30 (the link register). Only functions that call others need to save it on the stack.

Summary

  • x86-64 is CISC-style (variable-length, memory operands, many addressing modes); ARM64 is RISC-style (fixed 4-byte instructions, load/store only, three-operand arithmetic).
  • ARM64 arithmetic leaves flags alone unless the instruction ends in s; x86 arithmetic nearly always sets them.
  • After a subtraction, x86 CF means "borrow" and ARM C means "no borrow".
  • Both pass arguments in registers (six vs eight integer registers) but ARM64 keeps the return address in x30.
  • x86 uses a strong memory model, ARM64 a weaker one, so concurrent code needs proper atomics or barriers.
  • The concepts carry over, so learning one architecture makes the other far easier.

Next: Assemblers, Syntax Flavors and Object Files, where you turn assembly text into real programs.