Current Program Status Register (CPSR).

The Current Program Status Register (CPSR) is a 32-bit register in ARM architecture used to:

  • Monitor internal processor status
  • Control processor modes, interrupt states, and execution states
  • Hold condition flags for conditional execution

It plays a central role in managing instruction execution, mode switching, and interrupt handling.


Layout of CPSR

The CPSR is divided into four 8-bit fields:

BitsFieldDescription
[31:24]FlagsStores condition flags (N, Z, C, V, Q) and state bits (J, T)
[23:16]StatusReserved for future use
[15:8]ExtensionReserved for future expansion
[7:0]ControlStores interrupt masks, processor state, and processor mode bits

The status and extension fields are generally unused in current ARM implementations.


Processor Modes in CPSR

ARM supports 7 processor modes, each with different access permissions:

Mode NameAbbrev.Privileged?CPSR Mode BitsHex
Userusr❌ No100000x10
FIQfiq✅ Yes100010x11
IRQirq✅ Yes100100x12
Supervisorsvc✅ Yes100110x13
Abortabt✅ Yes101110x17
Undefinedund✅ Yes110110x1B
Systemsys✅ Yes111110x1F

Privileged modes can read/write all parts of CPSR.
User mode has limited access—read-only to some parts.


Banked Registers and Mode Switching

  • ARM has 37 physical registers, but only a subset is visible at any time.
  • Some registers are banked — unique to each mode.
  • Example:
    • r13_usr and r14_usr (User mode)
    • r13_irq and r14_irq (IRQ mode)

When the processor switches mode (e.g., on interrupt), it:

  • Banks (hides) the user registers
  • Replaces them with mode-specific registers (e.g., r13_irq, r14_irq)
  • Saves the current CPSR into SPSR_mode (Saved Program Status Register)

Only privileged modes have access to the SPSR.


Processor States and Instruction Sets

CPSR determines which instruction set is active:

BitsInstruction SetDescription
J = 0, T = 0ARM32-bit instructions
J = 0, T = 1Thumb16-bit instructions
J = 1, T = 0Jazelle8-bit Java bytecodes (specialized)

State is changed using special branch instructions, not by mixing instructions.


Interrupt Mask Bits in CPSR

The CPSR controls the enabling/disabling of interrupts using I and F bits:

BitNameFunction
7F1 = Mask FIQ (Fast Interrupt Request)
6I1 = Mask IRQ (Interrupt Request)

🔹 Set to 1 → Disable
🔹 Set to 0 → Enable


Condition Flags in CPSR

Located in bits [31:28], these flags are modified by ALU operations with S suffix (e.g., ADDS, SUBS):

FlagNameSet When
NNegativeResult is negative (bit 31 = 1)
ZZeroResult is zero
CCarryUnsigned carry-out from result
VOverflowSigned overflow in result
QSaturationOverflow/saturation in DSP instruction (sticky flag, manual reset)

Conditional Execution in ARM

Most ARM instructions can be executed conditionally based on CPSR condition flags.

ConditionMnemonicMeaning
EQEqualZ = 1
NENot EqualZ = 0
CS/HSCarry SetC = 1
CC/LOCarry ClrC = 0
MIMinusN = 1
PLPlusN = 0
VSOverflowV = 1
VCNo OVFLV = 0
ALAlwaysDefault

Leave a Reply

Your email address will not be published. Required fields are marked *