User guide
152 CHAPTER 8. THE DESIGN OF OCODE
E1 E2 En E
S
P
Old stack frame New stack frame
k
Figure 8.4: The moment of calling E(E1,E2,...En)
8.7 Control
The statement LAB Ln set the value of label Ln to the current position in the OCODE
program. An unconditional tr ansfe r to this label can be performed by the satement
JUMP Ln. Conditional jumps inspect the value on the top of th e stack P!(S-1). JT Ln
will make the jump if it is TRUE, and JF Ln will jump i f FALSE. The t ran sl ation of the
command GOTO E is the translation of E followed by the OCODE statement GOTO. It
thus takes the destination address from the top of the stack.
If the command RESULTIS E occurs in a context where the value of E is imme-
diately returne d as t he result of a function, it uses FNRN; but in other contexts, its
translation is code to evaluate E followed by a statement of the form RES Ln. This wil l
place the result in the special register (A) and jump to the label Ln, where a statement
of the for m RSTACK k will be present to accept the value and place it in P!k while
setting S to k + 1.
The OCODE statement:
SWITCHON n LdK
1
L
1
. . . K
n
L
n
is used in the compilations of switches. It makes a jump determined by the value on
the top of the stack. Its first argument (n) is the number of cases in the switch and the
second argument (Ld) is the the default l abel. K
1
to K
n
are the case c onst ants and L
1
to L
n
are the corresponding labels.
The FINISH statement is the compilation of the BCPL FINISH command. It is
converted into code equivalent to stop(0) by the code generator.
8.8 Directives
Sometimes the size of the stack frame changes other than in the course of expression
evaluation. This happens, for instance, when control leaves a blo ck in which local
variables were declared. The statement STACK s informs the code generator that the
size of the current stack frame is now s.
The STORE statem ent is used to inform the code gene r ator that the point separating
the decl ar at i ons and body of a block has been reached and that any anonymous results
on the stack are actually initiali s e d local variables and so should be stored in their true
stack locations.