行为建模在 testbench.test 中不是有效的左值

Behavioral Modeling is not a valid l-value in testbench.test

我正在尝试使用两个二进制输入 A 和 B 来获得二进制输出,即 F 就像下面的真相 table 一样,但它一直在说:

main.v:36: error: F3 is not a valid l-value in testbench.test
main.v:27:      : F3 is declared here as wire.

这就是我模型的真实情况 table。

A1 A0 B1 B0| F3 F2 F1 F0
0  0  0  0 | 0  0  0  0
0  0  0  1 | 0  0  0  0
0  0  1  0 | 0  0  0  0
0  0  1  1 | 0  0  0  0
0  1  0  0 | 0  0  0  0
0  1  0  1 | 0  0  0  1
0  1  1  0 | 0  0  1  0
0  1  1  1 | 0  0  1  1
1  0  0  0 | 0  0  0  0
1  0  0  1 | 0  0  1  0
1  0  1  0 | 0  1  0  0
1  0  1  1 | 0  1  1  0
1  1  0  0 | 0  0  0  0
1  1  0  1 | 0  0  1  1
1  1  1  0 | 0  1  1  0
1  1  1  1 | 1  0  0  1
  

我的 icarus Verilog 代码在这里:


module Multiply(A1,A0,B1,B0,F3,F2,F1,F0);
input A1,A0,B1,B0;
output F3,F2,F1,F0;


always@(A1 or A0 or B1 or B0) 
begin 

if({A1,A0}*{B1,B0})

begin
{F3,F2,F1,F0}=4'b0001;
{F3,F2,F1,F0}=4'b0010;
{F3,F2,F1,F0}=4'b0011;
{F3,F2,F1,F0}=4'b0010;
{F3,F2,F1,F0}=4'b0100;
{F3,F2,F1,F0}=4'b0110;
{F3,F2,F1,F0}=4'b1001;
end

end

endmodule 

module testbench;
reg [1:0] A,B; // these are like switches
wire F3,F2,F1,F0; // like an LED

//test the verilog model
Multiply test(A[1],A[0],B[1],B[0],F3,F2,F1,F0);

//Generate inputs
initial
begin//like {

//display the response of the circuit
//for every input combination


$display("--------------------------------------------------------");
$display("Multiplication of Two 2-Binary Inputs equal to 4-bit binary output");
$display("--------------------------------------------------------");
$display("Time\tA\tB\tF3\tF2\tF1,\tF0");
$display("--------------------------------------------------------");
$monitor("%g\t%d\t%d\t%d\t%d\t%d",$time,A,B,F3,F2,F1,F0);
#15 $finish;
end
initial begin A = 0; B = 0; end

always #1 B[0] = ~B[0];
always #2 B[1] = ~B[1];
always #4 A[0] = ~A[0];
always #8 A[1] = ~A[1];
always #3

$display("--------------------------------------------------------");

endmodule

由于在 always 块中对 F3 进行赋值,因此必须将其声明为 reg。 F2、F1、F0也是如此:

module Multiply(A1,A0,B1,B0,F3,F2,F1,F0);
input A1,A0,B1,B0;
output F3,F2,F1,F0;
reg F3,F2,F1,F0;

这修复了编译错误并允许您的模拟 运行。但是,我不认为 Verilog 代码符合事实 table.

编码真理 table 的常用方法是使用 case 语句:

module Multiply(A1,A0,B1,B0,F3,F2,F1,F0);
   input A1,A0,B1,B0;
   output F3,F2,F1,F0;
   reg    F3,F2,F1,F0;

   always @* begin 
        case ({A1,A0,B1,B0})
            4'b0101          : {F3,F2,F1,F0}=4'b0001;
            4'b0110          : {F3,F2,F1,F0}=4'b0010;
            4'b0111          : {F3,F2,F1,F0}=4'b0011;
            4'b1001          : {F3,F2,F1,F0}=4'b0010;
            4'b1010          : {F3,F2,F1,F0}=4'b0100;
            4'b1011, 4'b1110 : {F3,F2,F1,F0}=4'b0110;
            4'b1111          : {F3,F2,F1,F0}=4'b1001;
            default          : {F3,F2,F1,F0}=4'b0000;
        endcase
    end
endmodule