User guide

9.2. THE CINTCODE INSTRUCTION SET 167
dlab to jump to the default label. See Section 9.1.3 for details on how resolving half
words are interpreted.
SWB filler n dlab K
1
L
1
. . . K
n
L
n
This instruction is used when the range of case constants is too large for SWL to be
economical. It performs the jump using a binary chop strategy. The quantities n, dlab,
K
1
to K
n
and L
1
to L
n
are 16 bit half words aligned on 16 bit boundaries by the
option filler byte. Th i s instruction successively tests A with th e case constants in the
balanced bi nar y tree given in the instruction. The tree is struct ur e d in a way similar
to that used in heapsor t with the children of the node at position i at positions 2i and
2i + 1. Ref er e nc es to nodes beyond n are treated as null pointers. Within this tree, K
i
is greater than all case constants in the tree ro ot ed at position 2i, and less than those
in the tree at 2i + 1. The search starts at p osi t i on 1 and continues until a matching
case constant is found or a null pointer is reache d. If A is equal to some K
i
then PC is
set using the resolving half word L
i
, otherwise it uses the resolving half word dlab to
jump to the default label. See Section 9.1.3 for detail s on how resolving half words are
interpreted.
The use of this structure is particularly good for the hand writte n machine code
interpreter for the Pentium where there are rather few central registers. Cunning use
can be made of the add with carry instruction (adcl). In the following fragment of
code, %esi points to n, %eax holds i and A is held in %eab. There is a test elsewhere
to ensure that A is in the range 0 to 65535.
swb1: cmpw (%esi,%eax,4),%bx ; { compare A with Ki
je swb3 ; Jump if A=Ki
adcl ; IF A>Ki THEN i := 2i
; ELSE i := 2i+1
cmpw (%esi),%ax ;
jle swb1 ; } REPEATWHILE i<=n
The compi l e r ensures t hat the tr e e always has at least 7 nodes allowing the code can
be further improved by preceeding this loop with two copies of:
cmpw (%esi,%eax,4),%bx ; compare Ki with A
je swb3 ; Jump if match found
adcl ; IF A>Ki THEN i := 2i
; ELSE i := 2i+1
The above code is a great improvement on any straightforward implementation of the
standard binary chop mechanism.
9.2.10 Miscellaneous
XCH Exchange A and B
ATB B := A
ATC C := A
BTC C := B