|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
x
今天碰到别人写的一个计数器:
reg [2:0] cnt;
always @(posedge clk,negedge rst)
begin
if(rst)
cnt <= 3'd0;
else begin
cnt <= cnt + 3'd1;
if(cnt == 3'd3)
cnt <= 3'd0;
end
end
这样写的方式跟我们平时写的方式有出入,结果我就产生了疑问,这样的写法是基于怎样的考虑,
有考虑到实际的硬件电路?
ps:习惯写法:
reg [2:0] cnt;
always @(posedge clk,negedge rst)
begin
if(rst)
cnt <= 3'd0;
else if(cnt == 3'd3)
cnt <= 3'd0;
else
cnt <= cnt + 3'd1;
end |
|