Altifigence Academy

20 / 36 · 概念

Compute the next value from the old value

Read nonblocking assignments and reset priority in the code.

译文尚未提供,以下显示课时原文。 (English)

Learning goals

  • Identify the old state used by the expression
  • Read the priority between reset and increment

Calculate the next state separately

In count <= count + 2'b01, the right-hand count is the pre-update value. If it is 01, the computed next value is 10. Do not treat the expression as sequential edits to the same written value.

The nonblocking assignment <= schedules its evaluated value for the nonblocking update phase. Separating old and next values is also useful when several registers update on the same edge.

SystemVerilog
always_ff @(posedge clk)
    if (rst) count <= 2'b00;
    else count <= count + 2'b01;

One branch is taken at an edge

The if and else select one branch. With rst=1, the register stores 00 and does not take the increment branch. It does not reset to 00 and then increment to 01 on that same edge.

For a hand trace, write current count, current rst, selected branch and next count. Compare these columns with the code to check reset priority and wraparound.

自己试试

At a rising edge with count=11 and rst=1, is the result 00 or 01?

阅读解释

00. The reset branch is selected, so the increment branch is not taken on that edge.

你的选择适用于此浏览器,可随时在页脚更改。