文章目录
一、问题描述
向量用于使用一个名称对相关信号进行分组,以使其更易于操作。例如,声明一个名为 8 位向量, wire [7:0] w; 该向量在 w 功能上等效于具有 8 个单独的线网(wire w0, w1, w2, w3, w4, w5, w6, w7)。
向量的通用定义方式:
type [upper:lower] vector_name;
type 指定向量的数据类型。这通常是 wire 或 reg 。如果要声明输入或输出端口,则该类型还可以包括端口类型(例如, input 或 output )。一些例子:
wire [7:0] w; // 8-bit wire
reg [4:1] x; // 4-bit reg
output reg [0:0] y; // 1-bit reg that is also an output port (this is still a vector)
input wire [3:-2] z; // 6-bit wire input (negative ranges are allowed)
output [3:0] a; // 4-bit output wire. Type is ‘wire’ unless specified otherwise.
wire [0:7] b; // 8-bit wire where b[0] is the most-signi