Latest Post

Ads

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

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

module 2_Mag_Comp(
    input [1: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 2 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 = 2; b = 1;
#100; a = 1; b = 2;
#100; a = 3; b = 3; 
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 2 Bit Magnitude Comparator Behavioral Modelling using If Else Statement with Testbench Code
2 Bit Magnitude Comparator Behavioral Modelling

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