Latest Post

Ads

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

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

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

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