gpt4 book ai didi

verilog - verilog 中的二进制补码

转载 作者:行者123 更新时间:2023-12-02 16:39:37 28 4
gpt4 key购买 nike

我一直在尝试构建一个模块,该模块返回(3 位)输入的二进制补码表示(第一位是符号)。我认为以下代码在概念上是正确的,但我可能遗漏了它的结构:当我尝试编译时,出现以下错误:

(vlog-2110) Illegal reference to net "f_o".
(vlog-2110) Illegal reference to net "f_o".
(vlog-2110) Illegal reference to net "f_o".

搜索该错误表明,在同时使用变量作为输入和输出时通常会出现该错误,但这不是我的情况。能指出错误在哪里吗?

module ca2 (a_i,f_o);
input [2:0] a_i;
output [2:0] f_o;

always @(a_i[2:0] or f_o[2:0])
begin
if (a_i[2] == 1)
begin
f_o[2] = a_i[2];
f_o[1:0] = (~a_i[1:0] + 'b1);
end
else
begin
f_o = a_i;
end
end
endmodule

最佳答案

在 Verilog 中,在大多数情况下,未声明的标识符被视为隐式连线声明。由于 f_o 尚未声明,编译器将其视为连线,而不是变量。这会导致编译器提示所有的分配。

// What was typed
module ca2 (a_i,f_o);
input [2:0] a_i;
output [2:0] f_o;

// What the compiler implicitly declares
wire [2:0] a_i;
wire [2:0] f_o;

要修复它,您可以声明变量或同时声明端口和变量。

module ca2 (a_i,f_o);
input [2:0] a_i;
output [2:0] f_o;
reg [2:0] f_o;

module ca2 (a_i,f_o);
input [2:0] a_i;
output reg [2:0] f_o;

关于verilog - verilog 中的二进制补码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13150452/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com