Main Content

Guidelines for Using Assignment Blocks to Write Elements in Vectors, Matrices, and 3-D Arrays

Follow these guidelines when writing input signals to an element in a vector, matrix, or 3-D array signal.

Each guideline has a severity level that indicates the level of compliance requirements. To learn more, see HDL Modeling Guidelines Severity Levels.

Guideline ID

2.3.4

Severity

Recommended

Description

You can use the Assignment block to write input signals to an element in a vector, matrix, or 3-D array signal. For HDL code generation, use these block parameter settings:

  • Number of output dimensions: Set this parameter to 1 when the output is a vector, 2 for a 2-D array, or 3 for a 3-D array.

  • Index mode: Use zero-based indexing so that the generated code matches the model.

  • Initialize output (Y): Set this parameter to Initialize using input port <Y0>, which initializes the output with the signal at the input port Y0. You cannot use the Specify size for each dimension in table setting for HDL code generation. To enable this parameter, set Index Option to Index vector (port) or Starting index (port) for one or more dimensions.

  • Index option:

    • When using an Assignment block that has a variable index for an application such as register bank usage, choose a port-related setting, such as Index Vector (port). For a fixed index, select from dialog-related settings, such as Index vector (dialog).

    • When assigning individual values to multiple elements of the output port Y, use a input signal with the same size as the elements specified by setting of the Index option parameter.

    • When assigning the same value to multiple elements, use a scalar input signal regardless the setting of the Index option parameter.

Model a Register Bank by Using Assignment Block

This example shows how to model a register bank by using the Assignment block. The model in this figure contains an Assignment block that has variable index, a Delay block, and a Reshape block. To model as a register bank, the model employs a feedback loop from the output of the Reshape block to the input signal, Y0, of the Assignment block Y0. By specifying a scalar value to the input signal U as the register value and limiting the index from the port to one write address, the model behaves as a register bank. When you specify multiple elements to the input Idx1, the model simultaneously rewrites the elements in the output signals.

Register Bank Model

In the figure, when the column vector output [16;17;18;19] from the Delay block is input as the Y0 value, a column vector [20;21] with two elements is input to the write input signal U. Because the start index of Idx1 is 0, the input signal U overwrites the 0th to 1st element of Y0, and the output signal Y becomes the column vector [20;21;18;19]. The Delay block outputs signal Y when the Write En signal is valid, or otherwise holds previous value.

See Also