Turn-key PCB assembly services in prototype quantities or low-volume to mid-volume production runs

Compressed Thumb instructions of ARM MCU

Thumb instructions

Thumb instructions shrink ARM instructions from 32 bit to 16-bit length. This allows saving up to 40% of program memory comparing to the ARM instruction set. Maybe this is the main reason for Thumb instructions being used. Thumb instructions lose many properties of ARM instructions and become similar to traditional RISC instructions. Thumb instructions cant be conditional. Data processing has a two-address format where the destination register is one of the source registers.

ARM instruction: ADD R0, R0, R1

Thumb instruction: ADD R0, R1

As the Thumb instruction set takes less program space, it allows to upload bigger applications, but with lower speed than using ARM, instructions performance is up to 40% faster. But in noncritical applications or functions speed isn’t a significant factor.

Also, Thumb instructions don’t have full access to all registers. Thumb instructions can only access “low registers”(R0-R7). And only a few instructions can access “high registers”(R8-R12).

Thumb decoding

Thumb instructions have to be decoded-decompressed to equivalent ARM instructions while executing. This is handled in the instruction pipeline. The pipeline has additional de-compressor logic in series to instruction decoder, which decompresses Thumb instruction and then decodes. This usually results in decode latency.

Thumb_decode

Changing to Thumb mode

Changing to Thumb mode is done by setting T-flag in the 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 the ARM instruction set, where cost and power consumption are important, use Thumb instructions. Sometimes, it is better to use both instruction sets where a high-end ARM system uses Thumb code in noncritical routines to save power and memory space.

Leave a Reply