126 Chapter Five
implement. The basic algorithm of the function is the same as the fourval
resolution function; however, the operations with nine values are a little
more complex. Function resolve9still does a pairwise comparison of the
input values to determine the resultant value. With a nine-value system,
the comparison operation is more complicated, and therefore some constant
arrays were declared to make the job easier.
The constant get_strengthreturns the driving strength of the driver
value. The constant x_tabreturns the appropriate unknown nine-state
value, given the strength of the input. These constants could have been
implemented as IFstatements or CASEstatements, but constant arrays
are much more efficient.
In the nine-value system, there are three values at the lowest strength
level, so the variable result has to be initialized more carefully to predict
correct results. If there are no drivers, the range attribute of argument s
returns 0, and the default value (ZX) is returned.
Let’s look at a few examples of driver-input arguments and see what
the resolution function predicts. An example of two drivers is shown in
Figure 5-4.
This example contains two driver values,Z1and R0. Variable resultis
initialized to the first driver value, and the loop executes as many times
as there are drivers. The first time through the loop,resultequals Z1and
the first driver equals Z1. Variable resultremains at Z1because the
values are equal. The next time through the loop, variable resultcon-
tains Z1, and the second driver contains R0. The constant get_strength
returns strength R. The constant get_strengthfor variable resultreturns
strength Z. Strength Ris lexically greater than strength Z. This is because
value Rhas a higher position number than Z, because Ris listed after Z
in the type declaration for type strength. The fact that the new driver has
Driver Values
Initial
Value
Z1 Z1 R0
Z1
R0 Resultant Value
Figure 5-4
Nine State Resolution
with Two Values.