What is the ARM Thumb Instruction set?
Asked Answered
M

1

73

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?

Mintun answered 17/5, 2012 at 14:53 Comment(0)
L
103

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).

Letha answered 17/5, 2012 at 15:22 Comment(7)
The original Thumb-Instruction set only contained 16-bit instructions. Thumb2 introduced mixed 16/32 bit instructions. Thumb(1) was just a compressed version of the ARM-Instruction set. The CPU would enable a "decompressor" on instruction fetching so in the end the CPU still processed ARM-Instructions. For ARM this most probably was a quick but elegant hack to trim down on code size and ICache-Utilization with little changes to the actual cores. Thumb2 added a lot of new features like the mentioned "IT*" Instruction and some 32-Bit instructions.Towers
Which one is preferred over other? Do we have to use ARM instructions for 32 bit processors and Thumb instructions for 16 bit processors?Dupuy
@Dupuy AFAIK there is no "16-bit ARM processors". Use Thumb if you're targeting armv7 or above.Letha
@Rajesh: Machines with separate 16-bit and 32-bit modes tended to execute both kinds of instructions at about the same per-instruction speed, but the number of 32-bit instructions required to perform many tasks would be smaller than the number of 16-bit operations. Thus, parts of the code that were speed-critical would often benefit from using 32-bit mode, and parts that weren't could be made more compact using 16-bit mode.Mcclain
@Rajesh. Do not talk about 16-bit and 32-bit modes. The length of the instructions has nothing to with the length of the registers of the processor. The 80386 can be in 16-bit mode for data and 32-bit mode for address lenght or vice versa and the instructions are the same. The arm can not be in 16 bit mode for data! Before Intel came along to confuse us, a x-bit processor just means a processor with a x-bit wide data path. Intel contains at least 4 separate instruction to move register A to register B and they do not have the same length. Groetjes AlbertMonotone
@NicoErfurth In some conversation I quoted your Thumb(1) was just a compressed version of the ARM-Instruction set and got Thumb(1) is not a compressed version of the ARM set. Can you comment on that?Cromwell
@Cromwell This was not meant as "compressed" as in zip-compressed. But the original instruction-set was basically implemented by removing some flexibility and taking assumptions instead. Then the CPU pipeline had a fixed decompressor put in front of it, which just implemented a fixed-wired thumb-2-arm translation. There the instruction gets expanded to a full blown arm instruction. And the CPU will execute ARM instructions. See scienceprog.com/compressed-thumb-instructions-of-arm-mcu for example.Towers

© 2022 - 2024 — McMap. All rights reserved.