`timescale 1ns / 1ps
module sr_flip_flop(
input s,
input r,
input clk,
output reg q,
output reg nq
);
always@ (posedge clk)
begin
case({s,r})
2'b 00: q=q;
2'b 01: q=1'b 0;
2'b 10: q=1'b 1;
2'b 11: q=1'b x;
endcase
nq = ~q;
end
endmodule
-------------------------
//testbench.v
`timescale 1ns / 1ps
module testbench;
reg s, r, clk;
wire q, nq;
sr_flip_flop uut(s, r, clk, q, nq);
initial
begin
s=0;
r=0;
clk=0;
#100
s=0;
r=1;
#100
s=1;
r=0;
#100
s=1;
r=1;
end
always #10 clk=~clk;
endmodule
reference:
No comments:
Post a Comment