Verilog Xilinx的输出窗口中出现错误,如下图所示,该错误适用于使用门级的32位逻辑单元

Verilog Xilinx的输出窗口中出现错误,如下图所示,该错误适用于使用门级的32位逻辑单元,verilog,32-bit,Verilog,32 Bit,下面提到的是32位逻辑单元的代码,其逻辑功能如下图所示。我不确定我会错在哪里。我试着对选择位“s”的逻辑函数进行更改,但不知怎么的,它似乎不起作用 module ALU_unit(output out, input x, input y, input [1:0] s); wire ns0, ns1; wire w0,w1,w2,w3; wire t1,t2,t3,t4; and (t1,x,y); or (t2,x,y); xor (t3,x,y); nor (t4,x,y); not (n

下面提到的是32位逻辑单元的代码,其逻辑功能如下图所示。我不确定我会错在哪里。我试着对选择位“s”的逻辑函数进行更改,但不知怎么的,它似乎不起作用

module ALU_unit(output out, input x, input y, input [1:0] s);
wire ns0, ns1;
wire w0,w1,w2,w3;
wire t1,t2,t3,t4;

and (t1,x,y);
or (t2,x,y);
xor (t3,x,y);
nor (t4,x,y);

not (ns0, s[0]);
not (ns1, s[1]);
and (w0, t1, ns0, ns1);
and (w1, t2, s[0], ns1);
and (w2, t3, ns0, s[1]);
and (w3, t4, s[0], s[1]);
or (out, w0, w1, w2, w3);
endmodule

module stimulus;

reg [31:0] x, y;
reg [1:0] s;
wire [31:0] out;

ALU_unit m0(out[0], x[0], y[0], s[0]);
ALU_unit m1(out[1], x[1], y[1], s[1]);
ALU_unit m2(out[2], x[2], y[2], s[2]);
ALU_unit m3(out[3], x[3], y[3], s[3]);
ALU_unit m4(out[4], x[4], y[4], s[4]);
ALU_unit m5(out[5], x[5], y[5], s[5]);
ALU_unit m6(out[6], x[6], y[6], s[6]);
ALU_unit m7(out[7], x[7], y[7], s[7]);
ALU_unit m8(out[8], x[8], y[8], s[8]);
ALU_unit m9(out[9], x[9], y[9], s[9]);
ALU_unit m10(out[10], x[10], y[10], s[10]);
ALU_unit m11(out[11], x[11], y[11], s[11]);
ALU_unit m12(out[12], x[12], y[12], s[12]);
ALU_unit m13(out[13], x[13], y[13], s[13]);
ALU_unit m14(out[14], x[14], y[14], s[14]);
ALU_unit m15(out[15], x[15], y[15], s[15]);
ALU_unit m16(out[16], x[16], y[16], s[16]);
ALU_unit m17(out[17], x[17], y[17], s[17]);
ALU_unit m18(out[18], x[18], y[18], s[18]);
ALU_unit m19(out[19], x[19], y[19], s[19]);
ALU_unit m20(out[20], x[20], y[20], s[20]);
ALU_unit m21(out[21], x[21], y[21], s[21]);
ALU_unit m22(out[22], x[22], y[22], s[22]);
ALU_unit m23(out[23], x[23], y[23], s[23]);
ALU_unit m24(out[24], x[24], y[24], s[24]);
ALU_unit m25(out[25], x[25], y[25], s[25]);
ALU_unit m26(out[26], x[26], y[26], s[26]);
ALU_unit m27(out[27], x[27], y[27], s[27]);
ALU_unit m28(out[28], x[28], y[28], s[28]);
ALU_unit m29(out[29], x[29], y[29], s[29]);
ALU_unit m30(out[30], x[30], y[30], s[30]);
ALU_unit m31(out[31], x[31], y[31], s[31]);

initial
begin
$monitor("Input is %d %d, output is %d \n\n", x, y, out);
x = 32'd111; y = 32'd222;

#1 s= 2'b00;
#1 s= 2'b01;
#1 s= 2'b10;
#1 s= 2'b11;

end
endmodule
下面是逻辑单元的图像,上面提到的错误是门级Verilog中的代码。


您得到的错误是因为您将select信号声明为两位reg,然后尝试访问其中的32位。您应该为每个ALU_单元实例使用select信号的两个位,以获得规范中指定的行为。

您在设计中没有实例化32位ALU,而是为1位ALU编码并在测试台上制作多个实例。现在从刺激块的问题来看,您没有通过2位用于选择逻辑操作,而不是发送1位用于选择,因此代码将得到优化,这就是EDA工具中显示警告的原因

module alu_unit(
   output      out
  ,input       x,y
  ,input [1:0] s
);

  wire ns0, ns1;
  wire w0,w1,w2,w3;
  wire t1,t2,t3,t4;

  and  u_gate_inst_0(t1,x,y);
  or   u_gate_inst_1(t2,x,y);
  xor  u_gate_inst_2(t3,x,y);
  nor  u_gate_inst_3(t4,x,y);

  not u_mux_inst_0 (ns0, s[0]);
  not u_mux_inst_1 (ns1, s[1]);
  and u_mux_inst_2 (w0 , t1, ns0 , ns1   );
  and u_mux_inst_3 (w1 , t2, ns1 , s[0]  );
  and u_mux_inst_4 (w2 , t3, ns0 , s[1]  );
  and u_mux_inst_5 (w3 , t4, s[0], s[1]  );
  or  u_mux_inst_6 (out, w0, w1  , w2, w3);

endmodule

module alu_top(
    output [31:0] out
   ,input  [31:0] x,y
   ,input  [1:0]  s
);

 alu_unit u_alu_unit [31:0] (out,x,y,s);

endmodule

module stimulus;

 reg  [31:0] x, y;
 reg  [1:0]  s;
 wire [31:0] out;

 alu_top u_alu_top (out,x,y,s);

 initial begin
    $monitor("Input is %d %d, output is %d \n\n", x, y, out);
    x = 32'd111; y = 32'd222;

    #1 s= 2'b00;
    #1 s= 2'b01;
    #1 s= 2'b10;
    #1 s= 2'b11;

 end
endmodule