Chapter 1. Basic Techniques

Table of Contents
1.1. Hello World
1.2. Compiler Options
1.3. Simulator Options
1.4. What's in my Program

We'll start by writing a short program. Then we'll compile it and run it on the target CPU simulator. The defaults for compiler options mean you can quickly become productive.

Three steps are needed to create an executable file from a Coral 66 source file:

  1. The source file must first be compiled.

  2. The generated file must then be assembled.

  3. All appropriate object files must be linked to produce an executable image file.

All three steps are best handled by using the gcc program, which calls the Coral 66 compiler, and automatically performs the necessary assembly and link steps.

1.1. Hello World

The program will be hello.cor, which will use a library function to write the message "Hello World" to the terminal. You will find the source code on the distribution CD-ROM in the directory examples.

1.1.1. How to Prepare a Coral 66 Program

Any editor may be used to prepare a Coral 66 program. The program text is a normal text file with any of the usual end-of-line conventions. Keywords may be written in either case and are enclosed by apostrophe characters. Except in strings, spaces and other formatting characters are not significant.

We will suppose in our initial example that you have used your editor to prepare the following standard-format text file:

Example 1-1. Source code for Hello


'external' (
   'procedure' write (
      'value''integer', 'byte''array', 'value''integer');
)

'begin'
   'byte''array' Buf [1:12] := "Hello world", 10;

   write (1, Buf, 12);
'end'

This file should be named hello.cor. Using the default file naming conventions, the XGC Coral 66 compiler requires that each file contains a single Coral 66 segment and has a filename extension that is either .cor or .c66. Filenames in upper case are equally valid.

Note: The external procedure write is provided by the object code library libc.

1.1.2. How to Compile

You can compile the program using the following command:


$ m68k-coff-gcc hello.cor -o hello

The command m68k-coff-gcc is used to access the compiler. This command is capable of compiling programs in several languages including Coral 66, C, assembly language and object code. It determines you have given it a Coral 66 program by the filename extension (.cor or .c66), and calls the Coral compiler to compile the specified file.

The result is an executable file called hello.

1.1.3. How to Run a Program on the Simulator

The program that we just built can be run on the simulator using the following command. If all has gone well, you will see the message "Hello World".


$ m68k-coff-run hello
Hello World

1.1.4. The Coral Input-Output Package

We will now modify hello.cor to use the Coral 66 Input-Output functions provided by the file coralio.cor. You will find this file on the CD-ROM in directory examples.

The modified file looks like this:

Example 1-2. Source code for Hello2


'common' (
   'procedure' outstring ('value''integer','value''integer');
   'procedure' outnewline ('value''integer');
)

'begin'
   outstring (1, "Hello World");
   outnewline (1);
'end'

We can compile both the main source file and the file coralio.cor with the same command as follows:


$ m68k-coff-gcc hello2.cor coralio.cor -o hello2

The executable file is called hello2. We can run it on the simulator as follows:


$ m68k-coff-run hello2
Hello World