我有以下代码可以正确比较等于或大于彼此的数字。但是,它不会产生小于输出。它总是弹出未定义。
我在这里想念什么?
module FourBitComparator (input [3:0]a,
input [3:0]b,
output eq,
output gt,
output lt);
assign eq = a == b;
assign gt = a > b;
assign lt = a < b;
endmodule
module EightBitComparator(input [7:0]a,
input [7:0]b,
output eq,
output gt,
output lt);
wire [3:0]a1;
wire [3:0]a2;
wire [3:0]b1;
wire [3:0]b2;
assign a1 = {a[3:0]};
assign a2 = {a[7:4]};
assign b1 = {b[3:0]};
assign b2 = {b[7:4]};
FourBitComparator BC_2( a2, b2, eq, gt, lt);
FourBitComparator BC_1( a1, b1, eq, gt, lt);
endmodule
试验台
module EightBitCompTB;
// Variables
reg [7:0] a, b;
wire eq, gt, lt;
// Call comaparator
EightBitComparator BC_1(a, b, eq, gt, lt);
// Test inputs
initial begin
$monitor("%d a=%b, b=%b, eq=%b, gt=%b, lt=%b",
$time,
a, b, eq, gt, lt);
#10
a = 15;
b = 15;
#10
a = 255;
b = 0;
#10
a = 74;
b = 80;
#10
a = 65;
b = 50;
end
endmodule