Vector0:
wire [99:0] my_vector; // Declare a 100-element vector
assign out = my_vector[10]; // Part-select one bit out of the vector
module top_module (
input wire [2:0] vec,
output wire [2:0] outv,
output wire o2,
output wire o1,
output wire o0 ); // Module body starts after module declaratio
assign outv=vec;
assign o2=vec[2];
assign o1=vec[1];
assign o0=vec[0];
endmodule
Vector1:
1,Declaring Vectors:
Syntax:语法
type [upper:lower] vector name;
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-significant bit.
2,Implicit nets:隐式网
`default_nettype none //使用后避免错误
wire [2:0] a, c; // Two vectors
assign a = 3'b101; // a = 101
assign b = a; // b = 1 implicitly-created wire
assign c = b; // c = 001 <-- bug
my_module i1 (d,e); // d and e are implicitly one-bit wide if not declared.
// This could be a bug if the port was intended to be a vector.
3,Unpacked vs. Packed Arrays未打包与打包阵列
reg [7:0] mem [255:0]; // 256 unpacked elements, each of
//which is a 8-bit packed vector of reg.
reg mem2 [28:0]; // 29 unpacked elements, each of which is a 1-bit reg.
4,Accessing Vector Elements: Part-Select访问向量元素:~选择
assign w = a;//如果w和a位宽不一致,采用高位补零(w的位宽高于a