【问题标题】:Constant not recognized within systemverilog module在 systemverilog 模块中无法识别常量
【发布时间】:2019-12-16 14:18:06
【问题描述】:

我尝试编译以下代码:

module sample (
                  input  logic       [31:0] data_i,
                  output logic [31:0] data_o
                 );

`define SUBNORMAL 31'b0

/*Intermediate storage of input data*/
logic [15:0] data_str_0;
bit sign_0;

initial begin
  data_str_0 = data_i[31:16] ;
end

/*Assigning the sign bit*/
initial begin
sign_0 = data_str_0[15];
end

/*Exponent calculation*/
logic [4:0] exp_hf_0;
logic [7:0] exp_sf_0;

initial begin
exp_hf_0 = data_str_0 [14:10];
end

/*Adjusting the bias*/
always @(*)
begin
exp_sf_0 = exp_hf_0 + 8'd112;
end

/*Mantissa calculation*/
logic [9:0] man_hf_0;
logic [22:0] man_sf_0;

initial begin
man_hf_0 = data_str_0 [9:0];
end

always @(*)
begin
man_sf_0 = {man_hf_0,13'b0};
end

/*Packing the output*/
always @(*)
begin
if (exp_sf_0 == 5'b0 && man_sf_0 != 10'b0)
data_o = '{sign_0,SUBNORMAL};
end    

endmodule

但是我收到以下错误消息:

**错误:sample.sv(52): (vlog-2730) 未定义变量:'SUBNORMAL'。

我的意图是将 SUBNORMAL 常量值与 sign_0 绑定,并将其分配给 data_o。

谁能给我建议一个解决方案?

【问题讨论】:

  • 在 C 中,当您使用用 #define 定义的符号时,您不需要 #;在(系统)Verilog中,您确实需要添加反引号,如工具所说。
  • 反引号后出现以下错误。 (vlog-13174) 非法分配模式。元素的数量 (2) 与类型的宽度 (32) 不匹配。

标签: arrays system-verilog


【解决方案1】:

要使用`define 宏,您需要在它前面加上` 符号。

不过,我建议您改用parameter

parameter SUBNORMAL = 32'b0;

这样,参数的作用域就在您要使用它的地方。

【讨论】:

    猜你喜欢
    • 2019-02-27
    • 2022-01-22
    • 2021-11-01
    • 2016-07-08
    • 2023-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-22
    相关资源
    最近更新 更多