Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8971533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:58:53+00:00 2026-06-15T17:58:53+00:00

I have a verilog code where I wish to use recursion. However, whenever I

  • 0

I have a verilog code where I wish to use recursion. However, whenever I try this in an always block, it gives an error saying is not a task.

Is there any way I can implement a module in an always block? Also is there anyway I can use recursion within the always block?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T17:58:54+00:00Added an answer on June 15, 2026 at 5:58 pm

    You can write recursive modules using a generate block:

    module unary_and
    #(parameter WIDTH = 32)
    (input [WIDTH-1:0] in_and,
    output            out_and)
    
    generate
     if(WIDTH == 1) begin
       assign out_and = in_and;
     end
     else if(WIDTH == 2) begin
       assign out_and = in_and[0] & in_and[1];
     end
     else begin
       unary_and #(.WIDTH (WIDTH/2))
         unary_and_low
           (.in_and  (in_and[WIDTH/2-1:0]),
            .out_and (out_and_low));
    
       unary_and #(.WIDTH (WIDTH - WIDTH/2))
         unary_and_high
           (.in_and  (in_and[WIDTH-1:WIDTH/2]),
            .out_and (out_and_high));
    
       assign out_and = out_and_low & out_and_high;
     end
    endgenerate
    endmodule
    

    This is from Recursive and Iterative designs in Verilog where you can find other solutions as well. You can check out Recursive Modules too.

    Maybe you should also take a look at these questions and answers:
    Could we have generate inside an always block?
    Verilog generate/genvar in an always block

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have problems with this Verilog code. Basically, it won't let me do the
I have been reading verilog code online and have noticed this in many of
I have a top level Verilog module that instantiates a VHDL block with a
I have a simple question regarding how to write an always block in a
I have the following line of verilog code that i want to convert to
Have written all the code in a silverlight class library (dll) and linked this
Have a look at this HTML code: <div class=overlay> <a href=#>1</a> <a href=#>1</a> <a
Have a look at this code: #include <iostream> using namespace std; int main() {
I have a piece of Verilog code worked upon by a programmer no longer
I have a regular expression to find :ABC:`hello` pattern. This is the code. format

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.