8

Thumb mode instructions are 2 bytes and ARM mode instructions are 4 bytes. the screenshot is a disassembly of thumb mode instructions. why do I see 4 byte instructions mixed with 2byte instructions?? can someone explain this?

thank you in advance.

enter image description here

artless noise
  • 21,212
  • 6
  • 68
  • 105
daehee
  • 5,047
  • 7
  • 44
  • 70
  • 5
    Because it is **thumb-2**. – artless noise Aug 08 '13 at 13:59
  • The real question is why are those two mov instructions 4-byte when they could be encoded as 2-byte (thumb1) instructions. – Pete Fordham Aug 08 '13 at 16:58
  • 3
    *thumb-1* doesn't have 32bit op-codes at all. Only *thumb-2* has `mov.w`, etc. A processor can not switch modes between instructions (until a BLX,etc), so this code must be *thumb-2*. Even `bl` and `blx` are 16bit in *thumb-1*. – artless noise Aug 08 '13 at 18:29

2 Answers2

2

Cortex M micros can run only in Thumb-2 mode, which is something in between thumb and ARM modes. Thumbs-2 instruction set includes 16 and 32 bit instructions and processor don't need switch modes to execute both types of instructions.

  • 1
    32-bit Thumb-2 instruction encodings are *not* the same as ARM-mode instruction encodings. They just happen to have the same length when there's no 16-bit short encoding possible for a given combination of instruction and operands. For example they don't use the top 4 bits for predication, you still need a `.it` instruction in Thumb2 mode. – Peter Cordes May 15 '19 at 10:22
2

http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0471i/CHDFEDDB.html

or pdf

http://infocenter.arm.com/help/topic/com.arm.doc.dui0471i/DUI0471I_developing_for_arm_processors.pdf

Thumb-2 technology is available in the ARMv6T2 and later architectures. Thumb-2 technology is a major enhancement to the Thumb instruction set. It adds 32-bit instructions that can be freely intermixed with 16-bit instructions in a program. The additional 32-bit encoded Thumb instructions enable Thumb to cover most of the functionality of the ARM instruction set. The availability of 16-bit and 32-bit instructions enables Thumb-2 technology to combine the code density of earlier versions of Thumb with the performance of the ARM instruction set.