← ProblemsVerilog Language / Procedures
Case statement
64%proceduresconditionalsmuxA case statement is the tidy way to write a large multiplexer: one comparison expression, many alternatives.
Build a 6-to-1 multiplexer of 4-bit values. When sel is 0 through 5, output the matching data input (data0 … data5). For sel values 6 and 7, output 4'b0.
Use a case inside an always @(*) block, and make sure a default arm (or equivalent) covers the unused select values — otherwise you'd infer a latch.