The previous chapter provided a detailed overview of the hardware that will support the execution of our parallel programs. Understanding how the transputer operates and how it accesses its resources is a must to fully understand how to use the parallel concepts that have been added to C by Logical Systems.
In this chapter we will write our first transputer program and will look in details at the process transforming the source file containing C code into machine code executed by the [PC host, root transputer] system. Remember that running a program on the transputer requires running two programs: One on the host, and the other on the transputer network. With the help of batch files, the automation will make writing and running programs a smooth task. The software is an ANSI C compiler augmented with libraries written by Logical Systems to support parallel constructs. The package contains the standard preprocessor, compiler, assembler and linker programs that most C programmers will be familiar with, but also new utilities, such as a loader and a host driver, required by the parallel environment. We will look at each one with more or less scrutiny. Each program is covered in great technical detail in Logical Systems' C93.1 User Manual [CSA93].
Our first program is simple and is intended to run only on one transputer, the root transputer, also referred to as the PC/Link transputer. Although it seems that any other transputer in the network could have been just as good a target, we will see later that we have very little choice in this matter. We cannot run a program on an isolated transputer in the network without involving the root transputer. The reason is that any information exchanged between the PC and a transputer must flow through the root transputer [1] . The program is shown below.
/* =======================================================================
first.c
DESCRIPTION:
Gets two integers from user and displays their sum.
Tutorial program from Chapter 3.
====================================================================== */
#include <stdio.h>
#include <stdlib.h>
/* -------------------------------------------------------------------- */
/* MAIN */
/* -------------------------------------------------------------------- */
main()
{
int a, b;
printf("Enter two integers, a and b:\na: ");
scanf("%d", &a);
printf("b: ");
scanf("%d", &b);
printf("%d + %d = %d\n\n", a, b, a+b);
exit(0);
}
It looks exactly like any C program written for the PC. In fact, it would compile without errors by any ANSI C compiler. The difference lies in the process of compiling, assembling, linking, loading, and running it. These operations are illustrated in Figure 3-1. The process is a five-step operation which takes the original file first.c and passes it through a preprocessor (1), a compiler (2), an assembler (3), a linker (4), and a loader (5), this last one loads the code in the transputer network and starts its execution.
This section describes the process illustrated in Figure 3.2 and shows the commands required to execute each step. We assume here that the Logical Systems software is installed correctly, and that the PC environment has been set up properly. The compilation process requires that several DOS environment variables be set: PATH, PPINC, TLIB, and LINKNAME.

Figure 3- 1: The process of
running a transputer program written in LS C.
The compiler is the combination of a preprocessor, PP, and a cross-compiler, TCX. The PP preprocessor conforms to the ANSI standard. Its function is to read the file containing the original C program and to generate a new file, containing any file inclusion, macros expansion, and conditional compilation present in the original code. The syntax for invoking the preprocessor is:
where [-options] represents various switches controlling the execution of the preprocessor. In our case, we preprocess first.c with the command:
C:\ pp first.c
which takes the file first.c as input an outputs first.pp. The partial contents of the file first.pp is shown below.
#line 1 "first.c"
#line 22
#line 1 "D:\LSC\INCLUDE/stdio.h"
#line 15
typedef int FILE;
typedef unsigned int fpos_t;
typedef unsigned int size_t;
typedef char *va_list;
#line 26
extern int errno;
#line 39
extern FILE _fio[];
#line 45
void clearerr(FILE *stream);
int close(int handle);
[...]
long int strtol( char *nptr, char **endptr, int base);
unsigned long int strtoul( char *nptr, char **endptr, int base);
int system( char *string);
#line 24 "first.c"
main()
{
int a, b;
printf("Enter two integers, a and b:\n: ");
scanf("%d", &a);
printf("b: ");
scanf("%d", &b);
printf("%d + %d = %d\n\n", a, b, a+b);
exit(0);
}
Listing 3-2: Partial contents of first.pp file.
Upon successful preprocessing of the program, the file with the .pp extension is passed to the compiler for processing.
Here again [-options] represents various switches controlling the compilation. One option that we will use from time to time is -c, which forces the compiler to compress the output file by removing any debugging information. Clearly we will do this only when we have a high certainty that the program is correct, in an effort to save disk storage and loading time.
C:\ tcx first
By default the compiler outputs a file with the same name as the input file, but with the extension .tal. This file contains transputer assembly code corresponding to the original program. The next step is for it to be fed to the assembler.
Tasm is the assembler provided by Logical Systems. It can be used as a stand-alone assembler to process user-written programs, or as an addition to the tcx compiler to generate transputer code. The assembler is a multi-pass, relocating assembler. Multi-pass means that the assembler scans the input file several times in order to resolve jump and prefix instructions that cannot be determined completely without knowledge of instructions located further down in the source file. The relocating property means that the output of the assembler is not associated with any fixed memory addresses, and can be "moved" to any memory location by the linker. The syntax of the tasm assembler is:
where [-options] controls how the assembler operates. Most of these options are described in great detail in the Logical Systems documentation [CSA93]. Because tasm operates after tcx, we will use the -t option, which instructs tasm not to count the source lines as it would for a user- generated program, but to count only the #line pragmas generated by the compiler.
A useful option is -c, which forces the assembler to compress its output file by not including debugging information. Clearly we will do this only when our programs will have been thoroughly tested. The -c option economizes disk storage by yielding a smaller code file and increases executing speed by reducing the loading time. The command line will look something like this:
C:\ tasm first -t
or
C:\ tasm first -ct
if the debugging information is to be removed from the output file. The file output by tasm has a .trl extension (transputer relocatable). The next step for this file is to be linkedwith other modules by the linker[2] .