【发布时间】:2012-11-10 13:51:08
【问题描述】:
总的来说,我是编程新手,我发现自己过于依赖条件语句。我发现它们与我在编码时的思路相似,这使得它们易于实现。
下面我在 Verilog 中有一个小代码 sn-p,它控制数字时钟显示。整个代码几乎都是以这种方式布局的。该代码有效并且非常易读。但是,我觉得它不优雅。是否可以在简化代码的同时提高可读性?
if (cnt >= clkspeed) begin
cnt = 0;
out0 <= out0 + 4'h1;
// LED0 > 9 -> LED1 += 1
if (out0 == 4'h9) begin
out0 <= 4'h0;
out1 <= out1 + 4'h1;
// LED1 > 5 -> LED2 += 1
if (out1 == 4'h5) begin
out1 <= 4'h0;
out2 <= out2 + 4'h1;
// LED2 > 9 -> LED3 += 1
if (out2 == 4'h9) begin
out2 <= 4'h0;
out3 <= out3 + 4'h1;
// LED3 > 5 -> LED3 = 0
if (out3 == 4'h5) begin
out3 <= 4'h0;
end
end
end
end
end
【问题讨论】:
标签: verilog if-statement simplify