User guide
184 CHAPTER 10. THE DESIGN OF SIAL
The call cvfpg("KPG") reads the Sial stateme nt knowing it is of the form: KPG
Pk Gn. This outputs the statement as an asse mbly language comment after placing k
and n in pval and gval, respectively. The three writef calls then output the three
assembly language instructions for the KPG operati on , and ENDCASE transfers control to
where the next Sial statement is processed. All the other cases are equally simple.
The secti on name of the program, whi ch must be present, compi l es into a C callable
function that initialises the BCPL global vector with the entry points defined within
this mo dul e . To complete the 386 implementation, ther e is a short handwritten assem-
bly language library natbcpl/sysasm/mlib.s that defines the BCPL callable func-
tions sys, changeco and muldiv. The program must be linked the compiled ver-
sions of the B CPL library modules BLIB and DLIB, and also clib whose source is
in natbcpl/sysc/clib.c and a program typically called initprob.c that defines
the function initsections to invoke all the global initialisation functions. The file
initprog.c is nor m al l y created by a call such as:
makeinit prog.b to initprog.c
The resulting initprog.c is typically:
// Initialisation file written by makeinit version 2.0
#include "bcpl.h"
WORD stackupb=50000;
WORD gvecupb=1000;
// BCPL sections
extern BLIB(WORD *); // file (run-time library)
extern DLIB(WORD *); // file (system dependent library)
extern prog(WORD *); // file prog.b
void initsections(WORD *g) {
BLIB(g); // file (run-time library)
DLIB(g); // file (system dependent library)
prog(g); // file prog.b
return;
}
A later version of this program called sial-686.b includes the compilation of t he
floating point instructions and also does a little peephole optimisation which has become
necessary since integer and floati n g point registers are distinct on i386 machi n es . This
translator assumes that the target machine is a Pentium Pro or later, but this only
matters if floating point instructions are being comp i l ed . There are comments in the
program explaining how the peephole optimisation works.