Case |
LRM §9.5. |
The case statement selects for execution one of several alternative statements; the alternative is chosen based on the value of the associated expression.
case_word ( expression ) case_match : statement [ default [ : ] statement ] endcase case_word = case | casex | casez
The case statement compares the expression to each case_match and executes the statement associated with the first matching case. It executes the default if none of the case matches. If no default is specified, the case statement has no effect.
If more than one statement is to be executed for a particular match, the statements must be enclosed in a begin-end or fork-join block.
The casex is a special version of the case statement which uses X or Z logic values to represent don't care bits.
The casez is a special version of the case statement which uses a Z logic value to represent don't care bits.
case (Addr) 0 : Q <= 1; 1 : begin Q <= 1; R <= 0; end 2, 3 : R <= 1; default : $display("Illegal Addr value", Addr); endcase casez (Opcode) 2'b1?? : Q <= 2'b01; 2'b000 : Q <= 2'b00; 2'b10? : Q <= 2'b10; default : Q <= 2'bxx; endcase