User guide

146 CHAPTER 8. THE DESIGN OF OCODE
example, if the file test.b is the following:
GET "libhdr"
LET start() BE { LET a, b, c = 1, 0, -1
writef("Answer is %n*n", a+b+c)
}
then the command: bcpl test.b would write the following text to the file ocode.:
85 2 94 1 5 115 116 97 114 116 95 3 42 1 42 0 42 -1 92 91 9 43
13 65 110 115 119 101 114 32 105 115 32 37 110 10 40 4 40 3 14
40 5 14 41 74 51 6 97 91 3 103 91 3 90 2 92 76 1 1 1
These numbers encode the OCOD E statements in a natural way as can be verified
by comparing them wi th the following more readable form of the same statements,
generated by the procode command:
JUMP L2
ENTRY L1 5 ’s’ ’t’ ’a’ ’r’ ’t’
SAVE 3 LN 1 LN 0 LN -1 STORE STACK 9
LSTR 13 ’A’ ’n’ ’s’ ’w’ ’e’ ’r’ ’ ’ ’i’ ’s’ ’ ’ ’%’ ’n’ 10
LP 4 LP 3 PLUS LP 5 PLUS LG 74 RTAP 6 RTRN STACK 3
ENDPROC STACK 3 LAB L2 STORE GLOBAL 1 1 L1
8.2 The O CO DE Abs tr a ct Machine
OCODE was speci fic al l y designed for BCPL and is a compromise b e tween the desire
for s i mpl i c i ty and the conflicting demands of efficiency and machine independence.
OCODE is an assembly language for an abstract stack based machine that has a global
vector and an area of memory for program and static data as shown in figure 8.2.
G
S
P
Li Lj
Memory for program and static data
Global vector Current stack frame
Figure 8.2: The BCPL abstract machine
The global vector is pointed to by the G pointer and the current stack frame is
pointed to by the P pointer. S is the size of the current stack frame, and so P!S is the
first free element of the stack. The value of S is always known during compilation and
so is not held in a register of the OCODE abstract machine machine. Any assignments