Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Have to say I disagree with aqua. What he (and wisemonkey) says about <code>@*</code> is right, but the rest is wrong.</p> <p>Those two lines have nothing to do with an idle state. Those statements are there as good coding practise. They ensure that those two outputs are always assigned to when that always block is evaluated. Let's see why this is important:</p> <ul> <li>Imagine that those two statements aren't there.</li> <li>Next suppose that <code>state_reg = S0</code>, and <code>a = b = 0</code></li> <li>As we evaluate the always block, we enter the case statement, s0 half, and assign 1 to <code>y1</code></li> <li><code>a</code> is zero so we don't enter the if statement, and we drop out of the case, and end the block</li> </ul> <p>At the end of the block <code>y1 == 1</code> and <code>y0 == ...</code> erm, hang on what does <code>y0</code> get? I guess it has to keep it's old value. It didn't get a new one. </p> <p>That means it's possible <code>y0</code> has to remember it's value from one cycle to the next. That would mean it needs to have some kind of memory involved, like a register or a latch. In this case it would be a latch as it's written in a style that sometimes drives the output and sometimes holds it.</p> <p>...but we don't want that. <code>y1</code> and <code>y0</code> were meant to be simple wires. Therefore we must make sure each of them are always assigned to, no matter what the state or inputs are. We could do that by having assignments in all the branches of the logic, but that becomes a lot of work. Alternatively we can have a default assignment which we later override if necessary. </p> <p>The reason these statements don't introduce <code>y1</code> going to <code>0</code> in <code>s0</code> or <code>s1</code> is because everything that happens inside an always block happens with no time passing. No time passes between the <code>0</code> being assigned at the top and the <code>1</code> in <code>s0</code> or <code>s1</code>. All that's visible is the final state.</p> <p>You'll note the code does exactly the same thing with the state variable. It has a default assignment that the next state is the current state, and then overrides that it the correct conditions are met.</p> <p>Nice clean state machine. Nothing wrong with it.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload