Writing The Module
Part of the Fundamentals section of Coddy's Verilog journey — lesson 43 of 90.
Challenge
A half adder is a circuit that adds two single bits and tells you:
- sum — the result (0 or 1)
- carry — if there is an overflow (1 when both inputs are 1)
Example
| a | b | sum | carry |
|---|---|---|---|
| 0 | 0 | 0 | no overflow |
| 0 | 1 | 1 | no overflow |
| 1 | 0 | 1 | no overflow |
| 1 | 1 | 0 | overflow (carry = 1) |
When you add 1 + 1 in binary, the result is 0 with a carry of 1 (just like 5 + 5 = 0 with a carry of 1 in decimal).
Before we add the logic, we need to create the module container — the empty shell that will hold our half adder circuit.
For a half adder, these are the tasks:
- Create a module called
half_adder - Add two inputs:
aandb - Add two outputs:
sumandcarry
Try it yourself
// Task 1: Create a module named half_adder
// Task 2: Add two inputs: a and b
// Task 3: Add two outputs: sum and carry
// Logic will be added later
All lessons in Fundamentals
4Operators Part 1
Arithmetic OperatorsModulo OperatorComparison OperatorsRecap - Simple MathBitwise Operators7Assign And Gates
Continuous AssignmentAssign With OperatorsBuilt In Gate PrimitivesAND OR NOT GatesXOR XNOR GatesRecap - Logic Gate Circuit10Decision Making
If StatementIf - ElseRecap - Simple ComparatorCase StatementCasex And CasezRecap - ALU Design5Operators Part 2
Logical OperatorsReduction OperatorsShift OperatorsConcatenation OperatorConditional OperatorRecap - Operator Challenge3Number System
Binary RepresentationSized NumbersUnsized NumbersNegative NumbersSpecial Values X And ZRecap - Number Formats6Modules
Module StructureInput And Output PortsInout PortsModule InstantiationPort Mapping By NamePort Mapping By OrderRecap - Build A Module9Procedural Blocks
Always BlockInitial BlockSensitivity ListBlocking AssignmentNon Blocking AssignmentRecap - Always vs Initial15Traffic Light Controller
Defining The StatesState Machine Logic