Return to previous page Advance to next page
VHDL Reference Guide
Chapter 5: Sequential Statements

Assignment Statements and Targets

Use an assignment statement to assign a value to a variable or signal. The syntax follows.

target := expression; -- Variable assignment
target <= expression;   -- Signal assignment

target is a variable or signal (or part of a variable or signal, such as a subarray) that receives the value of the expression. The expression must evaluate to the same type as the target. See the “Expressions” section of the “Expressions” chapter for more information.

There are five kinds of targets.

The difference in syntax between variable assignments and signal assignments follows.

Simple Name Targets

The syntax for an assignment to a simple name (identifier) target follows.

identifier := expression;     -- Variable assignment
identifier <= expression;  -- Signal assignment

identifier is the name of a signal or variable. The assigned expression must have the same type as the signal or variable. For array types, all elements of the array are assigned values.

The following example shows assignments to simple name targets.

variable A, B: BIT;
signal C: BIT_VECTOR(1 to 4);

-- Target    Expression
A := '1'; -- Variable A is assigned '1'
B := '0'; -- Variable B is assigned '0'
C <= “1100"; -- Signal array C is assigned
-- bit value “1100"

Indexed Name Targets

The syntax for an assignment to an indexed name (identifier) target follows.

identifier(index_expression) := expression;   -- Variable assignment
identifier(index_expression) <= expression;   -- Signal assignment

identifier is the name of an array type signal or variable. index_expression must evaluate to an index value for the identifier array's index type and bounds but does not have to be computable (see the “Expressions” chapter), but more hardware is synthesized if it is not.

The assigned expression must contain the array's element type.

In the following example, the elements for array variable A are assigned values as indexed names.

variable A: BIT_VECTOR(1 to 4);

-- Target    Expression;
A(1) := '1'; -- Assigns '1' to the first element of array A.
A(2) := '1'; -- Assigns '1' to the second element of array A.
A(3) := '0'; -- Assigns '0' to the third element of array A.
A(4) := '0'; -- Assigns '0' to the fourth element of array A.

The example below shows two indexed name targets. One of the targets is computable, and the other is not. The figure following the example illustrates the corresponding design.

entity example5 3 is
   port (
      signal A, B: BIT_VECTOR(0 to 3);
      signal I: INTEGER range 0 to 3;
      signal Y, Z: BIT;
      );
end example5 3;

architecture behave of example5 3 is

begin
process (I, Y, Z)
begin

A    <= “0000";
B <= “0000";
A(I) <= Y; -- Noncomputable index expression
B(3) <= Z; -- Computable index expression

end process;
end behave

Figure 5.1 Design Illustrating Indexed Name Targets

Slice Targets

The syntax for an assignment to a slice target follows.

identifier(index_expr_1 direction index_expr_2)

identifier is the name of an array type signal or variable. Each index_expr expression must evaluate to an index value for the identifier array's index type and bounds. Both index_expr expressions must be computable (see the “Expressions” chapter) and must lie within the bounds of the array. The direction must match the identifier array type's direction, either to or downto.

The assigned expression must contain the array's element type.

In the following example, array variables A and B are assigned the same value.

variable A, B: BIT_VECTOR(1 to 4);
-- Target Expression;
A(1 to 2) := “11"; -- Assigns “11" to the first two elements of array A
A(3 to 4) := “00"; -- Assigns “00" to the last two elements of array A
B(1 to 4) := “1100";-- Assigns “1100" to array B

Field Targets

The syntax for a field target follows.

identifier.field_name

identifier is the name of a record type signal or variable. field_name is the name of a field in that record type, preceded by a period (.). The assigned expression must contain the identified field's type. A field can be any type, including an array, record, or aggregate type.

The following example assigns values to the fields of record variables A and B.

type REC is 
record
NUM_FIELD: INTEGER range -16 to 15;
ARRAY_FIELD: BIT_VECTOR(3 to 0);
end record;

variable A, B: REC;

-- Target        Expression;
A.NUM_FIELD := -12;
     -- Assigns -12 to record A's field NUM_FIELD
   A.ARRAY_FIELD := “0011";
     -- Assigns “0011" to record A's field ARRAY_FIELD
A.ARRAY_FIELD(3) := '1';
     -- Assigns '1' to the most significant bit of
     -- record A's field ARRAY_FIELD
   B := A;
-- Assigns values of record A to corresponding fields of B

For more information, see the “Record Types” section of the “Data Types” chapter.

Aggregate Targets

The syntax for an assignment to an aggregate target follows.

([choice => ] identifier
{,[choice =>] identifier}) := array_expression
;
   -- Variable assignment

([choice =>] identifier
{,[choice =>] identifier}) <= array_expression
;
   -- Signal assignment

aggregate assignment assigns the array_expression element values to one or more variable or signal identifiers.

Each (optional) choice is an index expression selecting an element or a slice of the assigned array_expression. Each identifier must have the element type of array_expression element type. An identifier can be an array type.

You can assign array element values to the identifiers by position or by name. In positional notation, the choice => construct is not used. Identifiers are assigned array element values in order, from the left array bound to the right array bound.

In named notation, the choice => construct identifies specific elements of the assigned array. A choice index expression indicates a single element, such as 3. The type of identifier must match the assigned expression's element type.

Positional and named notation can be mixed, but positional associations must appear before named associations, as in the following example.

signal A, B, C, D: BIT;
signal S: BIT_VECTOR(1 to 4);
. . .
variable E, F: BIT;
variable G: BIT_VECTOR(1 to 2);
variable H: BIT_VECTOR(1 to 4);

-- Positional notation 
S <= ('0', '1', '0', '0');
(A, B, C, D) <= S; -- Assigns '0' to A
-- Assigns '1' to B
-- Assigns '0' to C
-- Assigns '0' to D
-- Named notation
(3 => E, 4 => F,
2 => G(1), 1 => G(2)) := H;
-- Assigns H(1) to G(2)
-- Assigns H(2) to G(1)
-- Assigns H(3) to E
-- Assigns H(4) to F