2009年11月30日 星期一

2位元比較器含時脈周期


wire A_lt_B,A_gt_B,A_eq_B,A1,A0,B1,B0;

system_clock #100 clock_1(A1);
system_clock #200 clock_2(A0);
system_clock #400 clock_3(B1);
system_clock #800 clock_4(B0);

compare_2a X1(A_lt_B,A_gt_B,A_eq_B,A1,A0,B1,B0);


endmodule

module compare_2a(A_lt_B,A_gt_B,A_eq_B,A1,A0,B1,B0);
input A1,A0,B1,B0;
output A_lt_B,A_gt_B,A_eq_B;
wire A_lt_B,A_gt_B,A_eq_B;
assign A_lt_B=(~A1)&B1(~A1)&(~A0)&B0(~A0)&B1&B0;
assign A_gt_B=A1&(~B1)A0&(~A0)&(~B0)(~A0)&B1&B0;
assign A_eq_B=(~A1)&(~A0)&(~B1)&(~B0)(~A1)&A0&(~B1)&B0A1&A0&B1&B0A1&(~A0)&B1&(~B0);
endmodule


module system_clock(clk);
parameter PERIOD=100;
output clk;
reg clk;

initial clk=0;
always begin#(PERIOD/2) clk=~clk ;#(PERIOD-PERIOD/2) clk=~clk ;end
mailto:always@%20(posedge clk)if($time>10000) #(PERIOD-1) $stop;
endmodule

比較器2




module compare_2a(A_lt_B,A_gt_B,A_eq_B,A1,A0,B1,B0);
input A1,A0,B1,B0;
output A_lt_B,A_gt_B,A_eq_B;
wire A_lt_B,A_gt_B,A_eq_B;
assign A_lt_B=(~A1)&B1(~A1)&(~A0)&B0(~A0)&B1&B0;
assign A_gt_B=A1&(~B1)A0&(~A0)&(~B0)(~A0)&B1&B0;
assign A_eq_B=(~A1)&(~A0)&(~B1)&(~B0)(~A1)&A0&(~B1)&B0A1&A0&B1&B0A1&(~A0)&B1&(~B0);
endmodule




10/5 work

module mux;
integer ia,ib,isel;
reg a,b,sel;
wire out;

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);

initial
begin
for(ia=0;ia<=1;ia=ia+1)
begin a=ia;
for(ib=0;ib<=1;ib=ib+1)
begin b=ib;
for(isel=0;isel<=1;isel=isel+1)
begin sel=isel;

#10;
end
end
end
end
endmodule

2009年11月9日 星期一

module and4_rtl(y_out,x_in1,x_in2,x_in3,x_in4);

input x_in1,x_in2,x_in3,x_in4;

output y_out;

assign y_out=x_in1&x_in2&x_in3&x_in4;

endmodule

module and4_rtl(y_out,x_in);

input [ 3:0] x_in;

out y_out;

assign y_out=&x_in;

endmodule