Electronic – How does an ARM processor in thumb state execute 32-bit values

arminstruction-set

What I understand is, the ARM mode can execute 32-bit of instructions and Thumb mode can execute 16-bit of instructions.

For instance,

enter image description here

Here is the ARM instructions set:

enter image description here

And Thumb instructions set:

enter image description here

From these both instruction set tables, please see ADC mnemonic that describes add two 32-bit values and carry. So, 32-bit is common in both the modes.

What I didn't understand is, how a thumb mode which can execute 16-bit is able to execute 32-bit value?

I referred the other books (which I could) and in those books also same description is given. Please explain me this concept/correct me which I misunderstood.

Best Answer

The data bus width of the processor has nothing to do with the length of the instructions.

The ARM processor can manipulate 32 bit values because it is a 32-bit processor, whatever mode it is running in (Thumb or ARM). It just means its registers are 32 bits wide. And the registers don't change when you switch mode.

Now, it doesn't have any implication on the length of the instructions. The instructions could be encoded in any length. The x86, for example, uses 8-bit instructions but is also able to work on 32 bit values. For ARM, this is what changes when you switch to/from ARM and thumb modes.

For example, the instruction MOV R0, R1 (copy the contents of the 32-bit R1 register to the R0 register) is encoded in the following way:

  • E1A00001 for ARM (32 bit)
  • 4608 for Thumb (16-bit)

But the processor, in the end, will perform exactly the same operation, and it will do it on 32-bit wide data, whatever the mode.

This ability to switch modes simply allows you to decide on the compromise between code density and flexibility. You can pack more instructions in a kB of code with 16-bit instructions, but the 32 bit instructions are more flexible (they offer more features and you can do more with a single instruction).