What are SP, PC, LR and PSTATE?
Short answer: SP is the stack pointer, PC tracks instruction execution, X30 is the conventional link register, and PSTATE holds execution state including NZCV flags and interrupt masks. PC is not an ordinary general-purpose register in A64.
BL function
// ...
function:
RET
1. Special register roles
| Register | Purpose |
|---|---|
| SP | Current stack location |
| PC | Address associated with instruction execution |
| X30 / LR | Return address after BL |
| PSTATE | Flags, interrupt masks and execution state |
2. Function call: BL places the next instruction address in X30 and branches to the function. RET normally branches to X30. A nested call overwrites LR, so a non-leaf function generally saves it if it needs it later.
3. Practical note: AArch64 does not expose PC as an ordinary general-purpose register. ADR and ADRP can compute PC-relative addresses.
Interview takeaway: SP manages stack storage, LR supports returns, PC controls execution and PSTATE records processor state.
Function call versus exception return
BL function // X30 receives address of next instruction
// execution continues here after RET
function:
ADD X0, X0, #1
RET // normally branches to X30
A non-leaf function generally preserves its incoming return address before executing another BL. SP points into the active stack; the normal AAPCS64 stack alignment at public interfaces is 16 bytes. PC is not a general-purpose X register, but PC-relative instructions such as ADR and ADRP construct addresses relative to instruction execution.
An exception uses a separate mechanism: hardware writes ELR_ELx and SPSR_ELx for the target exception level, and ERET restores the saved return state. X30 is not the exception return register. PSTATE contains flags and execution controls (such as NZCV and exception masks); selected fields are accessed using architectural system-register interfaces, not as one ordinary writable GPR.