XNOR Logic Gate Modeling Using Verilog

XNOR GATE CIRCUIT:

XNOR-GATE-CIRCUIT-DIAGRAM

TRUTH TABLE:

X Y Output(Z)
0 0 1
1 0 0
0 1 0
1 1 1

 

XNOR GATE MODELLING METHODS:

Data Flow Modelling:

`timescale 1ns / 1ps

module xnorGate(output z, input x,y);
  assign z= ~(x^y); 
endmodule

 

Behavioral Modeling:

`timescale 1ns / 1ps

module xnorGate(output reg z, input x,y);
  always @ (x or y) 
    begin
      if ((x == 1'b1 & y == 1'b1) | (x == 1'b0 & y == 1'b0)) 
        begin
          z = 1'b1;
        end
      else
        z = 1'b0;
    end
endmodule

 

Gate Level Modelling:

`timescale 1ns / 1ps

module xnorGate(output z, input x,y);
  xnor(z, x, y); 
endmodule

 

TESTBENCH:

`timescale 1ns / 1ps

module xnorGateTB();
  reg tx,ty;
  wire tz;
  
  xnorGate DUT(.z(tz),.x(tx),.y(ty));
  
  initial
    begin
         tx=0; ty=0;
      #2 tx=0; ty=1;
      #2 tx=1; ty=0;
      #2 tx=1; ty=1;
      #2 $finish;
    end
  
  initial
    begin
      $monitor ($time, " tx=%d, ty=%d, tz=%d",tx,ty,tz);
    end
  
  initial 
    begin
      $dumpfile("xnorGateTB.vcd"); 
      $dumpvars;
    end
  
endmodule

Output:

0 tx=0, ty=0, tz=0
2 tx=0, ty=1, tz=1
4 tx=1, ty=0, tz=1
6 tx=1, ty=1, tz=0

 

SIMULATION RESULTS:

Xnor-Gate-Simulation-Output

Leave a comment