Electronic – case statement without always

verilog

Can I have a case statement without a always block like an inline if condition does not need a always function?

assign WORD_OUT = (SELECT_BIT_IN) ? WORD_IN1 : WORD_IN2;    

but if I try this,

assign WORD_OUT = case (SELECT_BIT_IN)
    4'd0 : WORD_IN0;
    4'd1 : WORD_IN1;

or this

case (SELECT_BIT_IN)
    1'd0 : assign WORD_OUT = WORD_IN0;
    1'd1 : assign WORD_OUT = WORD_IN1;

It gives me an error.

I am trying to avoid using any registers.

Best Answer

You can't. A case statement should always be in an always or initial block.

You have two choices if you don't want to use ternary conditionals. The first is use an always block which doesn't have edge sensitivity as shown below. This does not infer registers (that's not what declare the signal of reg type means), it infers a multiplexer with constant assignment - as there is no clock, so there is no register, the * simply means any input change.

reg WORD_OUT;

always @ * begin
    case (SELECT_BIT_IN)
    ...
    WORD_OUT = WORD_IN0;
    ...
    endcase
end

Alternatively specifically infer a ROM or multiplexer depending on what your input signals are (possibly instantiate a module of one). If the inputs are constants (like parameters), then your case simply infers a ROM. If the inputs are nets, then your code infers a multiplexer.