User guide
8.9. DISCUSSION 153
Static variables and tables are allocated space in the program area using statements
of the form ITEMN n, where n is the ini ti al value of the static cell . The el em ents of
table are placed in consecutive locations by consective ITEMN statements. A label may
be set to the address of a static cell by preceding the ITEMN statement by a statement
of the form DATALAB Ln.
The SECTION and NEEDS directives in a BCPL program translate into SECTION and
NEEDS statements of the form:
SECTION n C
1
. . . C
n
NEEDS n C
1
. . . C
n
where C
1
to C
n
are the characters of the SECTION or NEEDS name and n is the length.
The end of an OCODE module is marked by the GLOBAL s tat em ent which con-
tains information about global functions, routines and labels. The form of the GLOBAL
statement is as follows:
GLOBAL n K
1
L
1
. . . K
n
L
n
where n is the number of i te ms in the global initialisation list. K
i
is the global number
and L
i
is its label. When a module is loaded its gl obal entry points must be initialised.
8.9 Discussion
A very early version of OCODE used a three address code in which the operands were
allowed to be the sum of up to three simple values with a possible indirection. The
intention was that reasonable code shoul d be obtai nabl e even when codegenerating
one statement at a time. It was soon found more convenient to use an intermediate
code that separates the accessing of values from the application of operators. This
improved portability by making it possible to implement very simple non optimising
codegenerators. O pt i mi s i ng codegenerators could absorb several OCODE statements
before emitting compiled code.
The TRUE and FALSE statements were added in 1968 to improve portability to
machines using sign and modulus or one’s complement arithmetic. Luckily two’s com-
plement arith me ti c has now become the norm. Other extensions t o OCODE, notably
the ABS, QUERY, GETBYTE and PUTBYTE statements were added as the corresponding
constructs app ear e d in the language.
In 1980, the BCPL changed slightly to p e r mi t p os i ti on independent code to be
compiled. This change specified that non global functions, routines and l abels were
no longer variable s, and the current version of OCODE reflects this change by the
introduction of the LF statement and t he removal of the old ITEML statement that used
to allocate static cells for such entry points.
Another minor change in this version of OCODE is the elimination of the ENDFOR
statement that was provided to fix a problem on 16-bit word addressed machines with
more than 64 Kbytes of memory.