Goal and Big Picture
Two execution states exist in classic 32-bit ARM: ARM state (A32) and Thumb state (T32/Thumb-2). They share registers and semantics but use different instruction encodings. The T bit chooses which decoder runs. Mixed-state systems exist to balance code size, performance, and backward compatibility.
Names and Scope
- A32 = “ARM state.” Fixed 32-bit instructions.
- T32 = “Thumb-2 state.” Mixed 16/32-bit instructions.
- Thumb-1 = early 16-bit subset (v4T/v6-M).
- Cortex-M cores: T32 only. A32 does not exist.
- Cortex-A/R cores: both A32 and T32.
Why Two States Exist
Inputs → constraints:
- 1990s embedded ROM/flash was expensive.
- Many systems had narrow or slow instruction fetch.
- Large A32 software base already shipped.
Levers → design choices:
- Add a compact encoding (Thumb) to cut code size ~25–35% typical.
- Keep A32 for legacy and some early performance cases.
- Allow fine-grained mixing and transition at call boundaries.
Outputs → benefits:
- Higher I-cache/TLB hit rate.
- Lower instruction-fetch bandwidth and power.
- Gradual migration path from A32 to T32.
The T Bit and State
The processor’s T bit selects the decoder:
- Target LSB=1 → set T=1 (Thumb).
- Target LSB=0 → set T=0 (ARM).
Hardware then masks the LSB before writing PC:
PC ← target & ~1.
Location of T:
- A/R profiles: CPSR.T
- M profile: xPSR.T
Program Counter alignment by state:
- A32: PC is 4-byte aligned,
PC[1:0]=0. - T32: PC is 2-byte aligned,
PC[0]=0.
- A32: PC is 4-byte aligned,
Normal relative branches inside a state do not change T.
Cortex-M special case: Only T32 exists. Any attempt to set T=0 causes a fault.
Exception Entry and the Vector Table (Cortex-M)
Vector table holds handler pointers with LSB=1. Example at offset
0x04(Reset): value appears as…xxx1.On exception entry:
- Hardware reads the pointer.
- Sets xPSR.T = 1 (Thumb).
- Loads PC ← pointer & ~1 (align to halfword).
Result: You see
…xxx1in the table but…xxx0in PC.If a vector’s LSB=0 or clear T bit on Cortex-M → HardFault/UsageFault.
Privilege is orthogonal: Exception entry moves to Handler mode, privileged, but this has nothing to do with T or PC bit0.
A32 vs T32: What Actually Differs
Encoding and Alignment
- A32: fixed 32-bit opcodes, 4-byte alignment, uniform decode.
- A32: typically
PC = current + 8. - T32: mixed 16/32-bit opcodes, 2-byte alignment, denser code.
- T32: typically
PC = current + 4. - This affects PC-relative loads/adr. Assemblers abstract this, but hand-coded sequences must account for it.
Conditional execution
- A32: each instruction has a 4-bit condition field (predication).
- T32: only branches are generally conditional. Limited predication via IT(If-Then) blocks (up to 4 following instructions). In newer architectures, long IT blocks are discouraged.
Instruction coverage
- T32 (Thumb-2): adds 32-bit encodings to cover almost all A32 functionality: full register access, rich addressing modes, multi-load/store, barriers, saturating/DSP ops, system instructions.
- Thumb-1 (e.g., M0/M0+): small subset; many ops are 16-bit forms with limited registers.
Performance
- On modern cores, T32 ≈ A32 for most code.
- T32 often wins at system level due to better cache/I-fetch behavior.
- A32 can be equal or marginally faster in some micro-benchmarks on older A/R cores.
Interworking: Calling Across States (A/R Profiles)
Function pointers must carry state in LSB:
- Pointer to a T32 function has LSB=1.
- Pointer to an A32 function has LSB=0.
The linker may insert veneer stubs to cross states safely (via
BX/BLX), especially for long-range calls.C toolchains handle this if you compile with interworking enabled.
Example (conceptual):
; A32 → call Thumb function 'foo'
ldr r0, =foo+1 ; set LSB=1 to request T32
blx r0 ; switches to T32, LR set for return
; Thumb → call ARM function 'bar'
ldr r0, =bar ; LSB=0 means A32
blx r0 ; switches to A32
Toolchain Switches and Attributes
GCC/Clang:
-mthumb→ generate T32.-marm→ generate A32 (not valid on M-profile).-mcpu=or-march=must match the core.
Mixed builds on A/R:
- Compile some objects with
-marm, others with-mthumb. - Linker handles interworking veneers when enabled by defaults in modern toolchains.
- Compile some objects with
Do not manually OR
+1to C function pointers. Compilers represent function pointers correctly; manual bit-twiddling is error-prone unless you know the ABI and relocation model.
Disassembly and Debugging
Select the correct decoder:
- Cortex-M: always Thumb/T32.
- A/R: module-dependent; check symbol attributes or ELF flags.
Symptoms of wrong mode:
- “UNPREDICTABLE,” illegal opcodes, nonsense mnemonics.
- Vector entry shows
…xxx1but PC shows…xxx0by design.
Breakpoints align to instruction boundaries:
- T32 has 16- and 32-bit encodings. Place breakpoints carefully.
Minimal Code Examples
Vector Table Snippet (Cortex-M)
typedef void (*isr_t)(void);
extern unsigned _estack;
extern void Reset_Handler(void);
__attribute__((section(".isr_vector")))
isr_t const vector_table[] = {
(isr_t)&_estack, // Initial SP
(isr_t)((uintptr_t)Reset_Handler | 1u), // LSB=1 → Thumb
// ...
};
Summary
| Feature | Thumb-1 (T16) | Thumb-2 (T32) | A32 (ARM state) |
|---|---|---|---|
| Instruction length | Fixed 16-bit | Mixed 16/32-bit | Fixed 32-bit |
| Code density | High | High | Lower |
| Conditional execution | Conditional branches only | IT blocks for 1–4 instructions¹ | Condition field on most instructions |
| Register access | Mostly r0–r7 (+ limited “high regs”) | All GPRs | All GPRs |
| 2nd operand / addressing | Restricted | Close to A32 | Flexible barrel shifter and addressing modes |
| Branch range | B short, BL long |
16-bit short + 32-bit long (B.W/BL) |
Wide |
| PC alignment | 2-byte (PC[0]=0) | 2-byte (PC[0]=0) | 4-byte (PC[1:0]=0) |
| PC literal semantics | PC+4; most data uses Align(PC,4) | PC+4; most data uses Align(PC,4) | PC+8; data uses Align(PC,4) |
| IT support | None | Yes (IT{T/E}…)¹ |
Not needed |
Atomics (LDREX/STREX) |
None (ARMv6-M) | Present (v7-M/A/R) | Present (ARMv6+) |
| SIMD/FP (VFP/NEON) | None | Accessible if present | Accessible if present |
| A32↔T32 transition | Via BX/BLX (target LSB=1 → Thumb)² |
Via BX/BLX |
Via BX/BLX |
| T bit (xPSR/CPSR.T) | Must be 1 | Must be 1 | Must be 0 |
| Architectural origin | ARMv4T–v6 | ARMv6T2; common in ARMv7/ARMv8 | ARMv2–v7; AArch32 optional in v8-A |
| Typical cores | Cortex-M0/M0+ (ARMv6-M) | Cortex-M3/M4/M7/M33; A/R | Cortex-A/R |
| Primary use | Very small MCUs, tight memory | General use, embedded and mobile | High flexibility, legacy compatibility |
| Pros | Smallest binaries | Small binaries + broad feature set | Most flexible encoding, legacy software |
| Cons | Limited instructions/addressing | IT limitations, mixed length | Larger binaries, more fetch |
Notes:
1. IT blocks are largely deprecated in ARMv8-A; still valid on M-profile.
2. Cortex-M profiles do not support A32; switching to ARM state via BX/BLX is invalid on M.