Latest Post

Ads

Verilog: 4 Bit Magnitude Comparator Behavioral Modelling using If Else Statement with Testbench Code

Verilog Code for 4 Bit Magnitude Comparator Behavioral Modelling using If Else Statement with Testbench Code

module 4_Mag_Comp(
    input [3:0]a,b,
    output equal, greater, lower
    );
reg greater, equal, lower; 
initial greater = 0, equal = 0, lower = 0;
always @ (a or b)
    begin 
        if (a < b)
            begin
            greater = 0; equal = 0; lower = 1;
            end   
        else if (a == b)
            begin
            greater = 0; equal = 1; lower = 0;
            end
        else
            begin
            greater = 1; equal = 0; lower = 0;
            end
end  
endmodule

//Testbench code for 4 Bit Magnitude Comparator Behavioral Modelling using If Else Statement

initial begin
// Initialize Inputs 
a = 0; b = 0;
// Wait 100 ns for global reset to finish
#100;
// Add stimulus here 
#100; a = 5; b = 2;
#100; a = 15; b = 15;
#100; a = 2; b = 7; 
end
initial begin 
#100 
$monitor(“a = %b, b = %b, lower = %b, greater = %b, equal = %b”, a, b, lower, greater, equal); 
end 
endmodule

Xillinx Output:

Verilog Code for 4 Bit Magnitude Comparator Behavioral Modelling using If Else Statement with Testbench Code
4 Bit Magnitude Comparator Behavioral Modelling Verilog Code

Comments

Ads

Popular posts from this blog

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

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

VLSI: 4-1 MUX Dataflow Modelling with Testbench

VLSI: Half Subtractor and Full Subtractor Gate Level Modelling

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