Thumb instructions shrinks ARM instructions from 32 bit to 16 bit length. This allows saving up to 40% of program memory comparing to ARM instruction set. Maybe this is main reason of Thumb instructions being used. Thumb instructions loose many properties of ARM instructions and become similar to traditional RISC instructions. Thumb instructions cant be conditional, data processing have a two-address format where destination register is one of source registers.
ARM instruction: ADD R0, R0, R1
Thumb instruction: ADD R0, R1
As Thumb instruction set takes less of program space it allows to upload bigger applications but with lower speed as using ARM instructions performance is up to 40% faster. But in non critical applications or functions speed isn’t significant factor.
Also Thumb instructions doesn’t have full access to all registers. Thumb instructions can only access “low registers”(R0-R7). And only few instructions can access “high registers”(R8-R12).
Thumb instructions has to be decoded-decompressed to equivalent ARM instructions while executed. This is handled in instruction pipeline. Pipeline has additional de-compressor logic in series to instruction decoder, which firstly decompress Thumb instruction and then decode. This usually results in decode latency.
Changing to Thumb mode
Changing to Thumb mode is done by setting T-flag in CPSR register. This is usually done by executing BX(Branche exchange) instruction to address where the Thumb code begins. So same memory space may contain ARM-code and Thumb-code.
Some interesting facts about using Thumb:
- The Thumb code requires 70% of the space of the ARM code.
- The Thumb code uses 40% more instructions than the ARM code.
- With 32-bit memory, the ARM code is 40% faster than the Thumb code.
- With 16-bit memory, the Thumb code is 45% faster than the ARM code.
- Thumb code uses 30% less external memory power than ARM code.
This means that where performance is needed a system should use ARM instruction set, where cost and power consumption is important use Thumb instructions. Sometimes is better to use combination of both instruction sets. Where high end ARM system uses Thumb code in non critical routines to save power and memory space.