• Skip to main content
  • Skip to search
  • Skip to footer
Cadence Home
  • This search text may be transcribed, used, stored, or accessed by our third-party service providers per our Cookie Policy and Privacy Policy.

  1. Community Forums
  2. Mixed-Signal Design
  3. SystemVerilog: Assign a array to a bus

Stats

  • Locked Locked
  • Replies 3
  • Subscribers 64
  • Views 9370
  • Members are here 0
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

SystemVerilog: Assign a array to a bus

HoWei
HoWei over 2 years ago

Hi,

I want to assign an array of sigals to an output bus, as in the example below.

The order of assignements is dependent on the control input:

module mytest(

input logic control,

input real inA,

input real inB,

output real myOut[5:0]

);

assign myOut[5:0] = ( control == 1'b1) ? {inA, inA, inA, inB, inB) : {inB, inA, inB, inA, inB} ;

But this does not work, since it does not accept the array {} for the assignement.

How can I do this assignement properly ?

  • Cancel
Parents
  • tpylant
    tpylant over 2 years ago

    You are trying to do concatenation when what you want to do is array assignment. Also, your array was too big for the assignment. Here is the code that works:

    module mytest(
      input logic control,
      input real inA,
      input real inB,
      output real myOut[4:0]
    );

      assign myOut[4:0] = ( control == 1'b1) ? '{inA, inA, inA, inB, inB} : '{inB, inA, inB, inA, inB} ;

    endmodule

    Tim

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • HoWei
    HoWei over 2 years ago in reply to tpylant

    Hi Tim,

    yes, the example was buggy as the dimensions of the arrays did not match. Thanks for the working example. 

    Is there a way to write the array in a short form - assume I do have a 64-bit array and want to assign all "inA" or "inB".

    Can I do something like this:

    assign myOut [63:0] = ( control == 1'b1) ? [63:0] inA : [63:0] inB;

    I want to avoid to type 64-time the "inA" / "inB"  in brackets, like '{inA, inA, inA ...}.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • tpylant
    tpylant over 2 years ago in reply to HoWei

    You should look up "SystemVerilog array assignment" to confirm, but I think the following will work:

    assign myOut[64] = (control==1'b1) ? '{ 64 {inA} } : '{ 64 {inB} };

    Tim

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Reply
  • tpylant
    tpylant over 2 years ago in reply to HoWei

    You should look up "SystemVerilog array assignment" to confirm, but I think the following will work:

    assign myOut[64] = (control==1'b1) ? '{ 64 {inA} } : '{ 64 {inB} };

    Tim

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Children
No Data

Community Guidelines

The Cadence Design Communities support Cadence users and technologists interacting to exchange ideas, news, technical information, and best practices to solve problems and get the most from Cadence technology. The community is open to everyone, and to provide the most value, we require participants to follow our Community Guidelines that facilitate a quality exchange of ideas and information. By accessing, contributing, using or downloading any materials from the site, you agree to be bound by the full Community Guidelines.

© 2025 Cadence Design Systems, Inc. All Rights Reserved.

  • Terms of Use
  • Privacy
  • Cookie Policy
  • US Trademarks
  • Do Not Sell or Share My Personal Information