2

I have the following in Verilog:

reg a;

always @ (clk)
begin
  a = 0;
  a <= 1;
  $display(a);
end

What value of literal 'a' would show me? Is that 0 or 1?

9
  • Have you tried simulating it? Commented May 11, 2014 at 4:38
  • possible duplicate of How to interpret blocking vs non blocking assignments in Verilog? Commented May 11, 2014 at 11:36
  • @Qiu, this is not duplicate of that. It is close to that, but I want to see others' answers. --- I know the following about scheduling semantics in Verilog simulators: the order in which events are scheduled to execute is as below: 1- active events such as blocking assignment and RHS calculation of non-blocking assignments. 2- Inactive assignments, and 3- Nonblocking assign update. For the above example, I believe $display may show 0 or 1, depending on when display gets executed. Commented May 12, 2014 at 5:29
  • @Ari, can you recommend a good simulator in Mac that is free for use so I can simulate this? Commented May 12, 2014 at 5:34
  • There's a simple answer to your (good) question, but you've posted code that has obviously never been near a simulator. If you fixed it first, you'd be more likely to get an answer. Commented May 12, 2014 at 8:46

1 Answer 1

3

Verilog simulation occurs in 5 queues as stated in IEEE 1364-1995 § 5.3, IEEE 1364-2001 § 5.3, and IEEE 1364-2005 § 11.3:

  • Active Event (before #0)
    • Evaluate RHS of all non-blocking assignment
    • Evaluate RHS and change LHS of all blocking assignments
    • Evaluate RHS and change LHS of all continuous assignments
    • Evaluate inputs and change outputs of all primitives
    • Evaluate and print output from $display and $write
  • Inactive Event (after #0)
    • Evaluate RHS after #0 delay, otherwize same processes as Active Event
    • Callback procedures scheduled with PLI routines such as tf_synchronize()(deprecated in IEEE 1364-2005) and vpi_register_cb(cbReadWriteSynch)
  • NBA Update
    • Change LHS of all non-blocking assignments
  • Monitor Event
    • Evaluate and print output from $monitor and $strobe
    • Call PLI with reason_rosynchronize(deprecated in IEEE 1364-2005)
  • Future
    • Events to occur at some future simulation time

Since $display occurs before the non-blocking assignment is assigned , the value will be 0. Note the order of execution may change in each queue.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.