Chapter 2. Basic Techniques

Table of Contents
2.1. Hello World
2.2. Using the Simulator
2.3. Compiler Options
2.4. Simulator Options

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

The first steps will be as follows:

  1. Write a small program (hello world)

  2. Compile the program for the target M1750

  3. Run the program on the M1750 simulator

Before you use GCC-1750 on your application code, we recommend that you read about optimizations. See Section 3.2.

2.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 compiler, which is able to compile the source files, and automatically link the generated object code with any necessary startup and library code.

2.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 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 used your editor to prepare the following text file:

#include <stdio.h>

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

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

2.1.2. Compiling a Simple Program

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

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

The command m1750-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.

File name extensions that GCC-1750 recognizes are as follows:

.c C source pre-process, compile, assemble
.C C++ source pre-process, compile, assemble
.cc C++ source pre-process, compile, assemble
.cxx C++ source pre-process, compile, assemble
.cpp C++ source pre-process, compile, assemble
.i pre-processed C compile, assemble
.ii pre-processed C++ compile, assemble
.s Assembler source assemble
.S Assembler source pre-process, assemble
.h Header file not usually named on command line

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 printf.