在赋值语句中,"others=>'0' "是什么意思?[英] What does "others=>'0'" mean in an assignment statement?

本文是小编为大家收集整理的关于在赋值语句中,"others=>'0' "是什么意思?的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

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;

我知道" <="指定分配,但是什么是others? =>做什么?

推荐答案

cmd_r定义为 std_logic_vector 或 无符号或签名信号.让我们看看如何定义此信号类型:

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;

请注意,这三种类型的定义与std_logic项目的数组相同.

语句"其他=>'0'"是VHDL的功能,当编码器想在数组中定义具有相同值的数组中的几个项目.

在您的示例中,数组中的所有项目std_logic均设置为'0'.

该语句的另一个应用程序是将某些项目设置为特定值,而所有其他项目都以默认值设置:

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

在这种情况下,位0和4设置为'1',所有其他位均设置为'0'.

最后一件事,不可能写下这样的东西:

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

其他推荐答案

它只是意味着将所有位设置为零!!

其他推荐答案

( others => '0')是一种表达式,是复合类型的元素的聚集体.

没有看到cmd_r声明的声明,我们可以想象它是一种数组类型,而数组类型是一种复合类型(由一个或多个元素制成).

聚集体将一个或多个值作为元素组合为复合类型.

 aggregate ::=
     ( element_association { , element_association } )

请注意需要开口和关闭括号.

这些元素可以通过名称与记录类型的名称或数组类型的索引值位置相关联.

 element_association ::=
     [ choices => ] expression

元素关联由选择管辖.

 choices ::=  choice { | choice }

元素关联可以涵盖多个选择.

 choice ::=
        simple_expression
     | discrete_range
     | element_simple_name
     | others

选择可以代表一个或多个元素.

元素简单名称用于记录类型或具有枚举类型的索引类型的数组类型.

others始终是最后的选择,并代表该类型的所有剩余选择.可以从目标分配中发现类型.在某些情况下,该类型需要明确提供,例如合格的表达式.

元素关联others => '0'代表骨料类型的所有其他元素.在这种情况下

表达式'0'必须是元素类型,而骨料(others => '0')代表cmd_r cmd_r的子类型的值,'0'的每个元素'0' s组成.在这种情况下.

本文地址:https://www.itbaoku.cn/post/2090965.html

问题描述

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?

推荐答案

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');

其他推荐答案

It just means set all bits to zero!!

其他推荐答案

( 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.