6

How do I tell gcc to compile into Thumb1-only instructions?

Everyone knows helloworld.c:

#include <stdio.h>  
main() {  
 printf("Hello world");  
}  

And this is my command line:

user@debian-armel:~$gcc -mcpu=cortex-m3 -mthumb helloworld.c && objdump -d a.out

And voilá: most instructions are 32bit wide, as opposed to the 16bit I expected.

So, what am I doing wrong?

johannes
  • 7,262
  • 5
  • 38
  • 57
Alexander
  • 19,906
  • 19
  • 75
  • 162

1 Answers1

4

Cortex-M3 supports Thumb-2 so the compiler is free to generate 32-bit versions. One of the following should achieve what you need:

-march=ARMv5 -mthumb
-march=ARMv4T -mthumb
-march=ARMv6-M
-mcpu=Cortex-M0
Igor Skochinsky
  • 24,629
  • 2
  • 72
  • 109
  • 2
    Nope, Cortex-M0 and Cortex-M0+ don't support Thumb-2 with exception of BL and a couple of system instructions (MSR, MRS, DSB, DMB, ISB). See [ARMv6-M Architecture Reference Manual](http://infocenter.arm.com/help/topic/com.arm.doc.ddi0419c/index.html). – Igor Skochinsky Nov 20 '12 at 14:21
  • yeah I know it supports a subset, but it still supports it kind of, which means that gcc could still emit those Thumb-2 instructions – iabdalkader Nov 20 '12 at 14:38
  • 1
    if you do not specify the -march and only -mthumb you will get thumb instructions without thumb2 extensions. http://github.com/dwelch67/thumbulator if need be specify ARMv5 or ARMv4T which do not have thumb2 extensions – old_timer Nov 20 '12 at 14:48
  • 1
    gcc -mthumb -c myprog.c -o myprog.o – old_timer Nov 20 '12 at 14:49
  • 1
    Whether `-mthumb` will generate Thumb-1 or Thumb-2 insns depends on how the compiler is built, for example in my ARM compilers the default ISA is ARMv7-A, so `-mthumb` alone generates 32-bit thumb mode insns. On the other hand, `-march=armv4t -mthumb` will pretty reliably do the right thing. – chill Nov 20 '12 at 15:46