尝试在 VERILOG 中执行两个小数 fixed_point 操作数的加法,我陷入了这个错误

Trying to perform addition of two fractional fixed_point operands in VERILOG, I'm stuck in this error

我正在尝试编写一个 Verilog 可综合程序来添加两个小数 fixed_point 数字。这是测试台:

module sum_test;

// Inputs
reg [12:-20] oper1;
reg [12:-20] oper2;
reg cin;

// Outputs
wire [12:-20] sum_result;

// Instantiate the Unit Under Test (UUT)
sum_fix uut (
    .oper1(oper1), 
    .oper2(oper2), 
    .cin(cin), 
    .sum_result(sum_result)
);

initial begin
    // Initialize Inputs
    oper1 = 0;
    oper2 = 0;
    cin = 0;

    // Wait 100 ns for global reset to finish
    #100;

    // Add stimulus here
oper1 = 12.5;
oper2 = 5.4;

end

initial begin
    $monitor("oper1=%d,oper2=%d,sum_result=%d \n",oper1,oper2,sum_result);      

end

endmodule

///这是加法模块

module sum_fix(

input [12:-20] oper1,
input [12:-20] oper2,
input cin,
output [12:-20] sum_result
);

assign sum_result = oper1 + oper2 + cin;
endmodule

模拟器打印这个,

oper1=0,oper2=0,sum_result=0

oper1=13,oper2=5,sum_result=18

我似乎没有在测试台中正确引入数字或其他什么,可能是模拟器无法使用这种表示法?顺便说一句,我在 Ashenden 的书 "Digital Design (Verilog)" 中启发了这个模块。他谈到了这个定点小数符号,甚至像我一样用运算符“+”进行了加法,所以我不知道出了什么问题,不过他没有为这个例子制作测试台。谢谢大家,这个论坛太棒了。

尝试使用:

reg [32:0] oper1;
reg [32:0] oper2;

而不是:

reg [12:-20] oper1;
reg [12:-20] oper2;

刺激是:

oper1 = 12.5 * 2**20; //shift 20 binary places
oper2 = 5.4  * 2**20;