Verilog Code Examples Compiler HDL Code for Begineer Simulator

0

Verilog code is an HDL hardware description language used to design and document electronic systems. Verilog allows designers to design electronic systems at different levels of abstraction. Verilog is the widely used HDL with a user community of over 15000 active designers.

It is a language that describes a digital system such as a network switch, microprocessor, memory or flip-flop. Using HDL, we can describe digital hardware at any level.

Hardware Description Language (HDL) models digital circuits using codes. Verilog is one such code (VHDL is another type). We won’t go into depth about programming language details that you might find in books.

Verilog Code for Logical gates:

Although the behavior of a circuit in Verilog is usually specified using assignment statements, in some cases, a circuit is modeled using primitive gates to ensure that critical sections of the circuit are best optimized.

Verilog creates primitives such as gates, transmission gates, and transitions to model gate-level simulation. To see how gate-level simulation works, we will write the Verilog code used for the comparator circuit using primitive gates.

Verilog HDL programming has used below logical RTL gates for better understanding purposes;

  • AND
  • OR
  • NOT
  • NAND
  • XOR
  • NOR
  • XNOR

Verilog Code for AND gate:

Let assume that a, b, c are inputs in this programming;

module ANDgate(

     input a,

     input b,

     output c

    );

 and(c,a,b); 

endmodule

Verilog Code for OR gate:

Let assume that a, b are inputs in this programming and z is the output;

module ORgate(

    input x,

    input y,

    output z

    );

           or(z,p,q);  

endmodule

Verilog Code for NOR gate:

Let assume that a, b are inputs in this programming and c is the output;

module NORgate(

     input a,

     input b,

     output c

    );

 nor(c,a,b); 

// c is the output, a and b are inputs 

 endmodule

Verilog Code for XOR gate:

module XORgate(

    input x,

    input y,

    output z

    );

           xor(z,p,q);

endmodule

Verilog Code for XNOR gate:

module XNORgate(

     input x,

     input y,

     output z

    );

 xnor(z,x,y); 

 endmodule

Verilog Code for NAND gate:

module NANDgate(

     input i,

     input j,

     output k

    );

 nand(c,a,b);

 endmodule

What is the difference between VHDL and Verilog?

I have seen many people ask this question; Well, the simple answer is like Verilog C and VHDL ADA. Verilog is easy to learn and easy to write code. On the other hand, VHDL takes more time to learn, and writing code is a bit more complicated. This applies to engineers who are new to these two languages.

Conclusion:

In this blog, we have learned about Verilog Code along with its history. Also, we covered the Verilog code for most of all the logic gates such as AND, OR, NOR, XOR, XNOR and NAND gates.

Join Examdays Telegram

For more details about the Telegram Group, Click the Join Telegram below button.

Join Membership

In case of any doubt regarding Telegram, you can mail us at [email protected].

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.