Arrays

Registers, integers and time data types can be declared as arrays, as shown in the example below. Note the size of the array comes after the variable name in the declaration and after the variable name but before the bit reference in an assignment. So :-

declaration: <data_type_spec> {size} <variable_name> {array_size}

reference: <variable_name> {array_reference} {bit_reference}

        reg data [7:0]; // 8 1-bit data elements
        integer [3:0] out [31:0]; // 32 4-bit output elements

        data[5]; // referencing the 5th data element


Memories

Memories are simply an array of registers. The syntax is the same as above, we will discuss modelling RAM and ROM using memories in a later section.


        reg [15:0] mem16_1024 [1023:0]; // memory mem16_1024 is 1K of 16 bit elements
        mem16_1024[489]; // referencing element 489 of mem16_1024

It is always good practice to use informative names like mem16_1024 to help keep track of memories.

EXERCISE
Instantiated a 2k memory of 8 bit elements.

Answers


previous contents next