Skip to main content
CPU Registers, Memory Addressing & Calling Conventions
Lesson 7 of 20

CPU Registers, Memory Addressing & Calling Conventions

Understand how x86-64 and ARM64 CPUs hold data in registers and memory, and trace function arguments and return values across standard calling conventions.

Intermediate 26 min IoT & embedded
Authorised environments only — The techniques described here are used only in training labs and on systems you own or have written permission to test.

Learning objectives

  • Identify general-purpose, instruction-pointer, stack-pointer, and flags registers in x86-64
  • Convert little-endian byte sequences in memory dumps into multi-byte integers
  • Interpret common Intel-syntax memory addressing expressions such as [base + index*scale + disp]
  • Distinguish System V AMD64, Microsoft x64, and AArch64 calling conventions when reading disassembly

#Why this matters

When a compiled binary has no source code or symbol names, a disassembler still shows every instruction the processor executes. To read that output, you must know where the CPU keeps working values and how functions pass arguments. Tracking registers, memory addresses, and stack frames turns an unfamiliar function into clear inputs and logic checks.

#Registers: the CPU's workbench

A CPU register is a small, fast storage slot inside the processor core. On x86-64, general-purpose registers are 64 bits wide, and instructions can address smaller slices of the same hardware register: RAX (64 bits), EAX (lower 32 bits), AX (16 bits), and AL (8 bits). Writing to a 32-bit register such as EAX automatically zeroes the upper 32 bits of RAX, whereas writing to AX or AL leaves the upper bits untouched.

Register Typical role in x86-64
RAX Function return value, arithmetic accumulator
RDI, RSI, RDX, RCX Integer arguments (order depends on OS ABI)
RSP Stack pointer (top of stack)
RBP Frame pointer for local variables
RIP Instruction pointer (next instruction address)
RFLAGS Condition flags: ZF (zero), CF (carry), SF (sign), OF (overflow)

On 64-bit ARM (AArch64), general-purpose registers are X0-X30 (32-bit aliases W0-W30), SP is the stack pointer, PC is the program counter, and NZCV holds status flags.

#Memory addressing and little-endian order

Arrays and structures live in RAM rather than registers. On x86, x86-64, and standard Linux/Windows ARM64 systems, multi-byte integers use little-endian byte order: the least significant byte sits at the lowest address. Thus, 0x12345678 at 0x1000 appears in a hex dump as 78 56 34 12.

In Intel-syntax assembly, square brackets [...] dereference a memory address using [base + index*scale + displacement] (scale is 1, 2, 4, or 8):

  • mov eax, [rbp - 0x10] loads 4 bytes from stack address rbp - 0x10.
  • mov edx, [rdi + rcx*4] loads element rcx from a 32-bit array at rdi.
  • lea rax, [rdi + rcx*4 + 8] (Load Effective Address) computes the address itself and stores that number in rax without reading RAM.

The call stack grows downward toward lower addresses: push subtracts 8 from RSP and writes [RSP]; pop reads [RSP] and adds 8.

#Calling conventions across platforms

A calling convention (part of the platform ABI) defines how functions pass arguments, return results, and preserve registers.

Feature System V AMD64 (Linux, macOS x64) Microsoft x64 (Windows) AArch64 AAPCS64 (ARM64)
First 4 integer args RDI, RSI, RDX, RCX RCX, RDX, R8, R9 X0, X1, X2, X3
Extra register args R8, R9 (then stack) Stack (after 4th arg) X4-X7 (then stack)
Return value RAX RAX X0
Callee-saved regs RBX, RBP, R12-R15 RBX, RBP, RDI, RSI, R12-R15 X19-X29
Stack rule 16-byte alignment before call 32-byte shadow space by caller X30 (LR) holds return address
Function call flow under System V AMD64Function call flow under System V AMD64CallerStackCalleePut arg1 in RDI, execute call (pushes return RIP)push rbp; mov rbp, rsp; sub rsp, 0x10Compare [rbp-0x4] against constantmov eax, result; pop rbp; ret (pops return RIP)
Inspecting a lab binary with objdump (Intel syntax)
$ objdump -d -M intel ./starter_crackme | grep -A 9 "<check_pin>:"
0000000000001149 <check_pin>:
    1149: 55                    push   rbp
    114a: 48 89 e5              mov    rbp,rsp
    114d: 89 7d fc              mov    DWORD PTR [rbp-0x4],edi
    1150: 81 7d fc 39 05 00 00  cmp    DWORD PTR [rbp-0x4],0x539
    1157: 0f 94 c0              sete   al
    115a: 0f b6 c0              movzx  eax,al
    115d: 5d                    pop    rbp
    115e: c3                    ret

Here check_pin copies its first argument (edi) to [rbp-0x4], compares it to 0x539, sets al to 1 on equality (sete al), zero-extends al into eax, and returns.

#Common mistakes

  • Reading memory bytes as big-endian. Reverse multi-byte values from little-endian dumps (39 05 00 00 equals 0x00000539, not 0x39050000).
  • Confusing lea with mov. lea rax, [rdi + 8] adds 8 to rdi without reading RAM.
  • Forgetting zero-extension on 32-bit writes. mov eax, 1 clears bits 32-63 of RAX, while mov al, 1 preserves bits 8-63.
  • Mixing up System V and Windows x64 arguments. Linux passes arg1 in RDI; Windows uses RCX with 32-byte shadow space.

#Summary

Registers hold active operands, with 32-bit aliases like EAX zero-extending into RAX. Multi-byte integers in RAM use little-endian order, and [base + index*scale + disp] expressions calculate addresses for mov or lea. Platform calling conventions tell you which registers carry arguments and return values in any disassembly listing.

Knowledge check

Sign in to take the test, complete lessons and save your progress. Log in

Practice: test your knowledge