Menu
Coddy logo textTech

Recap - Simple Math

Part of the Fundamentals section of Coddy's Verilog journey. Lesson 22 of 90.

challenge icon

Challenge

Complete the code by writing the correct arithmetic and comparison expressions.

What to do:

  1. Calculate a + b and store in add
  2. Calculate a - b and store in sub
  3. Calculate a * b and store in mul
  4. Calculate a / b and store in div
  5. Calculate a % b and store in mod
  6. Check if a is greater than b and store in gt
  7. Check if a equals b and store in eq

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
endmodule

All lessons in Fundamentals

Practice on your own: Online Verilog compiler