verilog基础2Vector向量

这篇博客详细介绍了Verilog中向量的基础知识,包括声明、隐式网、未打包与打包阵列、访问向量元素和实践应用。讨论了如何拆分16位向量为高低字节、进行位运算、位宽扩展以及如何进行位比较等操作。
摘要由CSDN通过智能技术生成

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值