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 6188289
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:12:25+00:00 2026-05-24T02:12:25+00:00

I am trying to write this code: for (i = 0; i <= CONST

  • 0

I am trying to write this code:

 for (i = 0; i <= CONST - 1'b1; i = i + 1'b1)
                    begin : loop_inst

                        if (i < 3)
                        begin
                            if (changed[i] & !done_q[i])
                            begin
                                writedata[3-i] = en[i];
                                writedata[2-i:0] = readdata[2-i:0];
                                writedata[15:4-i] = readdata[15:4-i];
                            end
                        end
                        else
                        ...

Basically, the location of the bit I am trying to write to (en) changes depending on which address I am talking to, depending on i. This code is not synthesizable because i is not a constant.

Is there any other workaround to this? The only workaround I know is writing out those three statements CONST times. I am hoping I DON’T have to do that in the end. Is there any other solution?

  • 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-05-24T02:12:26+00:00Added an answer on May 24, 2026 at 2:12 am

    It looks like you’re trying to copy readdata to writedata all the time, but fill in the LSBs with en if certain special case conditions are met. I’m also going to assume that the for loop you have is in an always block, and that you’re intending to build combo logic.

    The for loop as you’ve it written doesn’t make much sense to me from a hardware perspective. A for loop is used for building arrays of logic, and as you’ve
    written it you’ll have at least 3 logic cones trying to set values on the entire writedata bus. (If it generates anything at all, it’ll be some weird priority structure).

    That said, it’s probably the range selects that your compiler is complaining about, ie the writedata[2-i:0] rather than the writedata[3-i] = en[i]; (anything with : in the part select). If you want to do something along those lines, you can use ‘indexed part selects’ ( +: or -:) but there are better solutions in this case.

    I’d rewrite it as follows – assuming I’ve assumed correctly 🙂

    always @( /*whatever*/ ) begin
    
        // default assignment
        writedata = readdata;
    
        // overwrite some bits in writedata for special cases
        for(i=0; i<3; i++) begin
            if( changed[i] & !done_q[i] )
                 writedata[3-i] = en[i];
        end
    end
    

    In this code, I’m setting writedata to readdata, and then tweaking the resulting value of writedata if the special cases are in play. The for loop is building 3 logic cones, one for each of the bits in writedata[3:1]. I’d double-check if the bit mapping is what you intend -ie, mapping en[2:0] on to writedata[1:3].

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

Sidebar

Related Questions

I am trying to write a simple tool using Shoes. This will indent code
I'm trying to write a regular expression for html code that looks like this:
I was trying to understand something with pointers, so I wrote this code: #include
I'm trying to figure out how to write this function: template <typename Bound> Bound::result_type
I could probably write this myself, but the specific way I'm trying to accomplish
I've been trying to figure out how to write this regular expression. It is
any better way to write this ? $(this).parent().parent().find( dd ul).toggle(); update.. I am trying
I've been trying myself, and searching online, to write this regular expression but without
I'm trying to write a calendar function like this function get_date($month, $year, $week, $day,
I'm trying to write a method like this: public static T Test<T>() { if

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.