In ARM-based processors, ARM and Thumb states serve different purposes, primarily affecting code size and memory efficiency. The ARM state operates with a full 32-bit RISC instruction set, while the Thumb state uses a compressed 16-bit instruction set, reducing memory usage while maintaining execution speed.
While both states execute at the same speed, the difference lies in how instructions are fetched and interpreted. ARM processors include dedicated hardware to expand Thumb instructions into their full 32-bit equivalents. This makes Thumb useful for embedded systems, mobile devices, and memory-constrained environments.
Comparison of ARM and Thumb states:
Feature | ARM State | Thumb State |
---|---|---|
Instruction Set | Full 32-bit RISC instructions | 16-bit compressed subset (some 32-bit instructions available) |
Code Size | Larger | Smaller (optimized for memory efficiency) |
Execution Speed | No impact (Instructions are processed natively) | No impact (CPU expands instructions efficiently) |
Registers | 18 total: R0-R12, SP (R13), LR (R14), PC (R15), CPSR, SPSR (for exceptions) | 12 total: R0-R7, SP, LR, PC, CPSR (Registers must be used for state transitions) |
CPSR T Bit | T = 0 (Indicates ARM state) | T = 1 (Indicates Thumb state) |
Branching Between States | BX or BLX to an address with LSB = 0 switches to ARM state (e.g., BX 0x80000000) | BX or BLX to an address with LSB = 1 switches to Thumb state (e.g., BX 0x80000001) |
Exception Handling | ARM state is entered on exceptions | Not available |
Returning from Exception | If T bit in SPSR is 1, returns to the Thumb state | If the T bit in SPSR is 1, returns to the Thumb state |
Register Access | Can access status and coprocessor registers | Cannot directly access status or coprocessor registers |
Stack Operations | Uses LDR and STR for stack manipulation | Provides dedicated stack mnemonics (PUSH, POP) |
Advantages | Full instruction set, direct register access, flexible operations | Reduced memory usage, works efficiently with 16-bit bus |
Disadvantages | Requires more memory | No direct access to coprocessor/status registers; Some operations need multiple instructions instead of one |
When to Use ARM vs Thumb?
- Use ARM state when performance and full register access are required.
- Use Thumb state for memory-efficient applications like embedded systems, IoT devices, and mobile processors.
ARM and Thumb states in processor architecture offer distinct advantages, primarily concerning code size optimization. ARM employs a unified instruction set, while Thumb introduces a 16-bit shorthand for a subset of these instructions. The processor fetches these 16-bit instructions and expands them into equivalent 32-bit instructions, ensuring execution speed remains unaffected. Dedicated hardware within the CPU interprets Thumb instructions efficiently.
ARM (Advanced RISC Machines) utilizes a comprehensive 32-bit RISC instruction set, requiring more memory but offering robust functionality across 18 registers, including SP (R13), LR (R14), PC (R15), CPSR, and SPSR for exception handling. In contrast, Thumb reduces memory usage with its 16-bit instructions, supporting a subset of ARM operations through 12 registers (R1-R7, SP, LR, PC, CPSR). The CPSR’s T bit distinguishes between ARM (T=0) and Thumb (T=1) states.
Branch instructions (BX or BLX) direct the processor to ARM or Thumb states based on the LSB of the target address. Exceptions typically trigger the ARM state, with returns governed by the SPSR’s T bit (0 for ARM, 1 for Thumb).
Thumb’s advantages include reduced memory footprint and efficient use of a 16-bit bus without compromising speed. However, limitations include the inability to directly access status or coprocessor registers and the need for multiple Thumb instructions to simulate certain complex ARM operations.
Further reference: https://www.ijset.in/wp-content/uploads/IJSET_V9_issue4_362.pdf