Latest Post

Ads

Verilog Code for 4 Bit Full Subtractor Behavioral Modelling with Testbench Code

Verilog Code for 4 Bit Full Subtractor Behavioral Modelling with Testbench Code

module 4_bit_Sub(
    input [3:0]a,b,
    input bin,
    output [3:0]diff,
    output bout
    );
reg [3:0]diff; 
reg bout;
 
always @ (a or b or bin)
   assign {bout,diff}= (~a) + b + bin;
endmodule

//Testbench code for 4 Bit Full Subtractor Behavioral 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=4; b=9; bin=1; 
#100 a=15; b=5; bin=1; 
#100 a=7; b=5; bin=0; 
#100 a=6; b=10; bin=1; 
end
initial begin 
#100 
$monitor(“a = %b, b = %b, bin = %b, diff = %b, bout = %b”, a, b, bin, diff, bout); 
end 
endmodule

Also See:

List of Verilog Programs

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