2013年4月25日 星期四

二位元加法器˙.3˙



module add2(Cout,Sum,A,B,Cin);
output Cout;
output [1:0]Sum;
input [1:0]A,B;
input Cin;

add hi(Cout,Sum[1],A[1],B[1],Cin);
add lo(Cout,Sum[0],A[0],B[0],Cin);

endmodule


module add(Cout,Sum,A,B,Cin);
output Cout,Sum;
input A,B,Cin;

xor I1(xor_ab,A,B);
and I2(and_ab,A,B);

xor I3(Sum,xor_ab,Cin);
and I4(and_abCin,xor_ab,Cin);

or I5(Cout,and_ab,and_abCin);

endmodule

module top;


wire Cout;
wire [1:0]A, B,Sum;
wire Cin;

system_clock #100 clock1(B[1]);
system_clock #200 clock2(A[0]);

system_clock #100 clock1(B[1]);
system_clock #200 clock2(A[0]);

system_clock #400 clock6(Cin);


add2 I3(Cout,Sum,A,B,Cin);

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

沒有留言:

張貼留言