2.3. Compiler Options

If you want to see the generated code, then compile with the option -Wa,-a. The first part (-Wa,) means pass the second part (-a) to the assembler. You could also use the object code dump utility m1750-coff-objdump to disassemble the generated code. If you compiled using the debug option -g then the disassembled instructions will be annotated with symbolic references.

Here is an example where the compiler generates a machine code listing.

$ m1750-coff-gcc -O2 -Wa,-a hello.c -o hello
GAS-1750  /tmp/cca00779.s                       page 1
   1                            .file  "hello.c"
   2                    gcc2_compiled.:
   3                    __gnu_compiled_c:
   4                            .section .rdata,"r"
   5                    .LC0:
   6 0000 0048 0065             .word    'H','e','l','l','o',' ','w','o'
   6      006C 006C 
   6      006F 0020 
   6      0077 006F 
   7 0010 0072 006C             .word    'r','l','d','\n',0
   7      0064 000A 
   7      0000 
   8                            .text
   9                    .global main
  10                    main:
  11 0000 9FEE                  pshm   r14,r14
  12 0002 81EF                  lr     r14,r15
  13 0004 8500 0009             lim    r0,.LC0
...more output...

Here is another example using the object code dump utility.

$ m1750-coff-objdump -d -l hello

hello:     file format coff-m1750

Disassembly of section .text:

00000080 <_stext>:
start():
/opt/xgc/m1750-coff/src/libc/crt0.c:79
      80:       85 f0 f7 ff     lim    r15,63487
      84:       e5 ee           xorr   r14,r14

00000086 <.LM4>:
/opt/xgc/m1750-coff/src/libc/crt0.c:84
      86:       85 10 80 00     lim    r1,32768

0000008a <.LM5>:
/opt/xgc/m1750-coff/src/libc/crt0.c:87
      8a:       83 20           lisn   r2,1
      8c:       85 00 80 00     lim    r0,32768
      90:       b1 01           sr     r0,r1
      92:       f1 02           cr     r0,r2
      94:       75 07           bez    7

...lots of output...

You can see how big your program is using the size command. The sizes are in bytes.

$ m1750-coff-size hello
text    data    bss     dec     hex     filename
5888    0       2       5890    1702    hello
$ 

The names “text”, “data” and “bss” refer to program sections as follows.

text

The text section contains executable instructions

data

The data section contains program variables and other initialized data

bss

The bss section contains program variables and other data initialized to zero

To get more detail you can use the object code dump program, and ask for headers.

$ m1750-coff-objdump -h hello

hello:     file format coff-m1750

Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 .init         00000000  00000000  00000000  00000000  2**1
                  ALLOC, LOAD
  1 .text         000012b4  00000080  00000080  00000148  2**1
                  CONTENTS, ALLOC, LOAD, CODE
  2 .rdata        0000044c  00001334  00001334  000013fc  2**1
                  CONTENTS, ALLOC, LOAD, READONLY
  3 .data         00000000  00010000  00001780  00000000  2**1
                  ALLOC, LOAD, DATA
  4 .bss          00000002  00010000  00010000  00000000  2**1
                  ALLOC
  5 .stab         000024cc  00000000  00000000  00001848  2**1
                  CONTENTS, NEVER_LOAD
  6 .stabstr      0000082e  00000000  00000000  00003d14  2**0
                  CONTENTS, NEVER_LOAD
$