This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

From the CPU's point of view, how does it distinguish an assembly code is an ARM code or a Thumb code?

From the CPU's point of view, how does it distinguish an assembly code is an ARM code or a Thumb code?

Is there some signal bit represent the code is ARM or Thumb code, this is just my guess.

Parents
  • Opcodes, whether ARM or Thumb, are just bit patterns in memory.  It's a question of how those bit patterns are interpreted, which is controlled by the CPSR.T bit (1=Thumb, 0=ARM).

    That is, if you execute from an address with T=1 the contents of the address will be treated as Thumb.  Execute the same address with T=0, and it will be treated as ARM.

    If a person looks at a region of memory, it's usually obvisous whether it contains ARM or Thumb.  As one will give you sensible looking code, and the other garbage.

    The T bit usually gets updated during branches, such as function calls/returns or exception entry/exit.  Sticking with function call/returns, "BL <label>" will branch to function in the same instruction set.  While "BLX <label>" will branch to a function in the other instruction set.  (You usually don't have to worry which to use, and can leave it to the linker).  On the return side, when you write an absolute address into the PC (e.g. "BX lr" or "POP {..., PC}"), bit 0 is used to update the T bit.

Reply
  • Opcodes, whether ARM or Thumb, are just bit patterns in memory.  It's a question of how those bit patterns are interpreted, which is controlled by the CPSR.T bit (1=Thumb, 0=ARM).

    That is, if you execute from an address with T=1 the contents of the address will be treated as Thumb.  Execute the same address with T=0, and it will be treated as ARM.

    If a person looks at a region of memory, it's usually obvisous whether it contains ARM or Thumb.  As one will give you sensible looking code, and the other garbage.

    The T bit usually gets updated during branches, such as function calls/returns or exception entry/exit.  Sticking with function call/returns, "BL <label>" will branch to function in the same instruction set.  While "BLX <label>" will branch to a function in the other instruction set.  (You usually don't have to worry which to use, and can leave it to the linker).  On the return side, when you write an absolute address into the PC (e.g. "BX lr" or "POP {..., PC}"), bit 0 is used to update the T bit.

Children