学海荡舟手机网
导航

主页 > 电子设备技术 > 电器电路基础 > > 详细内容

.Verilog-2001常量函数

        Verilog的语法要求定义向量的宽度或数组大小时其值必须是一个确定的数字或一个常量表达式。比如:
     
      parameter WIDTH = 8;
      wire [WIDTH-1:0] data;
      在Verilog-1995标准中,常量表达式只能是基于一些常量的算术操作。而在Verilog-2001中增加了constant function,其定义与普通的function一样,不过constant function只允许操作常量。下面是一个使用constant function的例子,clogb2函数返回输入值2次方的次数。
     
      module ram (address_bus, write, select, data);
      parameter SIZE = 1024;
      input [clogb2(SIZE)-1:0] address_bus;
      ...
      function integer clogb2 (input integer depth);
      begin
      for(clogb2=0; depth>0; clogb2=clogb2+1)
      depth = depth >> 1;
      end
      endfunction
      ...
      endmodule

相关文章