ST20-C1 STMICROELECTRONICS [STMicroelectronics], ST20-C1 Datasheet - Page 180

no-image

ST20-C1

Manufacturer Part Number
ST20-C1
Description
Instruction Set Reference Manual
Manufacturer
STMICROELECTRONICS [STMicroelectronics]
Datasheet
C.2
The switch statement is a special form of conditional transfer where the transfer is
determined by comparing an expression to a number of constants.
When compiling the process
the expression x is evaluated and stored in a local variable by
Then each branch of the switch statement
can be compiled by
where the label END: is placed at the end of the switch statement.
C.2.3 Optimal compilation of switch
The compilation method given above will produce inefficient code for large switch
statements. To produce more efficient code the following rules can be used.
First build up a set of pairs of selector values and processes, consisting of every
selector value in the switch statement along with its associated process — the
process part of each pair can be represented by the offset to the start of the compiled
code for that process. Then the following rules can be used.
The choice of 3 or less entries, 12 or less entries and one third filled tab le are the
values used in current ST20 compilers.
180/205
1
2
3
Compiling switch statements
switch x
x; stl selector
c
L:
M:
If there are 3 entries or less then use the method as described above.
If there are 12 entries or less then use a binary search to limit the number of
comparisons required.
For more than 12 entries attempt to use a jump table. The offset of the start of
each selected process is placed in the table against each selector value.
Entries that do not match a selector in the switch statement must contain the
offset of an error handler process. This jump table should be the largest table
such that about one third of the entries are filled. This compilation strategy is
then recursively called to handle the two ends. The jab (section 4.10) and ldpi
(section 4.5) instructions, can be used to jump to the selected piece of code.
1
, ..., c
...
ldl selector; ldc c
ldl selector; ldc c
...
ldl selector; eqc c
P; j END;
P
n
1
2
n
; sub; cj L;
; sub; cj L;
; cj M;

Related parts for ST20-C1