Chapter 1. Basic Techniques

Table of Contents
1.1. Hello World
1.2. Using the Simulator
1.3. Compiler Options
1.4. What's in My Program?

This chapter describes how to use the GCC-ERC32 development tools to build and run a simple application program written in ANSI C.

1.1. Hello World

Two steps are needed to create an executable file from a C or C++ source file:

  1. The source file must first be compiled.

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

For a simple program, both steps are best handled using the program erc-coff-gcc, which is able to compile the source files, and automatically link the generated object code with any necessary startup and library code.

For a large program, you may wish to call the linker directly, possibly under the control of a make file.

1.1.1. Preparing a Simple C Program

Any editor may be used to prepare the C source files. The popular editor vi is sensitive to some of the syntax of the C language, and can be of enormous help once you have mastered its command repertoire. We also recommend the program indent which is able to rescue a badly formatted program and make it readable.

The program text is a normal text file with any of the common conventions for the end of line. We will suppose in our initial example that you have prepared the following text file:

Example 1-1. The Source File

#include <stdio.h>

int main ()
{
  printf ("Hello world\n");
}

This file should be named hello.c. Using the GCC file naming conventions, GCC-ERC32 requires that each file has a name extension that identifies the contents of the file to the compiler.

File name extensions that GCC-ERC32 recognizes are given in the following table:

Table 1-1. Filename Extensions

ExtensionFile contentsCompiler action
.cC sourcepre-process, compile, assemble
.CC++ sourcepre-process, compile, assemble
.ccC++ sourcepre-process, compile, assemble
.cxxC++ sourcepre-process, compile, assemble
.cppC++ sourcepre-process, compile, assemble
.ipre-processed Ccompile, assemble
.iipre-processed C++compile, assemble
.sAssembler sourceassemble
.SAssembler sourcepre-process, assemble
.oObject codelink
.aObject code archivelink

1.1.2. How to Compile

You can compile the file hello.c using the following command:

Example 1-2. The Compile Command

$ erc-coff-gcc hello.c -o hello

The command erc-coff-gcc is the command used to access the C compiler. It determines you have given it a C language source file by the extension (.c), and will call the C compiler to compile the specified file.

The compiler is configured so that there are defaults for the start file and the libraries. This means that code will be linked into your application program to initialize the stack and to support the call of library function printf.