Switching to and from ARM/Thumb

Shaun Jackman sjackman@gmail.com
Tue Jan 18 01:18:00 GMT 2005


> You should not modify the thumb bit in the psr directly. The correct way to
> switch modes is using the bx instruction, ie:

The cli() macro was just an example of how the arm() and thumb()
macros would be used. It was only modifying the cpsr to clear the
interrupt flag. The arm() and thumb() macros used bx as you suggest.

> .code 16
> thumb_to_arm:
>  .align 2
>  bx pc
>  nop

Does gas insert zero bytes for alignment? and is this a reasonable nop
instruction? gas compiles 'nop' to 46c0 nop (mov r8, r8).

> .code32
> arm_to_thumb:
> #ifdef __ARMv4T__
>  add ip, pc, #1
>  bx ip
> #else
>  sub pc, pc, #1
> #endif
> thumb_code:

If this is used in inline assembler, does gcc need to be informed of
ip being trashed?

Cheers,
Shaun



More information about the Binutils mailing list