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

Verilog Tutorial 10: How to design half and full-adder circuits in Verilog

By Ashutosh Bhatt April 28, 2025

Note: it’s recommended to follow this VHDL tutorial series in order, starting with the first tutorial. Follow the full series here.

In the previous tutorial, VHDL Tutorial – 9, we learned how to build digital circuits using Boolean equations.

In this tutorial, we’ll:

  1. Write a Verilog program that builds half and full-adder circuits
  2. Verify the output waveform of the program (digital circuit) with the truth table for the half and full-adder circuits.

Half-adder circuit

Truth table

Let’s write the VHDL program, compile and simulate it, and get the output in a waveform. We’ll also verify the output waveforms with the given truth table.

First, it’s important to review the step-by-step procedure provided in VHDL Tutorial – 3. In that tutorial, we learn how to design a project, edit and compile a program, create a waveform file, simulate the program, and generate the final output waveforms.

VHDL program

Gate-level modeling:

module half_adder(a,b,sum,cry);
  input a,b;
  output sum,cry;
     xor(sum,a,b);
     and(cry,a,b);
endmodule

Dataflow modeling:

module half_adder(a,b,sum,cry);
  input a,b;
  output sum,cry;
     assign sum = a ^ b;
     assign cry = a & b;
endmodule

Behavior modeling:

module half_adder(a,b,sum,cry);
  input a,b;
  output sum,cry;
  always @(a, b)
   begin
      cry = a & b;
       sum = a ^ b;
   end
 endmodule

Next, compile the above program, creating a waveform file with all of the necessary inputs and outputs that are listed, and simulate the project. 

Here are the results…

Waveform simulation

Verify that the ‘sum’ and ‘cry’ output waveforms against the given truth table. For the ‘a=1’ and ‘b=0’ inputs, the outputs are ‘sum=1’ and ‘cry=0,’ as highlighted in the above figure.

Now let’s move on to the full-adder circuit design.

Full-adder circuit

Verilog program

Gate-level modeling:

module full_adder(a,b,cin,sum,carry);
input a,b,cin;
output sum,carry;
wire w1,w2,w3,w4;      

  xor(w1,a,b);
  xor(sum,w1,cin);        //Sum output
  and(w2,a,b);
  and(w3,b,cin);
  and(w4,cin,a);

  or(carry,w2,w3,w4);    
endmodule

Dataflow modellng:

module full_adder(a,b,cin,sum,carry);
  input a,b,cin;
  output sum,carry;
  assign sum = a ^ b ^ cin;
  assign carry = (a & b) | (b & cin)  | (cin & a) ;
endmodule

Next, let’s explore the same program using a different style called structural modeling, where the complete program is divided into different modules.. This style hasn’t been required in the previous tutorials.

For this program, we’ll first create a module for a half-adder and then use it twice. This is called module instantiation. In Verilog, one complete module can be instantiated inside another program, which is a fundamental feature of its programming.

Structural modeling is useful for building large and complex Verilog programs because it allows a complex design to be divided into smaller, more manageable modules. These modules are then instantiated wherever needed in the main program.

//////////// Verilog module of half adder ///////////////

module half_adr(a,b,sum,cy);
 input a,b;
 output sum,cy;
  xor(sum,a,b);
  and(cy,a,b);
endmodule

////// Verilog main program of full adder /////////////

module full_adder(a,b,cin,sum,carry);
 input a,b,cin;
 output sum,carry;
 wire w1,w2,w3;
 half_adr HA1(a,b,w1,w2);     // module instantiation
 half_adr HA2(w1,cin,sum,w3);
 or(carry,w2,w3);
endmodule

Simulation waveform

Remember to compare the outputs, ‘sum’ and ‘carry’ with the given truth table. As shown in the above figure, one is highlighted as ‘a=1,’ ‘b=1,’ and ‘cin=0,’ with the outputs of ‘sum=0’ and ‘carry=1.’

In next tutorial, we’ll learn how to design half and full-subtractor circuits using Verilog.

 

You may also like:


  • How to design a digital circuit for a Boolean equation…

  • How to use NOR as the universal gate in Verilog

  • How to design and verify D’Morgan’s Theorem in Verilog-Part 6

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

  • 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: adder, fulladder, halfadder, tutorial, verilog
 

Next Article

← Previous Article
Next Article →

Questions related to this article?
👉Ask and discuss on Electro-Tech-Online.com and EDAboard.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