{"id":203786,"date":"2020-10-31T09:10:01","date_gmt":"2020-10-31T01:10:01","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=203786"},"modified":"2020-10-26T19:10:53","modified_gmt":"2020-10-26T11:10:53","slug":"introduction-to-verilog","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/introduction-to-verilog.html","title":{"rendered":"Verilog \u591a\u8def\u5206\u652f\u8bed\u53e5\u7b80\u4ecb"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\ncase \u8bed\u53e5\u662f\u4e00\u79cd\u591a\u8def\u6761\u4ef6\u5206\u652f\u7684\u5f62\u5f0f\uff0c\u53ef\u4ee5\u89e3\u51b3 if \u8bed\u53e5\u4e2d\u6709\u591a\u4e2a\u6761\u4ef6\u9009\u9879\u65f6\u4f7f\u7528\u4e0d\u65b9\u4fbf\u7684\u95ee\u9898\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\"\"<\/p>\n

\u5173\u952e\u8bcd\uff1acase\uff0c\u9009\u62e9\u5668<\/strong><\/div>\n

case \u8bed\u53e5\u662f\u4e00\u79cd\u591a\u8def\u6761\u4ef6\u5206\u652f\u7684\u5f62\u5f0f\uff0c\u53ef\u4ee5\u89e3\u51b3 if \u8bed\u53e5\u4e2d\u6709\u591a\u4e2a\u6761\u4ef6\u9009\u9879\u65f6\u4f7f\u7528\u4e0d\u65b9\u4fbf\u7684\u95ee\u9898\u3002<\/p>\n

case \u8bed\u53e5<\/strong><\/div>\n

case \u8bed\u53e5\u683c\u5f0f\u5982\u4e0b\uff1a<\/p>\n

case(case_expr)\r\n    condition1     :             true_statement1 ;\r\n    condition2     :             true_statement2 ;\r\n    \u2026\u2026\r\n    default        :             default_statement ;\r\nendcase<\/pre>\n

case \u8bed\u53e5\u6267\u884c\u65f6\uff0c\u5982\u679c condition1 \u4e3a\u771f\uff0c\u5219\u6267\u884c true_statement1 ; \u5982\u679c condition1 \u4e3a\u5047\uff0ccondition2 \u4e3a\u771f\uff0c\u5219\u6267\u884c true_statement2\uff1b\u4f9d\u6b21\u7c7b\u63a8\u3002\u5982\u679c\u5404\u4e2a condition \u90fd\u4e0d\u4e3a\u771f\uff0c\u5219\u6267\u884c default_statement \u8bed\u53e5\u3002<\/p>\n

default \u8bed\u53e5\u662f\u53ef\u9009\u7684\uff0c\u4e14\u5728\u4e00\u4e2a case \u8bed\u53e5\u4e2d\u4e0d\u80fd\u6709\u591a\u4e2a default \u8bed\u53e5\u3002<\/p>\n

\u6761\u4ef6\u9009\u9879\u53ef\u4ee5\u6709\u591a\u4e2a\uff0c\u4e0d\u4ec5\u9650\u4e8e condition1\u3001condition2 \u7b49\uff0c\u800c\u4e14\u8fd9\u4e9b\u6761\u4ef6\u9009\u9879\u4e0d\u8981\u6c42\u4e92\u65a5\u3002\u867d\u7136\u8fd9\u4e9b\u6761\u4ef6\u9009\u9879\u662f\u5e76\u53d1\u6bd4\u8f83\u7684\uff0c\u4f46\u6267\u884c\u6548\u679c\u662f\u8c01\u5728\u524d\u4e14\u6761\u4ef6\u4e3a\u771f\u8c01\u88ab\u6267\u884c\u3002<\/p>\n

ture_statement1 \u7b49\u6267\u884c\u8bed\u53e5\u53ef\u4ee5\u662f\u4e00\u6761\u8bed\u53e5\uff0c\u4e5f\u53ef\u4ee5\u662f\u591a\u6761\u3002\u5982\u679c\u662f\u591a\u6761\u6267\u884c\u8bed\u53e5\uff0c\u5219\u9700\u8981\u7528 begin \u4e0e end \u5173\u952e\u5b57\u8fdb\u884c\u8bf4\u660e\u3002<\/p>\n

case \u8bed\u53e5\u652f\u6301\u5d4c\u5957\u4f7f\u7528\u3002<\/strong><\/span><\/div>\n

\u4e0b\u9762\u7528 case \u8bed\u53e5\u4ee3\u66ff if \u8bed\u53e5\u5b9e\u73b0\u4e86\u4e00\u4e2a 4 \u8def\u9009\u62e9\u5668\u7684\u529f\u80fd\u3002\u4eff\u771f\u7ed3\u679c\u4e0e testbench \u53ef\u53c2\u8003\u6761\u4ef6\u8bed\u53e5\u4e00\u7ae0\uff0c\u4e24\u8005\u5b8c\u5168\u4e00\u81f4\u3002<\/p>\n

\u5b9e\u4f8b<\/strong><\/p>\n

module mux4to1(\r\n    input [1:0]     sel ,\r\n    input [1:0]     p0 ,\r\n    input [1:0]     p1 ,\r\n    input [1:0]     p2 ,\r\n    input [1:0]     p3 ,\r\n    output [1:0]    sout);\r\n \r\n    reg [1:0]     sout_t ;\r\n    always @(*)\r\n        case(sel)\r\n            2'b00:   begin      \r\n                    sout_t = p0 ;\r\n                end\r\n            2'b01:       sout_t = p1 ;\r\n            2'b10:       sout_t = p2 ;\r\n            default:     sout_t = p3 ;\r\n        endcase\r\n    assign sout = sout_t ;\r\n \r\nendmodule<\/pre>\n

case \u8bed\u53e5\u4e2d\u7684\u6761\u4ef6\u9009\u9879\u8868\u5355\u5f0f\u4e0d\u5fc5\u90fd\u662f\u5e38\u91cf\uff0c\u4e5f\u53ef\u4ee5\u662f x \u503c\u6216 z \u503c\u3002<\/p>\n

\u5f53\u591a\u4e2a\u6761\u4ef6\u9009\u9879\u4e0b\u9700\u8981\u6267\u884c\u76f8\u540c\u7684\u8bed\u53e5\u65f6\uff0c\u591a\u4e2a\u6761\u4ef6\u9009\u9879\u53ef\u4ee5\u7528\u9017\u53f7\u5206\u5f00\uff0c\u653e\u5728\u540c\u4e00\u4e2a\u8bed\u53e5\u5757\u7684\u5019\u9009\u9879\u4e2d\u3002<\/p>\n

\u4f46\u662f case \u8bed\u53e5\u4e2d\u7684 x \u6216 z \u7684\u6bd4\u8f83\u903b\u8f91\u662f\u4e0d\u53ef\u7efc\u5408\u7684\uff0c\u6240\u4ee5\u4e00\u822c\u4e0d\u5efa\u8bae\u5728 case \u8bed\u53e5\u4e2d\u4f7f\u7528 x \u6216 z \u4f5c\u4e3a\u6bd4\u8f83\u503c\u3002<\/p>\n

\u4f8b\u5982\uff0c\u5bf9 4 \u8def\u9009\u62e9\u5668\u7684 case \u8bed\u53e5\u8fdb\u884c\u6269\u5c55\uff0c\u4e3e\u4f8b\u5982\u4e0b\uff1a<\/p>\n

\u5b9e\u4f8b<\/strong><\/p>\n

case(sel)\r\n    2'b00:   sout_t = p0 ;\r\n    2'b01:   sout_t = p1 ;\r\n    2'b10:   sout_t = p2 ;\r\n    2'b11:     sout_t = p3 ;\r\n    2'bx0, 2'bx1, 2'bxz, 2'bxx, 2'b0x, 2'b1x, 2'bzx :\r\n        sout_t = 2'bxx ;\r\n    2'bz0, 2'bz1, 2'bzz, 2'b0z, 2'b1z :\r\n        sout_t = 2'bzz ;\r\n    default:  $display(\"Unexpected input control!!!\");\r\nendcase<\/pre>\n
casex\/casez \u8bed\u53e5<\/strong><\/div>\n

casex\u3001 casez \u8bed\u53e5\u662f case \u8bed\u53e5\u7684\u53d8\u5f62\uff0c\u7528\u6765\u8868\u793a\u6761\u4ef6\u9009\u9879\u4e2d\u7684\u65e0\u5173\u9879\u3002<\/p>\n

casex \u7528 \"x\" \u6765\u8868\u793a\u65e0\u5173\u503c\uff0ccasez \u7528\u95ee\u53f7 \"?\" \u6765\u8868\u793a\u65e0\u5173\u503c\u3002<\/p>\n

\u4e24\u8005\u7684\u5b9e\u73b0\u7684\u529f\u80fd\u662f\u5b8c\u5168\u4e00\u81f4\u7684\uff0c\u8bed\u6cd5\u4e0e case \u8bed\u53e5\u4e5f\u5b8c\u5168\u4e00\u81f4\u3002<\/p>\n

\u4f46\u662f casex\u3001casez \u4e00\u822c\u662f\u4e0d\u53ef\u7efc\u5408\u7684\uff0c\u591a\u7528\u4e8e\u4eff\u771f\u3002<\/p>\n

\u4f8b\u5982\u7528 casez \u8bed\u53e5\u6765\u5b9e\u73b0\u4e00\u4e2a 4bit \u63a7\u5236\u7aef\u7684 4 \u8def\u9009\u62e9\u9009\u62e9\u5668\u3002<\/p>\n

\u5b9e\u4f8b<\/strong><\/p>\n

module mux4to1(\r\n    input [3:0]     sel ,\r\n    input [1:0]     p0 ,\r\n    input [1:0]     p1 ,\r\n    input [1:0]     p2 ,\r\n    input [1:0]     p3 ,\r\n    output [1:0]    sout);\r\n \r\n    reg [1:0]     sout_t ;\r\n    always @(*)\r\n        casez(sel)\r\n            4'b???1:     sout_t = p0 ;\r\n            4'b??1?:     sout_t = p1 ;\r\n            4'b?1??:     sout_t = p2 ;\r\n            4'b1???:     sout_t = p3 ;  \r\n        default:         sout_t = 2'b0 ;\r\n    endcase\r\n    assign      sout = sout_t ;\r\n \r\nendmodule<\/pre>\n","protected":false},"excerpt":{"rendered":"

case \u8bed\u53e5\u662f\u4e00\u79cd\u591a\u8def\u6761\u4ef6\u5206\u652f\u7684\u5f62\u5f0f\uff0c\u53ef\u4ee5\u89e3\u51b3 if \u8bed\u53e5\u4e2d\u6709\u591a\u4e2a\u6761\u4ef6\u9009\u9879\u65f6\u4f7f\u7528\u4e0d\u65b9\u4fbf\u7684\u95ee\u9898\u3002 case \u8bed […]<\/p>\n","protected":false},"author":1481,"featured_media":203787,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-203786","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/203786","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1481"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=203786"}],"version-history":[{"count":2,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/203786\/revisions"}],"predecessor-version":[{"id":203790,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/203786\/revisions\/203790"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/203787"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=203786"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=203786"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=203786"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}