0

Is it allowed to instantiate a module inside always_comb block in system verilog?

always_comb 
begin
   OR OR1 (.Y(A), .A(Z), 
end
2
  • 1
    if you really want to use conditional hardware, convert your module to task or function and call it conditionally. It increase your hardware resources but will meet your requirement. Commented May 17, 2016 at 8:54
  • 2
    Is there any particular reason your trying todo this rather than just instantiating it? Commented May 17, 2016 at 12:55

1 Answer 1

6

First of all, your code is incomplete. Obviously, a two-input OR gate requires three connections.

In verilog, when you are instantiating a module, that means you are adding extra hardware to the board.

This hardware must be added before simulation starts(i.e. at compile time). Here, you can not add/remove hardware at each clock pulse.

Once instantiated, the module is executed/checked for each timestamp of simulation, till the end.

So to execute any module, just instantiate it, providing the required inputs to it (and add the always block in the sub-module itself, if necessary).

// Simply instantiate module
OR OR1 (.Y(A), .A(Z), .B(M));

Either way, you can add a combinational block to the current module itself:

// Directly use ORing
always_comb begin
  A = Z | M;
end

More information on instantiation can be obtained from Verilog Module Instantiation, Instantiating Modules and Primitives, Structural Modelling links.

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.