Recap - Simple Math
Part of the Fundamentals section of Coddy's Verilog journey — lesson 22 of 90.
Challenge
Complete the code by writing the correct arithmetic and comparison expressions.
What to do:
- Calculate
a + band store inadd - Calculate
a - band store insub - Calculate
a * band store inmul - Calculate
a / band store indiv - Calculate
a % band store inmod - Check if
ais greater thanband store ingt - Check if
aequalsband store ineq
Try it yourself
module simple_math_challenge;
reg [3:0] a, b;
reg [7:0] add, sub, mul, div, mod;
reg gt, eq;
initial begin
a = 4'd13;
b = 4'd4;
add = ______; // a + b
sub = ______; // a - b
mul = ______; // a * b
div = ______; // a / b
mod = ______; // a % b
gt = ______; // a > b
eq = ______; // a == b
$display("13 + 4 = %d", add);
$display("13 - 4 = %d", sub);
$display("13 * 4 = %d", mul);
$display("13 / 4 = %d", div);
$display("13 %% 4 = %d", mod);
$display("13 > 4 = %d", gt);
$display("13 == 4 = %d", eq);
$finish;
end
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