What is the ARM Thumb Instruction set?

Soroush picture Soroush · May 17, 2012 · Viewed 43k times · Source

under "The Thumb instruction set" in section 1-34 of "ARM11TechnicalRefManual" it said that:

"The Thumb instruction set is a subset of the most commonly used 32-bit ARM instructions.Thumb instructions are 16 bits long,and have a corresponding 32-bit ARM instruction that has the same effect on processor model."

can any one explain more about this especially second sentence and say how does processor perform it?

Answer

kennytm picture kennytm · May 17, 2012

The ARM processor has 2 instruction sets, the traditional ARM set, where the instructions are all 32-bit long, and the more condensed Thumb set, where most common instructions are 16-bit long (and some are 32-bit long). Which instruction set to run can be chosen by the developer, and only one set can be active (i.e. once the processor is switched to Thumb mode, all instructions will be decoded as using the Thumb instead of ARM).

Although they are different instruction sets, they share similar functionality, and can be represented using the same assembly language. For example, the instruction

ADDS  R0, R1, R2

can be compiled to ARM (E0910002 / 11100000 10010001 00000000 00000010) or Thumb (1888 / 00011000 10001000). Of course, they perform the same function (add r1 and r2 and store the result to r0), even if they have different encodings. This is the meaning of Thumb instructions are 16 bits long,and have a corresponding 32-bit ARM instruction that has the same effect on processor model.

Every* instruction in Thumb encoding also has a corresponding encoding in ARM, which is meant by the "subset" sentence.


*: Not strictly true, there is not "IT" instruction in ARM, although ARM doesn't need "IT" anyway (it will be ignored by the assembler).