module number_detect_es(found,number);
input number;
output found;
wire [3:0] number;
wire b1001,b0010,n0,n1,n2,n3;
or (found,b1001,b0010);
and (b1001,number[3],n2,n1,number[0]);
and (b0010,n3,n2,number[1],n0);
not (n0,number[0]);
not (n1,number[1]);
not (n2,number[2]);
not (n3,number[3]);
endmodule
module number_detect_is(found,number);
input number;
output found;
wire [3:0] number;
assign found = number === 4'b1001 || number === 4'b0010;
endmodule
module test_number_detect();
integer n;
reg expected_output;
wire fes, fis;
number_detect_es ndes(fes,n[3:0]);
number_detect_is ndis(fis,n[3:0]);
initial
begin
for(n=0; n<16; n=n+1)
begin
#1;
expected_output = ( n === 9 || n === 2 ) ? 1 : 0;
if( fes !== expected_output )
$display("Wrong output for explicit str, n=%d",n);
if( fis !== expected_output )
$display("Wrong output for implicit str, n=%d",n);
end
$display("Done testing.");
end
endmodule
module pos_edge_trigger(o,i);
input i;
output o;
wire i;
wire o;
wire noti;
wire #2 preout;
assign o = preout;
not #2 (noti,i);
and #(2,3) (preout,i,noti);
endmodule
module test_pos_edge();
reg i;
wire o;
pos_edge_trigger et(o,i);
initial
begin
i=0;
#10;
i=1;
#1;
i=0;
#5;
i=1;
#2;
i=0;
#7;
i=1;
#9;
i=0;
#5;
end
endmodule