What does “others=>'0'” mean in an assignment statement?












3















cmd_register: process (rst_n, clk)
begin
if (rst_n='0') then
cmd_r<= (others=>'0');
elsif (clk'event and clk='1') then
cmd_r<=...;
end if;
end process cmd_register;


I know "<=" specifies assignment but what is others? And what does => do?










share|improve this question

























  • eda.org/comp.lang.vhdl/FAQ1.html#aggregates

    – fru1tbat
    Aug 28 '14 at 13:58











  • (not an exact answer, but as this is kind of a FAQ-type question, I thought I'd point you there for starters)

    – fru1tbat
    Aug 28 '14 at 14:06
















3















cmd_register: process (rst_n, clk)
begin
if (rst_n='0') then
cmd_r<= (others=>'0');
elsif (clk'event and clk='1') then
cmd_r<=...;
end if;
end process cmd_register;


I know "<=" specifies assignment but what is others? And what does => do?










share|improve this question

























  • eda.org/comp.lang.vhdl/FAQ1.html#aggregates

    – fru1tbat
    Aug 28 '14 at 13:58











  • (not an exact answer, but as this is kind of a FAQ-type question, I thought I'd point you there for starters)

    – fru1tbat
    Aug 28 '14 at 14:06














3












3








3


2






cmd_register: process (rst_n, clk)
begin
if (rst_n='0') then
cmd_r<= (others=>'0');
elsif (clk'event and clk='1') then
cmd_r<=...;
end if;
end process cmd_register;


I know "<=" specifies assignment but what is others? And what does => do?










share|improve this question
















cmd_register: process (rst_n, clk)
begin
if (rst_n='0') then
cmd_r<= (others=>'0');
elsif (clk'event and clk='1') then
cmd_r<=...;
end if;
end process cmd_register;


I know "<=" specifies assignment but what is others? And what does => do?







if-statement process vhdl fpga






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Aug 28 '14 at 19:22









user1155120

12.3k32228




12.3k32228










asked Aug 28 '14 at 13:38









Mehmet Salih CüvelekMehmet Salih Cüvelek

421211




421211













  • eda.org/comp.lang.vhdl/FAQ1.html#aggregates

    – fru1tbat
    Aug 28 '14 at 13:58











  • (not an exact answer, but as this is kind of a FAQ-type question, I thought I'd point you there for starters)

    – fru1tbat
    Aug 28 '14 at 14:06



















  • eda.org/comp.lang.vhdl/FAQ1.html#aggregates

    – fru1tbat
    Aug 28 '14 at 13:58











  • (not an exact answer, but as this is kind of a FAQ-type question, I thought I'd point you there for starters)

    – fru1tbat
    Aug 28 '14 at 14:06

















eda.org/comp.lang.vhdl/FAQ1.html#aggregates

– fru1tbat
Aug 28 '14 at 13:58





eda.org/comp.lang.vhdl/FAQ1.html#aggregates

– fru1tbat
Aug 28 '14 at 13:58













(not an exact answer, but as this is kind of a FAQ-type question, I thought I'd point you there for starters)

– fru1tbat
Aug 28 '14 at 14:06





(not an exact answer, but as this is kind of a FAQ-type question, I thought I'd point you there for starters)

– fru1tbat
Aug 28 '14 at 14:06












4 Answers
4






active

oldest

votes


















8














cmd_r is defined as a std_logic_vector, or unsigned or signed signal. let's see how this signal type are defined:



type std_logic_vector is array (natural range <>) of std_logic; 
type unsigned is array (natural range <>) of std_logic;
type signed is array (natural range <>) of std_logic;


Note that these 3 types have the same definition as an array of std_logic items.



The statement "Others => '0'" is a feature of the VHDL when the coder want to defined several items in an array with the same value.



In your example, all item std_logic in the array are set to '0'.



Another application of this statement is to set some items at a specific value and all others at a default value :



cmd_r <= (0      => '1',
4 => '1',
others => '0');


In this case, the bit 0 and 4 are set to '1' and all other bits are set to '0'.



One last thing, it's NOT possible to write something like this :



  cmd_r <= (0          => '1',
4 downto 2 => "111", -- this line is wrong !!!
others => '0');





share|improve this answer





















  • 3





    I believe that last bit of code is possible with VHDL-2008.

    – fru1tbat
    Aug 28 '14 at 18:08



















4














( others => '0') is an expression, an aggregate of elements into a composite type.



Without seeing the declaration for cmd_r we can imagine it's an array type, an array type is a composite type (made of one or more elements).



An aggregate combines one or more values as elements into a composite type.



 aggregate ::=
( element_association { , element_association } )


Notice the opening and closing parentheses are required.



Those elements can be associated positionally by name for a record type or by index value position for an array type.



 element_association ::=
[ choices => ] expression


The element association is governed by choices.



 choices ::=  choice { | choice }


The element association can cover more than one choice.



 choice ::=
simple_expression
| discrete_range
| element_simple_name
| others


A choice can represent one or more elements.



An element simple name is used for a record type or an array type with an index type that is an enumerated type.



others is always the last choice and stands for all the remaining choices for that type. The type can be discovered in an assignment from the target. In some instances the type is required to be supplied explicitly, as in a qualified expression.



The element association others => '0' stands for all other elements of the type of the aggregate. In this case the type and subtype of cmd_r, where a subtype indication specifies a range index of elements of a std_logic_vector.



The expression '0' is required to be of the element type, and the aggregate (others => '0') stands for a value of the subtype of cmd_r comprised of '0''s for each of the elements of cmd_r in this case.






share|improve this answer































    2














    It just means set all bits to zero!!






    share|improve this answer































      2














      The expression (others=>’O’) means that all elements are assigned to ’0’.

      If cmd_r is 8 bit then it will assign 00000000 to cmd_r. If cmd_r is two dimensional then the same thing will be (others =>(others =>'0')).






      share|improve this answer


























      • seems like extra syntactic noise. Why not just allow cmd_r<= '0'

        – S.N.
        Nov 21 '18 at 0:05











      • This will create an ambiguity. Sometime this will assign just the LSB to zero. I had a code in which this happened. So I always insure that when a vector is presented and if it should be zero then no lose syntax. Just to avoid extra debugging work.

        – TRoa
        Nov 21 '18 at 10:39











      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f25550244%2fwhat-does-others-0-mean-in-an-assignment-statement%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      4 Answers
      4






      active

      oldest

      votes








      4 Answers
      4






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      8














      cmd_r is defined as a std_logic_vector, or unsigned or signed signal. let's see how this signal type are defined:



      type std_logic_vector is array (natural range <>) of std_logic; 
      type unsigned is array (natural range <>) of std_logic;
      type signed is array (natural range <>) of std_logic;


      Note that these 3 types have the same definition as an array of std_logic items.



      The statement "Others => '0'" is a feature of the VHDL when the coder want to defined several items in an array with the same value.



      In your example, all item std_logic in the array are set to '0'.



      Another application of this statement is to set some items at a specific value and all others at a default value :



      cmd_r <= (0      => '1',
      4 => '1',
      others => '0');


      In this case, the bit 0 and 4 are set to '1' and all other bits are set to '0'.



      One last thing, it's NOT possible to write something like this :



        cmd_r <= (0          => '1',
      4 downto 2 => "111", -- this line is wrong !!!
      others => '0');





      share|improve this answer





















      • 3





        I believe that last bit of code is possible with VHDL-2008.

        – fru1tbat
        Aug 28 '14 at 18:08
















      8














      cmd_r is defined as a std_logic_vector, or unsigned or signed signal. let's see how this signal type are defined:



      type std_logic_vector is array (natural range <>) of std_logic; 
      type unsigned is array (natural range <>) of std_logic;
      type signed is array (natural range <>) of std_logic;


      Note that these 3 types have the same definition as an array of std_logic items.



      The statement "Others => '0'" is a feature of the VHDL when the coder want to defined several items in an array with the same value.



      In your example, all item std_logic in the array are set to '0'.



      Another application of this statement is to set some items at a specific value and all others at a default value :



      cmd_r <= (0      => '1',
      4 => '1',
      others => '0');


      In this case, the bit 0 and 4 are set to '1' and all other bits are set to '0'.



      One last thing, it's NOT possible to write something like this :



        cmd_r <= (0          => '1',
      4 downto 2 => "111", -- this line is wrong !!!
      others => '0');





      share|improve this answer





















      • 3





        I believe that last bit of code is possible with VHDL-2008.

        – fru1tbat
        Aug 28 '14 at 18:08














      8












      8








      8







      cmd_r is defined as a std_logic_vector, or unsigned or signed signal. let's see how this signal type are defined:



      type std_logic_vector is array (natural range <>) of std_logic; 
      type unsigned is array (natural range <>) of std_logic;
      type signed is array (natural range <>) of std_logic;


      Note that these 3 types have the same definition as an array of std_logic items.



      The statement "Others => '0'" is a feature of the VHDL when the coder want to defined several items in an array with the same value.



      In your example, all item std_logic in the array are set to '0'.



      Another application of this statement is to set some items at a specific value and all others at a default value :



      cmd_r <= (0      => '1',
      4 => '1',
      others => '0');


      In this case, the bit 0 and 4 are set to '1' and all other bits are set to '0'.



      One last thing, it's NOT possible to write something like this :



        cmd_r <= (0          => '1',
      4 downto 2 => "111", -- this line is wrong !!!
      others => '0');





      share|improve this answer















      cmd_r is defined as a std_logic_vector, or unsigned or signed signal. let's see how this signal type are defined:



      type std_logic_vector is array (natural range <>) of std_logic; 
      type unsigned is array (natural range <>) of std_logic;
      type signed is array (natural range <>) of std_logic;


      Note that these 3 types have the same definition as an array of std_logic items.



      The statement "Others => '0'" is a feature of the VHDL when the coder want to defined several items in an array with the same value.



      In your example, all item std_logic in the array are set to '0'.



      Another application of this statement is to set some items at a specific value and all others at a default value :



      cmd_r <= (0      => '1',
      4 => '1',
      others => '0');


      In this case, the bit 0 and 4 are set to '1' and all other bits are set to '0'.



      One last thing, it's NOT possible to write something like this :



        cmd_r <= (0          => '1',
      4 downto 2 => "111", -- this line is wrong !!!
      others => '0');






      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Aug 28 '14 at 13:59

























      answered Aug 28 '14 at 13:53









      grorelgrorel

      826813




      826813








      • 3





        I believe that last bit of code is possible with VHDL-2008.

        – fru1tbat
        Aug 28 '14 at 18:08














      • 3





        I believe that last bit of code is possible with VHDL-2008.

        – fru1tbat
        Aug 28 '14 at 18:08








      3




      3





      I believe that last bit of code is possible with VHDL-2008.

      – fru1tbat
      Aug 28 '14 at 18:08





      I believe that last bit of code is possible with VHDL-2008.

      – fru1tbat
      Aug 28 '14 at 18:08













      4














      ( others => '0') is an expression, an aggregate of elements into a composite type.



      Without seeing the declaration for cmd_r we can imagine it's an array type, an array type is a composite type (made of one or more elements).



      An aggregate combines one or more values as elements into a composite type.



       aggregate ::=
      ( element_association { , element_association } )


      Notice the opening and closing parentheses are required.



      Those elements can be associated positionally by name for a record type or by index value position for an array type.



       element_association ::=
      [ choices => ] expression


      The element association is governed by choices.



       choices ::=  choice { | choice }


      The element association can cover more than one choice.



       choice ::=
      simple_expression
      | discrete_range
      | element_simple_name
      | others


      A choice can represent one or more elements.



      An element simple name is used for a record type or an array type with an index type that is an enumerated type.



      others is always the last choice and stands for all the remaining choices for that type. The type can be discovered in an assignment from the target. In some instances the type is required to be supplied explicitly, as in a qualified expression.



      The element association others => '0' stands for all other elements of the type of the aggregate. In this case the type and subtype of cmd_r, where a subtype indication specifies a range index of elements of a std_logic_vector.



      The expression '0' is required to be of the element type, and the aggregate (others => '0') stands for a value of the subtype of cmd_r comprised of '0''s for each of the elements of cmd_r in this case.






      share|improve this answer




























        4














        ( others => '0') is an expression, an aggregate of elements into a composite type.



        Without seeing the declaration for cmd_r we can imagine it's an array type, an array type is a composite type (made of one or more elements).



        An aggregate combines one or more values as elements into a composite type.



         aggregate ::=
        ( element_association { , element_association } )


        Notice the opening and closing parentheses are required.



        Those elements can be associated positionally by name for a record type or by index value position for an array type.



         element_association ::=
        [ choices => ] expression


        The element association is governed by choices.



         choices ::=  choice { | choice }


        The element association can cover more than one choice.



         choice ::=
        simple_expression
        | discrete_range
        | element_simple_name
        | others


        A choice can represent one or more elements.



        An element simple name is used for a record type or an array type with an index type that is an enumerated type.



        others is always the last choice and stands for all the remaining choices for that type. The type can be discovered in an assignment from the target. In some instances the type is required to be supplied explicitly, as in a qualified expression.



        The element association others => '0' stands for all other elements of the type of the aggregate. In this case the type and subtype of cmd_r, where a subtype indication specifies a range index of elements of a std_logic_vector.



        The expression '0' is required to be of the element type, and the aggregate (others => '0') stands for a value of the subtype of cmd_r comprised of '0''s for each of the elements of cmd_r in this case.






        share|improve this answer


























          4












          4








          4







          ( others => '0') is an expression, an aggregate of elements into a composite type.



          Without seeing the declaration for cmd_r we can imagine it's an array type, an array type is a composite type (made of one or more elements).



          An aggregate combines one or more values as elements into a composite type.



           aggregate ::=
          ( element_association { , element_association } )


          Notice the opening and closing parentheses are required.



          Those elements can be associated positionally by name for a record type or by index value position for an array type.



           element_association ::=
          [ choices => ] expression


          The element association is governed by choices.



           choices ::=  choice { | choice }


          The element association can cover more than one choice.



           choice ::=
          simple_expression
          | discrete_range
          | element_simple_name
          | others


          A choice can represent one or more elements.



          An element simple name is used for a record type or an array type with an index type that is an enumerated type.



          others is always the last choice and stands for all the remaining choices for that type. The type can be discovered in an assignment from the target. In some instances the type is required to be supplied explicitly, as in a qualified expression.



          The element association others => '0' stands for all other elements of the type of the aggregate. In this case the type and subtype of cmd_r, where a subtype indication specifies a range index of elements of a std_logic_vector.



          The expression '0' is required to be of the element type, and the aggregate (others => '0') stands for a value of the subtype of cmd_r comprised of '0''s for each of the elements of cmd_r in this case.






          share|improve this answer













          ( others => '0') is an expression, an aggregate of elements into a composite type.



          Without seeing the declaration for cmd_r we can imagine it's an array type, an array type is a composite type (made of one or more elements).



          An aggregate combines one or more values as elements into a composite type.



           aggregate ::=
          ( element_association { , element_association } )


          Notice the opening and closing parentheses are required.



          Those elements can be associated positionally by name for a record type or by index value position for an array type.



           element_association ::=
          [ choices => ] expression


          The element association is governed by choices.



           choices ::=  choice { | choice }


          The element association can cover more than one choice.



           choice ::=
          simple_expression
          | discrete_range
          | element_simple_name
          | others


          A choice can represent one or more elements.



          An element simple name is used for a record type or an array type with an index type that is an enumerated type.



          others is always the last choice and stands for all the remaining choices for that type. The type can be discovered in an assignment from the target. In some instances the type is required to be supplied explicitly, as in a qualified expression.



          The element association others => '0' stands for all other elements of the type of the aggregate. In this case the type and subtype of cmd_r, where a subtype indication specifies a range index of elements of a std_logic_vector.



          The expression '0' is required to be of the element type, and the aggregate (others => '0') stands for a value of the subtype of cmd_r comprised of '0''s for each of the elements of cmd_r in this case.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Aug 28 '14 at 19:15









          user1155120user1155120

          12.3k32228




          12.3k32228























              2














              It just means set all bits to zero!!






              share|improve this answer




























                2














                It just means set all bits to zero!!






                share|improve this answer


























                  2












                  2








                  2







                  It just means set all bits to zero!!






                  share|improve this answer













                  It just means set all bits to zero!!







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Aug 28 '14 at 13:50









                  PiboRockPiboRock

                  941211




                  941211























                      2














                      The expression (others=>’O’) means that all elements are assigned to ’0’.

                      If cmd_r is 8 bit then it will assign 00000000 to cmd_r. If cmd_r is two dimensional then the same thing will be (others =>(others =>'0')).






                      share|improve this answer


























                      • seems like extra syntactic noise. Why not just allow cmd_r<= '0'

                        – S.N.
                        Nov 21 '18 at 0:05











                      • This will create an ambiguity. Sometime this will assign just the LSB to zero. I had a code in which this happened. So I always insure that when a vector is presented and if it should be zero then no lose syntax. Just to avoid extra debugging work.

                        – TRoa
                        Nov 21 '18 at 10:39
















                      2














                      The expression (others=>’O’) means that all elements are assigned to ’0’.

                      If cmd_r is 8 bit then it will assign 00000000 to cmd_r. If cmd_r is two dimensional then the same thing will be (others =>(others =>'0')).






                      share|improve this answer


























                      • seems like extra syntactic noise. Why not just allow cmd_r<= '0'

                        – S.N.
                        Nov 21 '18 at 0:05











                      • This will create an ambiguity. Sometime this will assign just the LSB to zero. I had a code in which this happened. So I always insure that when a vector is presented and if it should be zero then no lose syntax. Just to avoid extra debugging work.

                        – TRoa
                        Nov 21 '18 at 10:39














                      2












                      2








                      2







                      The expression (others=>’O’) means that all elements are assigned to ’0’.

                      If cmd_r is 8 bit then it will assign 00000000 to cmd_r. If cmd_r is two dimensional then the same thing will be (others =>(others =>'0')).






                      share|improve this answer















                      The expression (others=>’O’) means that all elements are assigned to ’0’.

                      If cmd_r is 8 bit then it will assign 00000000 to cmd_r. If cmd_r is two dimensional then the same thing will be (others =>(others =>'0')).







                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited Nov 21 '18 at 10:36

























                      answered Aug 27 '18 at 13:16









                      TRoaTRoa

                      669




                      669













                      • seems like extra syntactic noise. Why not just allow cmd_r<= '0'

                        – S.N.
                        Nov 21 '18 at 0:05











                      • This will create an ambiguity. Sometime this will assign just the LSB to zero. I had a code in which this happened. So I always insure that when a vector is presented and if it should be zero then no lose syntax. Just to avoid extra debugging work.

                        – TRoa
                        Nov 21 '18 at 10:39



















                      • seems like extra syntactic noise. Why not just allow cmd_r<= '0'

                        – S.N.
                        Nov 21 '18 at 0:05











                      • This will create an ambiguity. Sometime this will assign just the LSB to zero. I had a code in which this happened. So I always insure that when a vector is presented and if it should be zero then no lose syntax. Just to avoid extra debugging work.

                        – TRoa
                        Nov 21 '18 at 10:39

















                      seems like extra syntactic noise. Why not just allow cmd_r<= '0'

                      – S.N.
                      Nov 21 '18 at 0:05





                      seems like extra syntactic noise. Why not just allow cmd_r<= '0'

                      – S.N.
                      Nov 21 '18 at 0:05













                      This will create an ambiguity. Sometime this will assign just the LSB to zero. I had a code in which this happened. So I always insure that when a vector is presented and if it should be zero then no lose syntax. Just to avoid extra debugging work.

                      – TRoa
                      Nov 21 '18 at 10:39





                      This will create an ambiguity. Sometime this will assign just the LSB to zero. I had a code in which this happened. So I always insure that when a vector is presented and if it should be zero then no lose syntax. Just to avoid extra debugging work.

                      – TRoa
                      Nov 21 '18 at 10:39


















                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f25550244%2fwhat-does-others-0-mean-in-an-assignment-statement%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Biblatex bibliography style without URLs when DOI exists (in Overleaf with Zotero bibliography)

                      ComboBox Display Member on multiple fields

                      Is it possible to collect Nectar points via Trainline?