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:
The source file must first be compiled.
The generated file must then be assembled.
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.
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.
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.
You can compile the program using the following command:
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.
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".
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:
The executable file is called hello2. We can run it on the simulator as follows: