-1

我对以下代码有一些问题:

    module register_window(port_A, port_B, PD, CWP, A, B, C, loadRF, clk);

output reg[4:0] port_A;
output reg[4:0] port_B;
input [31:0] PD; 
input [1:0] CWP;    
input [4:0] A;    
input [4:0] B;
input [4:0] C;
input loadRF; 
input clk;

    reg ld; //enable 

    wire  [3:0] t;
    decoder_2x4 decoder2by4(CWP, t, loadRF);

    wire [31:0] bitDecoder1;
    decoder_5x32 decoder0(C, bitDecoder1, t[0]);

    wire [31:0] bitDecoder2;
    decoder_5x32 decoder1(C, bitDecoder2, t[1]);

    wire[31:0] globalReg0;
      assign ld = (bitDecoder1[0] == 32'b0 ||bitDecoder2[0] == 32'b0||bitDecoder3[0] == 32'b0||bitDecoder4[0] == 32'b0);
     registers g0(globalReg0, PD, ld, clk);      

    // G1
    wire[31:0] globalReg1;
      assign ld = (bitDecoder1[1]== 32'b0||bitDecoder2[1]== 32'b0||bitDecoder3[1]== 32'b0||bitDecoder4[1]== 32'b0);
     registers g1(globalReg1, PD, ld, clk);

     wire[31:0] globalReg2;
     assign ld = (bitDecoder1[2]== 32'b0||bitDecoder2[2]== 32'b0||bitDecoder3[2]== 32'b0||bitDecoder4[2]== 32'b0);
    registers g2(globalReg2, PD, ld, clk);

基本上我的代码试图做的是设置wire t为二进制解码器的输出以及其他 5x32 解码器的输入(这里省略了一些)。然后,根据解码器的值,它为 ld 分配一个值,该值基本上只是一个启用信号(如果任何解码器位为 1,则启用为 1,否则为 0)。然后这些值进入一个寄存器,并由电线(globalReg1、、globalReg2等)输出。如果重要的话,他们都使用相同的时钟。

我得到的编译错误是

testbench.sv:37:错误:未解决的 net/uwire ld 不能有多个驱动程序。

在分配的每一行中;assign ld = (bitDecoder1[1]== 32'b0||bitDecoder2[1]== 32'b0||bitDecoder3[1]== 32'b0||bitDecoder4[1]== 32'b0);

我还尝试将上面的行放在always @(*) beginandend语句之间(因为我认为您总是必须在代码的逻辑部分之间这样做),但这只会给我一个错误:

testbench.sv:33:错误:ld 无法分配给未解析的电线。

如果有人能指出我正确的方向,我将永远感激不尽。谢谢!

4

1 回答 1

1

首先:assign的目标必须是wire,而不是reg。

其次,我找不到 bitDecoder1 或 bitDecoder2 的任何定义。
顾名思义,它们是位,但您将它们与 32 位进行比较。这让我有些困惑,但这对你的问题并不重要。

... ld 这基本上只是一个启用信号(如果任何解码器位为 1,则启用为 1,否则为 0)。

我无法将其与您的代码匹配。你有三个寄存器(g0,g1,g2,每个都需要一个加载启用。因此你需要一个ld0,ld1,ld2。Verilog
不像C,你可以多次重复使用一个变量。记住它是一种大规模的并行语言:任何文件中的所有分配都同时执行。

或者,如果12 个比较匹配中的任何一个,您希望加载所有g0、g1、g2 。在这种情况下,您仍然需要 ld0 ld1 和 ld2 但您需要将它们与 OR 函数结合起来:

assign ld = l0 | ld1 | ld2;
于 2018-01-11T15:41:21.140 回答