1
\$\begingroup\$

Can I "break" an always blocks in Verilog? I would like to rewrite

 always @(posedge clk_i or posedge rst_i) begin
 if(rst_i) begin
 // Do stuff
 end else begin
 // Do stuff
 end
 end

as follows (which I find cleaner):

 always @(posedge clk_i or posedge rst_i) begin
 if(rst_i) begin
 // Do stuff
 break;
 end
 // Do stuff
 end
asked Nov 29, 2012 at 11:05
\$\endgroup\$
1
  • \$\begingroup\$ This seems dangerously close to forgetting that the operations described are not executed sequentially as in a software programming language, but rather in parallel. \$\endgroup\$ Commented Nov 29, 2012 at 15:31

1 Answer 1

5
\$\begingroup\$

Yes, you should name your begin-end block and then use disable statement like this:

always @(posedge clk_i or posedge rst_i) begin : block_to_disable
 if(rst_i) begin
 // Do stuff
 disable block_to_disable;
 end
 // Do stuff
end

Though, this is probably non-synthesizable, so you can do such tricks only in simulation (testbenches, etc.).

answered Nov 29, 2012 at 14:01
\$\endgroup\$
3
  • \$\begingroup\$ I'd feel that if the compiler made a bit of an effort, this could be synthesizable. \$\endgroup\$ Commented Nov 29, 2012 at 14:05
  • \$\begingroup\$ @Randomblue - you'd be better off learning to think in terms of hardware operation, than expecting the tools to synthesize from software paradigms. Remember these are not sequential operations - everything happens at the same time. \$\endgroup\$ Commented Nov 29, 2012 at 15:30
  • \$\begingroup\$ I understand that. But there is the rule that when multiple assignments to the same register are done, the last one wins. There is no ambiguity. So the compiler just has to figure out the last assignment for every possible combination of the input signals. \$\endgroup\$ Commented Nov 29, 2012 at 15:32

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.