1.3. Compiler Options

If you want to see the generated code, then use 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 erc-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 we generate a machine code listing.

Example 1-4. Generating a Machine Code Listing

$ erc-coff-gcc -Wa,-a hello.c -o hello
GAS-ERC  /tmp/cca00558.s                        page 1
   1                            .file  "hello.c"
   2                    gcc2_compiled.:
   3                    __gnu_compiled_c:
   4                            .section .rodata,"r"
   5                            .align  8
   6                    .LC0:
   7 0000 48656C6C              .ascii "Hello world\12\0"
   7      6F20776F
   7      726C640A
   7      00
   8 000d 000000                .text
   9                            .align  4
  10                            .global main
  11                            .proc   04
  12                    main:
  13 0000 9DE3BF98              save    %sp,-104,%sp
  14 0004 11000000              sethi   %hi(.LC0),%o0
  15 0008 40000000              call    printf,0
  16 000c 90122000              or      %o0,%lo(.LC0),%o0
  17 0010 81C7E008              ret
  18 0014 81E80000              restore
...more output...

Here is another example using the object code dump utility.

Example 1-5. Output from objdump

$ erc-coff-objdump -d hello
hello:     file format coff-erc
Disassembly of section .text:
02000000 <_stext>:
 2000000:       10 80 05 8d     b  2001634 <__start>
 2000004:       01 00 00 00     nop
 2000008:       01 00 00 00     nop
 200000c:       01 00 00 00     nop
 2000010:       a1 48 00 00     rd  %psr, %l0
 2000014:       29 00 80 04     sethi  0x8004, %l4
 2000018:       81 c5 22 dc     jmp  %l4 + 0x2dc
 200001c:       a6 10 20 0b     mov  0xb, %l3
 2000020:       a1 48 00 00     rd  %psr, %l0
 2000024:       29 00 80 04     sethi  0x8004, %l4
 2000028:       81 c5 22 dc     jmp  %l4 + 0x2dc
 200002c:       a6 10 20 04     mov  4, %l3
 2000030:       a1 48 00 00     rd  %psr, %l0
...lots of output...

You can see how big your program is using the size command. The sizes are in bytes. Note that the UNIX command ls -s gives you the size of the file rather than the size of the executable program.

Example 1-6. Using the size command

$ erc-coff-size hello.o
   text    data     bss     dec     hex filename
     48       0       0      48      30 hello.o
$ erc-coff-size hello
   text    data     bss     dec     hex filename
  12368       8     536   12912    3270 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.

Example 1-7. Using the Object Code Dump Program

$ erc-coff-objdump -h hello

hello:     file format coff-erc

Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 .init         00000118  00000000  00000000  00001000  2**3
                  CONTENTS, CODE, NEVER_LOAD
  1 .text         00002c88  02000000  02000000  00002000  2**2
                  CONTENTS, ALLOC, LOAD, CODE
  2 .rodata       000003c8  02002c88  02002c88  00004c88  2**3
                  CONTENTS, ALLOC, LOAD, READONLY
  3 .data         00000008  02100000  02003050  00006000  2**3
                  CONTENTS, ALLOC, LOAD, DATA
  4 .bss          00000218  02100010  02100010  00000000  2**3
                  ALLOC
  5 .stab         00002610  00000000  00000000  00006008  2**2
                  CONTENTS, DEBUGGING, NEVER_LOAD
  6 .stabstr      00002595  00000000  00000000  00008618  2**0
                  CONTENTS, DEBUGGING, NEVER_LOAD
$ 

By default, the compiler generates a program that will run on the standard target board (the Temic Starter Kit), or on the simulator. If you wish to run on the XGC monitor, or on some other board then you will need to specify the memory layout and other parameters. These topics are covered in Chapter 2.