0
0
Verilogprogramming~10 mins

Case statement for multiplexing in Verilog - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to assign output based on select signal using a case statement.

Verilog
always @(*) begin
  case(sel)
    2'b00: out = in0;
    2'b01: out = in1;
    2'b10: out = in2;
    default: out = [1];
  endcase
end
Drag options to blanks, or click blank then click option'
A1'b0
Bin3
C1'b1
Dsel
Attempts:
3 left
💡 Hint
Common Mistakes
Using an undefined signal in the default case.
Forgetting the default case causing latches.
2fill in blank
medium

Complete the case statement to select the correct input based on 2-bit select signal.

Verilog
always @(*) begin
  case([1])
    2'b00: out = in0;
    2'b01: out = in1;
    2'b10: out = in2;
    2'b11: out = in3;
  endcase
end
Drag options to blanks, or click blank then click option'
Aclk
Bout
Cin0
Dsel
Attempts:
3 left
💡 Hint
Common Mistakes
Using output or input signals as the case expression.
Using clock signal instead of select signal.
3fill in blank
hard

Fix the error in the case statement to correctly assign output based on select signal.

Verilog
always @(*) begin
  case(sel)
    2'b00: out = in0;
    2'b01: out = in1;
    2'b10: out = in2;
    2'b11: out = in3;
    default: out = [1];
  endcase
end
Drag options to blanks, or click blank then click option'
A1'b0
Bsel
C1'bx
Din4
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning an undefined input in default case.
Using select signal as default output.
4fill in blank
hard

Fill both blanks to complete the case statement for a 4-to-1 multiplexer.

Verilog
always @(*) begin
  case([1])
    2'b00: out = in0;
    2'b01: out = in1;
    2'b10: out = in2;
    2'b11: out = in3;
    default: out = [2];
  endcase
end
Drag options to blanks, or click blank then click option'
Asel
B1'b0
C1'b1
Din4
Attempts:
3 left
💡 Hint
Common Mistakes
Using input signals or constants as case expression.
Assigning undefined signals in default case.
5fill in blank
hard

Fill all three blanks to complete the case statement for a 4-input multiplexer with default output zero.

Verilog
always @(*) begin
  case([1])
    2'b00: out = [2];
    2'b01: out = [3];
    2'b10: out = in2;
    2'b11: out = in3;
    default: out = 1'b0;
  endcase
end
Drag options to blanks, or click blank then click option'
Asel
Bin0
Cin1
Din4
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing input signals in wrong case branches.
Using wrong variable as case expression.