Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe

How to design, simulate, and verify in Verilog using the AND-OR-NOT gates-Part 5

By Michelle Froese March 17, 2025

In the previous Verilog tutorial, we designed and simulated all seven basic logic gates (including, AND, OR, NOT, NAND, NOR, XOR, and XNOR) in Verilog. (If you haven’t been following this VHDL tutorial series step by step, it’s recommended to start here, and review the previous tutorials before continuing.)

In this tutorial, we’ll:

  1. Write a Verilog program to implement NAND, NOR, XOR, and XNOR gates using only AND, OR, and NOT gates.
  2. Simulate the program to design the digital circuits for these gates using the AND-OR-NOT implementation.
  3. Verify the output waveforms and compare them to the truth tables of these logic gates.

Let’s begin with the digital circuit for which we will write the Verilog program.

The truth tables

The truth table for the NAND gate using the AND-OR-NOT gate circuit:

The truth table for the NOR gate using the AND-OR-NOT gate:

The truth table for the XOR gate using the AND-OR-NOT gate circuit:

The truth table for the XNOR gate using the AND-OR-NOT gate circuit:

Now, let’s write a Verilog program, compile it, simulate it, and observe the output in the form of waveforms. Then, we’ll verify that the output waveforms match the corresponding truth table.

(For detailed steps on how to edit and compile the program, create a waveform file, simulate the program, and generate output waveforms, please refer to this tutorial.)

Verilog program

Gate-level modeling:

module AOI (a,b,y_nand,y_nor,y_xor,y_xnor);
input a,b;
output y_nand,y_nor,y_xor,y_xnor;
wire t1,t2,t3,t4,t5,t6,a_not,b_not;
  and (t1, a, b);
  not (y_nand, t1);
  or (t2, a, b);
  not (y_nor, t2);
  not (a_not, a);
  not (b_not, b);
  and (t3, a, b_not);
  and (t4, b, a_not);
  or (y_xor, t3, t4);
  and (t5, a, b);
  and (t6, a_not, b_not);
  or (y_xnor, t5, t6);
endmodule

Dataflow modeling:

module AOI (a,b,y_nand,y_nor,y_xor,y_xnor);
input a,b;
output y_nand,y_nor,y_xor,y_xnor;
  assign y_nand = ~(a & b);
  assign y_nor = ~(a | b);
  assign y_xor = (a & ~b) | (~a & b);
  assign y_xnor = (a & b) | (~a & ~b);
endmodule

Next, compile the program and create a waveform file including all the inputs and outputs. Simulate the project, and you should receive3 the following result.

Note: Write the program using one modeling style at a time, and then compile it. Afterward, you can modify the program to use another modeling style and recompile it. You can also experiment with a third modeling style, such as behavioral modeling (not covered here), and verify the results.

Compare the output waveforms with the truth table for the gates. For example, the highlighted case shows inputs “a = 1” and “b = 0.” You can verify the other three cases in a similar way.

This demonstrates how you can build NAND, NOR, XOR, and XNOR gates in Verilog using the AND-OR-NOT gates, verifying their outputs against the corresponding truth tables.

In the next tutorial, we’ll prove De Morgan’s Theorems by designing their digital circuits using Verilog programming.

 

You may also like:


  • How to design, simulate, and verify all digital gates in…

  • How to compile, simulate, and verify a Verilog program using…

  • What is Verilog, its features, and design flow?- Part 2

  • What are the fundamentals of Verilog programs?-Part 1

  • How to design a digital circuit using VHDL

Filed Under: Tutorials
Tagged With: gates, logicgates, tutorial, verilgo
 

Next Article

← Previous Article
Next Article →

Questions related to this article?
👉Ask and discuss on EDAboard.com and Electro-Tech-Online.com forums.



Tell Us What You Think!! Cancel reply

You must be logged in to post a comment.

EE TECH TOOLBOX

“ee
Tech Toolbox: Internet of Things
Explore practical strategies for minimizing attack surfaces, managing memory efficiently, and securing firmware. Download now to ensure your IoT implementations remain secure, efficient, and future-ready.

EE Learning Center

EE Learning Center
“engineers
EXPAND YOUR KNOWLEDGE AND STAY CONNECTED
Get the latest info on technologies, tools and strategies for EE professionals.

HAVE A QUESTION?

Have a technical question about an article or other engineering questions? Check out our engineering forums EDABoard.com and Electro-Tech-Online.com where you can get those questions asked and answered by your peers!


RSS EDABOARD.com Discussions

  • Reducing "shoot-through" in offline Full Bridge SMPS?
  • High Side current sensing
  • How to simulate power electronics converter in PSpice?
  • Voltage mode pushpull is a nonsense SMPS?
  • Layout IRN reduction in Comparator

RSS Electro-Tech-Online.com Discussions

  • Back to the old BASIC days
  • Parts required for a personal project
  • PIC KIT 3 not able to program dsPIC
  • Failure of polypropylene motor-run capacitors
  • Siemens large industrial PLC parts

Featured – RPi Python Programming (27 Part)

  • RPi Python Programming 21: The SIM900A AT commands
  • RPi Python Programming 22: Calls & SMS using a SIM900A GSM-GPRS modem
  • RPi Python Programming 23: Interfacing a NEO-6MV2 GPS module with Raspberry Pi
  • RPi Python Programming 24: I2C explained
  • RPi Python Programming 25 – Synchronous serial communication in Raspberry Pi using I2C protocol
  • RPi Python Programming 26 – Interfacing ADXL345 accelerometer sensor with Raspberry Pi

Recent Articles

  • What is AWS IoT Core and when should you use it?
  • AC-DC power supply extends voltage range to 800 V DC
  • Infineon’s inductive sensor integrates coil system driver, signal conditioning circuits and DSP
  • Arm Cortex-M23 MCU delivers 87.5 µA/MHz active mode
  • STMicroelectronics releases automotive amplifiers with in-play open-load detection

EE ENGINEERING TRAINING DAYS

engineering

Submit a Guest Post

submit a guest post
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • Battery Power Tips
  • DesignFast
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • EV Engineering
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • Subscribe to our newsletter
  • About Us
  • Contact Us
  • Advertise

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy

Search Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe