Getting Started with M68K Coral 66: Compilation System for the Motorola M68000 Family | ||
---|---|---|
Prev | Chapter 1. Basic Techniques | Next |
If a source file contains errors, then it is useful to get a listing that shows the source with the error messages clearly pointing to the errors. The following example shows how get to get source listing from the compiler.
Example 1-3. Source Code Listing
$ m68k-coff-gcc -c --list bad-hello.cor XGC CORAL66 Compiler Version 1.7 Compiling: bad-hello.cor (time stamp: 2001/11/02 11:23:18) 1. 'external' ( 2. 'procedure' write ('value''integer', 'byte''array', 'value''integer'); 3. ) 4. 5. 'begin' 6. 'byte''array' Buf [1:12] := "Hello world", 10; 7. 8. write (1, Buff, 12); 12 >>> error: Parameter must refer to an array >>> error: "Buff" is not declared 9. 'end' 10.
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 m68k-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 that shows the generated code with the assembled machine code.
Example 1-4. Machine Code Listing
$ m68k-coff-gcc -c -Wa,-a hello.cor 68K GAS /tmp/ccYwbyC9.s page 1 1 .file "hello2.cor" 2 gcc2_compiled.: 3 __gnu_compiled_c66: 4 .section .rdata,"r" 5 .LC0: 6 0000 4865 6C6C .ascii "Hello World\0" 6 6F20 576F 6 726C 6400 7 .text 8 .even 9 .globl main 10 main: 11 0000 4E56 0000 link.w %a6,#0 12 0004 4879 0000 pea .LC0 12 0024 13 000a 4878 0001 pea 1.w 14 000e 4EB9 0000 jsr outstring__Fii 14 0000 15 0014 4878 0001 pea 1.w 16 0018 4EB9 0000 jsr outnewline__Fi 16 0000 17 001e 7000 moveq.l #0,%d0 18 0020 4E5E unlk %a6 19 0022 4E75 rts ...
We can list the source, generated code and machine code together, as in the following example:
Example 1-5. Machine Code Listing with Interleaved Source
$ m68k-coff-gcc -c -g -Wa,-ahld coralio.cor ... 49:coralio.cor **** 'comment' Output one character to the operating system; 50:coralio.cor **** 51:coralio.cor **** 'procedure' outchar ('value''integer' file, char); 18 .LM1: 19 0000 4E56 0000 link.w %a6,#0 20 .LBB2: 52:coralio.cor **** 'begin' 53:coralio.cor **** 'byte''array' buf [0:0]; 54:coralio.cor **** 55:coralio.cor **** buf [0] := char; 22 .LM2: 23 0004 41F9 0000 lea buf.0,%a0 23 014A 24 000a 10AE 000F move.b 15(%a6),(%a0) 56:coralio.cor **** write (1, buf, 1); 26 .LM3: 27 000e 4878 0001 pea 1.w 28 0012 2F08 move.l %a0,-(%sp) 29 0014 4878 0001 pea 1.w 30 0018 4EB9 0000 jsr write 30 0000 31 .LBE2: 32 001e 4E5E unlk %a6 33 0020 4E75 rts ...
Here is another example using the object code dump utility.
Example 1-6. Disassembling Object Code
$ m68k-coff-objdump -d -l hello2 hello2: file format coff-m68k Disassembly of section .text: 00000400 <_stext>: 400: 227c 0000 1508 moveal #5384,%a1 406: 207c 0010 0000 moveal #1048576,%a0 40c: 203c 0010 0004 movel #1048580,%d0 412: 9088 subl %a0,%d0 414: 6f08 bles 41e <_stext+0x1e> 416: 20d9 movel %a1@+,%a0@+ 418: 5980 subql #4,%d0 41a: 4a80 tstl %d0 ...lots of output...
You can see how big your program is using the size command. The sizes are in bytes.
The names "text", "data" and "bss" refer to program sections as follows.
The text section contains executable instructions
The data section contains program variables and other initialized data
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. Section Headers
$ m68k-coff-objdump -h hello2 hello2: file format coff-m68k Sections: Idx Name Size VMA LMA File off Algn 0 .init 00000400 00000000 00000000 00002000 2**2 CONTENTS, ALLOC, LOAD, READONLY 1 .text 00000ecc 00000400 00000400 00002400 2**2 CONTENTS, ALLOC, LOAD, CODE 2 .rdata 0000023c 000012cc 000012cc 000032cc 2**2 CONTENTS, ALLOC, LOAD, CODE 3 .data 00000004 00100000 00001508 00004000 2**2 CONTENTS, ALLOC, LOAD, DATA 4 .bss 00000144 00100004 00100004 00000000 2**2 ALLOC 5 .stab 00002f28 00000000 00000000 00004004 2**2 CONTENTS, DEBUGGING, NEVER_LOAD 6 .stabstr 00000eea 00000000 00000000 00006f2c 2**0 CONTENTS, DEBUGGING, NEVER_LOAD $