{"id":96,"date":"2015-09-13T18:01:11","date_gmt":"2015-09-13T18:01:11","guid":{"rendered":"http:\/\/www.verilogpro.com\/?p=96"},"modified":"2022-06-27T00:43:12","modified_gmt":"2022-06-27T07:43:12","slug":"verilog-case-casez-casex","status":"publish","type":"post","link":"https:\/\/www.verilogpro.com\/verilog-case-casez-casex\/","title":{"rendered":"Verilog twins: case, casez, casex. Which Should I Use?"},"content":{"rendered":"\n
The Verilog case<\/b> statement is a convenient structure to code various logic like decoders, encoders, onehot state machines. Verilog defines three versions of the case statement: case<\/b>, casez<\/b>, casex<\/b>. Not only is it easy to confuse them, but there are subtleties between them that can trip up even experienced coders. In this article I will highlight the identifying features of each of the twins, and discuss when each should be used.<\/p>\n\n\n\nBasic Verilog Case Statement<\/h3>\n\n\n\n
Let’s start by reviewing the basic case<\/b> statement:<\/p>\n\n\n\n A case statement has the following parts:<\/p>\n\n\n\ncase (case_expression) \/\/ case statement header\n case_item_1 : begin\n case_statement_1a;\n case_statement_1b;\n end\n case_item_2 : case_statement_2;\n default : case_statement_default;\nendcase<\/pre>\n\n\n\n