Latest Post

Ads

VLSI: 4 Bit Full Subtractor Structural/Gate Level Modelling with Testbench

Verilog Code for 4 Bit Full Subtractor Structural/Gate Level Modelling

module full_subtractor_4_bit(
    input [3:0]a,b,
    input bin,
    output [3:0]diff,
    output borrow,
               wire c0,c1,c2
    );
               fus f0(diff[0],c0,a[0],b[0],bin);
               fus f1(diff[1],c1,a[1],b[1],c0);
               fus f2(diff[2],c2,a[2],b[2],c1);
               fus f3(diff[3],borrow,a[3],b[3],c2);
endmodule


module fus(borrow,diff,a,b,c);

output borrow,diff;

input a,b,c;

wire w1,w4,w5,w6;

xor (diff,a,b,c);

not n1(w1,a);

and a1(w4,w1,b);

and a2(w5,w1,c);

and a3(w6,b,c);

or o1(borrow,w4,w5,w6);

endmodule

//Testbench code for 4 Bit Full Subtractor Structural/Gate Level Modelling

initial begin
                             // Initialize Inputs
                             a = 0;
                             b = 0;
                             bin = 0;
                             // Wait 100 ns for global reset to finish
                             #100;
                             // Add stimulus here
                             #100;a=0;b=0;bin=1;
                             #100;a=0;b=1;bin=0;
                             #100;a=0;b=1;bin=1;
                             #100;a=1;b=0;bin=0;
                             #100;a=1;b=0;bin=1;
                             #100;a=1;b=1;bin=0;
                            #100;a=1;b=1;bin=1;
end


Output:






Other Verilog Programs:

Go to Index of Verilog Programming

Comments

Ads

Popular posts from this blog

VLSI: 1-4 DEMUX (Demultiplexer) Dataflow Modelling with Testbench

VLSI: BCD to Excess 3 and Excess 3 to BCD Dataflow Modelling

VLSI: 2 Bit Magnitude Comparator Dataflow Modelling

1 to 4 DEMUX (Demultiplexer) Verilog CodeStructural/Gate Level Modelling with Testbench

Full Subtractor Verilog Code in Structural/Gate Level Modelling with Testbench