4 bit Comparator 比較器 Behavioral Modeling (& Test Bench)
//數位IC設計入門-Verilog combinational logic
// 4 bit Comparator 比較器 Behavioral Modeling (& Test Bench)
module COMP(a, b, gt, eq, lt);
input [3:0] a, b;
output gt, eq, lt;
reg gt, eq, lt;
always@(a or b)
begin
gt = 1'd0;
eq = 1'd0;
lt = 1'd0;
if(a > b)
begin
gt = 1'd1;
end
else if (a == b)
begin
eq = 1'd1;
end
else
begin
lt = 1'd1;
end
end
endmodule
// 時間單位 100ns, 時間精確度100 ps
`timescale 100ns/100ps
module Test_bench;
//module COMP(a, b, gt, eq, lt);
//input [3:0] a, b;
//output gt, eq, lt;
// Inputs
reg [3:0]a=4'd0, b=4'd0;
// Outputs
wire gt, eq, lt;
// Instantiate the Unit Under Test (UUT)
//DECODER3X8(enable, in, out);
COMP UUT(a, b, gt, eq, lt);
initial begin
$monitor(a, b, gt, eq, lt);
// Initialize Inputs
//#25 a[3:0]=4'd0 ,b[3:0]=4'd0;
#25 a[3:0]=4'd9 ; b[3:0]=4'd0;
#25 a[3:0]=4'd9 ; b[3:0]=4'd15;
#25 a[3:0]=4'd10 ; b[3:0]=4'd10;
end
initial
begin
#110; // 模擬終止時間 110 ns
$stop;
end
endmodule
沒有留言:
張貼留言