开发者

Parameterized Bit-fields in verilog

开发者 https://www.devze.com 2023-03-15 04:59 出处:网络
Is it possible to parameterize a bit-field in verilog? Essentially I want to use a parameter or alternative to define a bit-range. The only way I can think of doing this is with a 开发者_运维技巧`defi

Is it possible to parameterize a bit-field in verilog? Essentially I want to use a parameter or alternative to define a bit-range. The only way I can think of doing this is with a 开发者_运维技巧`define as shown below but it seems like there should be a better way.

`define BITFIELD_SELECT 31:28
foo = bar[BITFIELD_SELECT]


Parameters are nicer(safer) than defines since the namespace is not global to the project. You should be able to do this with two parameters.

parameter BITFIELD_HIGH = 31;
parameter BITFIELD_LOW = 28;

assign foo = bar[BITFIELD_HIGH:BITFIELD_LOW];

Alternatively

parameter BITFIELD_HIGH = 31;
localparam BITFIELD_LOW = BITFIELD_HIGH-3;

assign foo = bar[BITFIELD_HIGH:BITFIELD_LOW];


If you use macros (define) include the "`" when call the macro

`define BITFIELD_SELECT 31:28
foo = bar[`BITFIELD_SELECT]; // `BITFIELD_SELECT
0

精彩评论

暂无评论...
验证码 换一张
取 消