← ProblemsVerilog Language / Procedures

If statement

64%proceduresconditionalsmux

An if statement inside a combinational always block is just another way to describe a multiplexer.

Build a 2-to-1 mux that outputs b when both sel_b1 and sel_b2 are 1, and outputs a otherwise. Implement it twice:

  • out_assign: using an assign with the conditional (ternary) operator
  • out_always: using an if/else inside an always @(*) block

Both outputs implement the exact same function.