Altifigence Academy

20 / 36 · Conceito

Compute the next value from the old value

Read nonblocking assignments and reset priority in the code.

A tradução ainda não está disponível. A aula original é exibida. (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.

Experimente

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

Ler a explicação

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

Sua escolha vale neste navegador. Altere-a a qualquer momento no rodapé.