1
\$\begingroup\$

The following is Verilog code an SR latch.

module SR_latch(Q, Qbar, Sbar, Rbar);
output Q, Qbar;
input Sbar, Rbar;
 
nand n1(Q, Sbar, Qbar);
nand n2(Qbar, Rbar, Q);
endmodule

I think that when an always block is used, it starts executing the code statements from top to bottom unless one is using nonblocking statements which execute in parallel. It's my understanding that an initial block which is used for testbenches always executes the code lines from top to bottom.

For the given code of SR latch, my question is that how the code lines get executed. They cannot start executing from top to bottom since the gate n1 needs Qbar as an input which comes from gate n2 which lies below n1.

toolic
10.8k11 gold badges31 silver badges35 bronze badges
asked May 24, 2022 at 1:36
\$\endgroup\$
2
  • 3
    \$\begingroup\$ Those are not "lines of code", they are a description of hardware. \$\endgroup\$ Commented May 24, 2022 at 2:04
  • \$\begingroup\$ I agree with you but still there would be a certain sequence in which they are executed when simulation is performed. \$\endgroup\$ Commented May 24, 2022 at 2:19

1 Answer 1

4
\$\begingroup\$

The initial and always constructs both instantiate procedural processes that execute concurrently; each construct creating an independent process. Within those constructs, there may be begin/end blocks where each statement within the block gets executed consecutively. Non-blocking assignments also execute consecutively within a begin/end block. It's just that the LHS does not get updated until a later region.

In gate-level modeling, each primitive you instantiate also creates a process that waits for an input to change, then schedules its output to update its value. In your example, something has to change the value of Sbar or Rbar to get the nand primitives scheduled to execute.

answered May 24, 2022 at 4:47
\$\endgroup\$
1
  • \$\begingroup\$ I'm sorry but I needed to clarify few related points. I thought it'd better to edit the question. I'd appreciate if you can help. \$\endgroup\$ Commented May 25, 2022 at 8:44

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.