File "code.v"
Full Path: /home/analogde/www/DB_JS/Verilog/TP04/code.v
File size: 1022 B
MIME-type: text/plain
Charset: utf-8
module full_adder(a,b,cin,sum,cout);
input a,b,cin;
output sum, cout;
reg sum, cout;
always @(a or b or cin)
begin
sum = a^b^cin;
cout = (a & b) | (a & cin) | (b & cin);
end
endmodule
module full_adder_4bit(a,b,cin,sum,cout);
input[3:0] a,b;
input cin;
output[3:0] sum;
output cout;
wire c1,c2,c3;
// instantiation
full_adder FA1(a[0],b[0],cin,sum[0],c1);
full_adder FA2(a[1],b[1],c1,sum[1],c2);
full_adder FA3(a[2],b[2],c2,sum[2],c3);
full_adder FA4(a[3],b[3],c3,sum[3],cout);
endmodule
module test_adder;
reg[3:0] a,b;
reg cin;
wire[3:0] sum;
wire cout;
full_adder_4bit dut(a,b,cin,sum,cout);
initial
begin
a=4'b0000;
b=4'b0000;
cin = 1'b0;
#50;
a=4'b0101;
b=4'b1010;
// sum = 1111 et cout = 0
#50;
a=4'b1111;
b=4'b0001;
// sum = 0000 et cout = 1
#50;
a=4'b0000;
b=4'b1111;
cin = 1'b1;
// sum = 0000 et cout = 1
#50;
a=4'b0110;
b=4'b0001;
// sum = 1000 et cout = 0
end
endmodule