当我在cmd上运行此代码时,它会给我一个语法错误。有什么帮助吗?
module xor (a, b, c);
input a, b;
output c;
wire c, not_a, not_b;
not a_invert (not_a, a);
not b_invert (not_b, b);
and A1 (x, not_a, b);
and A2 (y, not_b, a);
or Result (c, x, y);
endmodule
module xor_test(a, b); //test bench
input a, b;
wire c;
xor x(a,b,c);
initial
begin
$monitor("c=%b",c);
end
endmodule
module main();
wire a=0, b=1 ;
xor_test t1(a,b);
endmodule
由于尝试使用xor
作为模块名称,因此出现语法错误。由于xor
是Verilog中的保留关键字,因此将其用作模块名称是非法的。您可以将其重命名为类似xor1
:的名称
module xor1 (a, b, c); ////////// CHANGED
input a, b;
output c;
wire c, not_a, not_b;
not a_invert (not_a, a);
not b_invert (not_b, b);
and A1 (x, not_a, b);
and A2 (y, not_b, a);
or Result (c, x, y);
endmodule
module xor_test(a, b); //test bench
input a, b;
wire c;
xor1 x(a,b,c); ////////// CHANGED
initial
begin
$monitor("c=%b",c);
end
endmodule
module main();
wire a=0, b=1 ;
xor_test t1(a,b);
endmodule
我用注释CHANGED
更改了这两行。
xor
是一种门类型,就像代码中的or
、and
和not
一样。参考IEEE Std 1800-2017第28节门级和开关级建模。
以下是一个运行在edafoundation 上的示例