module top;
reg [1:0] A, B;
wire[1:0] OUT;
system_clock #100 clock1(SEL);
mux2 M1(OUT, A, B, SEL);
initial
begin
A=2'd2;
B=2'd1;
end
endmodule
module mux(OUT, A, B, SEL);
output OUT;
input A,B,SEL;
not I5 (sel_n, SEL);
and I6 (sel_a, A, SEL);
and I7 (sel_b, sel_n, B);
or I4 (OUT, sel_a, sel_b);
endmodule
module mux2(OUT, A, B, SEL);
output [1:0] OUT;
input [1:0] A,B;
input SEL;
mux hi (OUT[1], A[1], B[1], SEL);
mux lo (OUT[0], A[0], B[0], SEL);
endmodule
module system_clock(clk);
parameter PERIOD=100;
output clk;
reg clk;
initial
clk=0;
always
begin
#(PERIOD/2)clk=~clk;
end
always@(posedge clk)
if($time>1000)
$stop;
endmodule
-----------
4bits 多工
module top;
system_clock #100 clock1(A);
system_clock #200 clock2(B);
system_clock #400 clock3(SEL);
mux ml(OUT,A,B,SEL);
mux2 ml(OUT,A,B,SEL);
mux4 ml(OUT,A,B,SEL);
endmodule
module mux(OUT, A, B, SEL);
output OUT;
input A,B,SEL;
not I5 (sel_n, SEL);
and I6 (sel_a, A, SEL);
and I7 (sel_b, sel_n, B);
or I4 (OUT, sel_a, sel_b);
endmodule
module mux2(OUT, A, B, SEL);
output [1:0] OUT;
input [1:0] A,B;
input SEL;
mux hi (OUT[1], A[1], B[1], SEL);
mux lo (OUT[0], A[0], B[0], SEL);
endmodule
module mux4(OUT, A, B, SEL);
output [3:0] OUT;
input [3:0] A,B;
input SEL;
mux2 hi (OUT[3:2], A[3:2], B[3:2], SEL);
mux2 lo (OUT[1:0], A[1:0], B[1:0], SEL);
endmodule
module system_clock(clk);
parameter PERIOD=100;
output clk;
reg clk;
initial
clk=0;
always
begin
#(PERIOD/2)clk=~clk;
end
always@(posedge clk)
if($time>1000)
$stop;
endmodule
沒有留言:
張貼留言