2

I have assigned names to numbers using:

`define ADD 0
`define SUB 1
`define LSF 2
`define RSF 3
`define AND 4
`define OR 5

I'd like to handle in a case block such that the code will apply for more than one option. In C this can be done using:

switch (x){

case ADD:
case SUB:
case LSF:
case RSF:
case AND:
case OR:
    printf ("Handling");
    break;
}

Is there a way to achieve that in Verilog? Thanks!

1 Answer 1

6

Yup, commas!

case (x)
ADD, SUB, LSF, RSF, AND, OR: begin
    $display("Handling multiple cases");
    // no need for breaks
end
MULT: begin
    $display("handle a single case");
end
default: begin
    $display("do something to do for all other cases");
end
endcase
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.