</>EmbeddedInterview

What are the Cortex-M core registers?

MediumMicrocontrollers & ARM Cortex-M

Short answer: Cortex-M has 16 core registers: R0–R12 general purpose, R13 the stack pointer (banked as MSP and PSP), R14 the link register, R15 the program counter, plus the program status register xPSR and the special registers PRIMASK, FAULTMASK, BASEPRI (interrupt masking) and CONTROL (privilege and stack selection). Cores with an FPU add S0–S31 and FPSCR.

Register Role
R0–R3 arguments and return values (AAPCS), scratch
R4–R11 callee-saved variables
R12 scratch (IP, intra-procedure call)
R13 (SP) stack pointer: MSP (main) or PSP (process), selected by mode and CONTROL.SPSEL
R14 (LR) return address after BL; inside an exception holds an EXC_RETURN value (e.g. 0xFFFFFFF9)
R15 (PC) program counter
xPSR combined APSR (N, Z, C, V, Q flags, GE bits), IPSR (current exception number), EPSR (Thumb bit, IT/ICI state)
PRIMASK 1 = mask all configurable-priority interrupts
FAULTMASK 1 = also mask HardFault (not on v6-M)
BASEPRI mask interrupts at or below a priority (not on v6-M)
CONTROL bit 0 nPRIV (unprivileged thread mode), bit 1 SPSEL (use PSP in thread mode), bit 2 FPCA (FP context active)
MSPLIM, PSPLIM stack limits (Armv8-M)

Reading special registers from C (CMSIS): __get_IPSR(), __get_CONTROL(), __set_BASEPRI(), __get_MSP(), __get_PSP().

Why these matter in interviews

  • The IPSR tells you whether code is running in an ISR (non-zero) and which one; RTOS code uses this to choose between normal and FromISR APIs.
  • EXC_RETURN in LR tells a fault handler which stack held the faulting context (bit 2: 0 = MSP, 1 = PSP).
  • The Thumb bit (EPSR.T) must always be 1 on Cortex-M; branching to an address with bit 0 clear causes a UsageFault (INVSTATE), a classic bug with hand-built function pointers.