next up previous contents
Next: Iteratively constructing vectors Up: Vectors and vector operators Previous: Assignments to arrays   Contents

Vectors as inputs and outputs

The above rules regarding vector assignments have consequences when vectors are passed as parameters to modules. For example, suppose we have a module:

        MODULE foo(x)
        {
          INPUT x : array 1..0 of boolean;
          ...
        }
Suppose we create an instance of ``foo'' as follows:

        bar : foo(y);
This is equivalent to:

        bar.x : array 1..0 of boolean;
        bar.x := y;
        ...

The meaning of this depends on whether ``y'' is big-endian or little endian. If ``y'' is declared in the same order as ``bar.x'':

        y : array 1..0 of boolean;
then we have

        bar.x[1] := y[1];
        bar.x[0] := y[0];

On the other hand, if ``y'' is in the opposite order:

        y : array 0..1 of boolean;
then

        bar.x[1] := y[0];
        bar.x[0] := y[1];

That is, passing a ``big-endian'' array to a ``little-endian'' parameter, results in a reversal of the index order of the elements. What remains constant is the value as a binary number.

Note that as a result of the above rules for vector assignment, inputs may be truncated, or zero-extended. For example, if we instantiate ``foo'' as follows:

        bar : foo([0,1,0]);
the effect will be

        bar.x[1] := 1;
        bar.x[0] := 0;
since the vector [0,1,0] will be truncated to [1,0]. On the other hand,

        bar : foo([1]);
will give us

        bar.x[1] := 0;
        bar.x[0] := 1;
since the integer 1 will be coerced to the vector [0,1].

The same remarks apply to outputs. That is, suppose we have a module

        MODULE zip(y)
        {
          OUTPUT y : array 1..0 of boolean;
          ...
        }
An instance

        bar : zip(x);
is equivalent to

        bar.y : array 1..0 of boolean;
        x := bar.y;

This means that if ``x'' has length shorter than ``bar.y'', then ``x'' will get the low order bits of ``bar.y''. Similarly, if ``x'' is longer, then it will get ``bar.y'' extended with zeros. If ``x'' is an array declared in the opposite order to ``bar.y'', then ``x'' will get ``bar.y'' reversed, and so on.


next up previous contents
Next: Iteratively constructing vectors Up: Vectors and vector operators Previous: Assignments to arrays   Contents
2002-10-28