Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如果我知道一个字段的位数,那么为该字段创建掩码的最佳方法是什么。
例如,如果位数是 4,我想要一个掩码4'b1111
4'b1111
我目前正在做 C 风格的面具创作:
`define MY_BITS 4 ... mask = (1 << `MY_BITS) - 1;
尝试复制运算符:
mask = {`MY_BITS{1'b1}};
替代方案(仅限 System-Verilog):
logic [`MY_BITS-1:0] mask; ... mask = '1;
使用复制运算符:
有关一些示例,请参见http://www.asic-world.com/verilog/operators2.html。