← Back to the chapter · Previous detail

Technical detail · Microcontroller Programming: Timing and Reliability

Cortex-M status registers

On Cortex-M4, xPSR is the combined view of three overlapping status-register roles: the Application Program Status Register (APSR), Interrupt Program Status Register (IPSR), and Execution Program Status Register (EPSR).

Saturating arithmetic clamps a result to the allowed range instead of wrapping; DSP operations are instructions used for signal-processing tasks such as packed arithmetic. Thumb is the instruction set used by Cortex-M. ICI records progress for certain interrupted instructions, while IT tracks conditional execution in a Thumb instruction block. These fields help the processor resume work correctly.

View / fieldBit(s)Meaning
APSR N31Negative: the result’s most significant bit is one
APSR Z30Zero: the result is zero
APSR C29Carry/borrow/shift carry; interpret subtraction using Arm’s no-borrow convention
APSR V28Signed overflow: the signed mathematical result did not fit
APSR Q27Sticky saturation flag set by saturating/DSP operations until software clears it as permitted
IPSR exception number8:0Zero means Thread mode; nonzero identifies the active exception
EPSR T24Thumb execution state; Cortex-M executes Thumb instructions and an invalid state faults
EPSR ICI/ITsplit across 26:25 and 15:10Interrupt-continuable instruction state or Thumb IT conditional-execution state

The arithmetic flags are easiest to separate with two examples. 0xFFFFFFFF + 1 produces zero, so Z=1 and C=1; interpreted as signed −1+1-1+1, it does not overflow, so V=0. By contrast, 0x7FFFFFFF + 1 produces 0x80000000: N=1, V=1, and C=0. Carry describes the unsigned result, while overflow describes the signed result.

IPSR gives exception context, not a generic interrupt-enabled flag. Handler mode has a nonzero exception number; Thread mode reads zero. EPSR’s ICI/IT fields are execution-resume state maintained by the processor around interrupted multi-cycle instructions or IT blocks. Application code should not treat them as spare flags. When a debugger shows xPSR, decode each view by its own meaning: arithmetic result in APSR, active exception in IPSR, and execution state in EPSR.

Decode processor status by question, not as one opaque hexadecimal word, in the diagram Figure 5.

Cortex-M xPSR anatomy combining APSR condition flags, IPSR exception number, and EPSR Thumb and ICI or IT execution state.
The xPSR combines arithmetic flags in APSR, the active exception number in IPSR, and execution state in EPSR.

In this snapshot, choose the field that answers the debugging question: APSR for arithmetic, IPSR for exception identity, or EPSR for execution state.

← Back to the chapter · Previous detail