Do ARM64 registers contain data or addresses?
Short answer: Both. X0–X30 hold 64-bit values; instructions determine whether those bits represent data or an address. Writing Wn zeroes the upper 32 bits of Xn.
MOV X1, #0x1000
LDR X2, [X1] // assuming valid readable address
ADD X3, X2, #1
1. Actual data: MOV X1, #10 puts the number 10 directly in X1. ADD operates on register values without reading data memory.
2. Address: LDR X2, [X1] interprets X1 as an address and loads eight bytes. If the MMU is enabled, the address is translated before accessing memory.
long a = 50;
long *p = &a;
long b = *p;
Conceptually X1 holds p and X2 holds b on typical ARM64 Linux.
| Instruction | Meaning |
|---|---|
| MOV X2, X1 | Copy bits |
| LDR X2, [X1] | Read pointed-to memory |
| STR X2, [X1] | Write pointed-to memory |
Interview takeaway: Registers are not inherently typed as pointers or integers; the instruction decides how to use their bits.
Trace the values through a real load and store
Assume X1 contains the valid mapped virtual address 0x1000 and an eight-byte value 50 is stored there.
LDR X2, [X1] // X2 becomes 50
ADD X2, X2, #5 // X2 becomes 55
STR X2, [X1] // memory at that address becomes 55
X1 remains 0x1000 throughout. The instruction's addressing mode determines the effective address, and its operand width determines the number of bytes read or written. LDR W2 reads four bytes and zero-extends into X2; LDRSW X2 reads a signed 32-bit value and sign-extends it. For an invalid or forbidden address, LDR may generate an exception rather than return a value. With an enabled MMU, X1 usually contains a virtual address, not a DRAM physical address. A compiler can keep a C object entirely in registers, so the C example does not guarantee actual loads and stores in optimized machine code.