Menu
Coddy logo textTech

Using Case Statement

Part of the Fundamentals section of Coddy's Verilog journey — lesson 66 of 90.

challenge icon

Challenge

Build a 4-to-1 multiplexer using a case statement instead of if-else.

Truth Table

selout
00out = in0
01out = in1
10out = in2
11out = in3

What to do:

  1. Create a module named mux4to1_case
  2. Add inputs in0, in1, in2, in3 (1 bit each)
  3. Add input sel (2 bits)
  4. Add output out (1 bit, type reg)
  5. Add an always @(*) block
  6. Inside, add a case (sel) statement
  7. Add cases for 2'b00, 2'b01, 2'b10, 2'b11
  8. Add a default case
  9. Close with endcase and endmodule

Try it yourself

// TODO: Create module named mux4to1_case

// TODO: Add inputs: in0, in1, in2, in3 (1 bit each)

// TODO: Add input sel (2 bits)

// TODO: Add output out (reg type)

// TODO: Add always @(*) block

// TODO: Add case (sel)

// TODO: Add case 2'b00: out = in0;

// TODO: Add case 2'b01: out = in1;

// TODO: Add case 2'b10: out = in2;

// TODO: Add case 2'b11: out = in3;

// TODO: Add default: out = in0;

// TODO: Add endcase

// TODO: Add endmodule

All lessons in Fundamentals