| Getting Started with LEON Ada: Ada 95 Compilation System for Spacecraft Microprocessors | ||
|---|---|---|
| Prev | Chapter 1. Basic Techniques | Next |
If you want to see the generated code, then use the compiler option
-Wa,-a. The first part (-Wa,) means pass
the second part (-a) to the assembler. To get a listing
that includes interleaved source code, use the options -g
and -Wa,-ahld. See The LEON Ada Users
Guide, for more information on assembler options.
Here is an example where we generate a machine code listing.
Example 1-6. Generating a Machine Code Listing
$ leon-coff-gcc -c -O2 -Wa,-a hello.adb 1 .file "hello.adb" 2 gcc2_compiled.: 3 __gnu_compiled_ada: 4 .section .rodata,"r" 5 .align 8 6 .LC0: 7 0000 48656C6C .ascii "Hello World" 7 6F20576F 7 726C64 8 000b 00 .align 4 9 .LC1: 10 000c 00000001 .long 1 11 0010 0000000B .long 11 12 0014 00000000 .text 13 .align 4 14 .global _ada_hello 15 .proc 020 16 _ada_hello: 17 0000 9DE3BF90 save %sp,-112,%sp 18 0004 80A38007 cmp %sp,%g7 19 0008 89D02009 tleu 9 20 000c 15000000 sethi %hi(.LC0),%o2 21 0010 9012A000 or %o2,%lo(.LC0),%o0 22 0014 15000000 sethi %hi(.LC1),%o2 23 0018 9212A000 or %o2,%lo(.LC1),%o1 24 001c D03FBFF0 std %o0,[%fp-16] 25 0020 40000000 call ada__text_io__put_line$2,0 26 0024 9007BFF0 add %fp,-16,%o0 27 0028 81C7E008 ret 28 002c 81E80000 restore ...
You could also use the object code dump utility
leon-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 using the object code dump utility.
Example 1-7. Output from objdump
$ leon-coff-objdump -d hello.o hello.o: file format coff-erc Disassembly of section .text: 00000000 <_ada_hello>: 0: 9d e3 bf 90 save %sp, -112, %sp 4: 80 a3 80 07 cmp %sp, %g7 8: 89 d0 20 09 tleu 9 c: 15 00 00 00 sethi %hi(0), %o2 10: 90 12 a0 00 mov %o2, %o0 ! 0 <_ada_hello> 14: 15 00 00 00 sethi %hi(0), %o2 18: 92 12 a0 00 mov %o2, %o1 ! 0 <_ada_hello> 1c: d0 3f bf f0 std %o0, [ %fp + -16 ] 20: 40 00 00 00 call 20 <_ada_hello+0x20> 24: 90 07 bf f0 add %fp, -16, %o0 28: 81 c7 e0 08 ret 2c: 81 e8 00 00 restore
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-8. Using the Size Command
$ leon-coff-size hello.o
text data bss dec hex filename
72 0 0 72 48 hello.o
$ leon-coff-size hello
text data bss dec hex filename
16008 464 624 17096 42c8 hello
$
To get more detail you can use the object code dump program, and ask for headers.
Example 1-9. Using the Object Code Dump Program
$ leon-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 00003dc0 02000000 02000000 00002000 2**2
CONTENTS, ALLOC, LOAD, CODE
2 .rodata 000000c8 02003dc0 02003dc0 00005dc0 2**3
CONTENTS, ALLOC, LOAD, READONLY
3 .data 000001d0 02100000 02003e88 00006000 2**3
CONTENTS, ALLOC, LOAD, DATA
4 .bss 00000270 021001d0 021001d0 00000000 2**3
ALLOC
5 .stab 0000516c 00000000 00000000 000061d0 2**2
CONTENTS, DEBUGGING, NEVER_LOAD
6 .stabstr 000064a2 00000000 00000000 0000b33c 2**0
CONTENTS, DEBUGGING, NEVER_LOAD
$