This is probably an absolute newbie question but what happens to "unchanged" output register as in the following example(pseudocode):

module TOP(
   input CLK,
   input A,
   input B,
   output reg O1,
   output reg O2

reg state = 0;

always @(posedge CLK) begin
      0: begin   
          O1 <= A;
          state <= 1;
      1: begin   
          O2 <= B;
          state <= 0;

Do O1 and O2 keep the same value as for the last pass where they were specifically set or are they undefined in the pass where they are not specifically set?

Thank you very much in advance!

  • 1
    \$\begingroup\$ Previous values are retained if not otherwise set on any given path through the always block. \$\endgroup\$ – Dave Tweed Jul 3 '20 at 15:53

Once you assign a register variable* with = or <=, it retains its value until the next time it is assigned.

* Verilog "register variables" do not always represent actual registers in synthesized hardware.


When working with a hardware description language you must always think of the hardware implementation to better understand the expected result.

It is a good idea to check some available tools especially for simple descriptions like this one. This lets you mastering the HDL like Verilog.

For instance, the Netlist Viewer can show you the hardware implementation for your description. In your case it is the following:

enter image description here

This shows that at the arrival of the clock, depending on the "state" resulting of the previous clock, B or A are assigned. And "state" is complemented and this complemented value will be used in the next clock for assigning A or B. the outputs of the latches are of course maintained between clocks.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.