Designing The Logic
Part of the Fundamentals section of Coddy's Verilog journey — lesson 44 of 90.
Challenge
Designing the logic means figuring out what equations the circuit needs based on the truth table.
Truth Table:
| a | b | sum | carry |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 1 |
Step 2: Find the pattern for sum
- sum = 1 when a=0,b=1 or a=1,b=0
- sum = 1 when a and b are different
- Different = XOR →
sum = a ^ b
Step 3: Find the pattern for carry
- carry = 1 only when a=1 and b=1
- Both = AND →
carry = a & b
Step 4: Write equations
sum = a ^ b
carry = a & b
What to do:
Your task is to add the missing logic equations inside the module.
1. Add an assign statement for sum (a XOR b)
2. Add an assign statement for carry (a AND b)
Try it yourself
module half_adder (
input a,
input b,
output sum,
output carry
);
endmoduleAll 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